From 422641ddf0f13366bca0b1378f8a5557d22dd2f6 Mon Sep 17 00:00:00 2001 From: Joscha Date: Thu, 28 Jul 2022 12:57:01 +0200 Subject: [PATCH] Add focus range to Block --- src/ui/chat/blocks.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ui/chat/blocks.rs b/src/ui/chat/blocks.rs index ebe872d..2644225 100644 --- a/src/ui/chat/blocks.rs +++ b/src/ui/chat/blocks.rs @@ -1,4 +1,5 @@ -use std::collections::{vec_deque, VecDeque}; +use std::collections::VecDeque; +use std::ops::Range; use toss::frame::Frame; @@ -9,6 +10,12 @@ pub struct Block { id: I, top_line: i32, height: i32, + /// The lines of the block that should be made visible if the block is + /// focused on. By default, the focus encompasses the entire block. + /// + /// If not all of these lines can be made visible, the top of the range + /// should be preferred over the bottom. + focus: Range, widget: BoxedWidget, } @@ -18,13 +25,20 @@ impl Block { // here but rustc knows it's a `BoxedWidget`. let widget = widget.into(); let size = widget.size(frame, Some(width), None); + let height = size.height.into(); Self { id, top_line: 0, - height: size.height.into(), + height, + focus: 0..height, widget, } } + + pub fn focus(mut self, focus: Range) -> Self { + self.focus = focus; + self + } } pub struct Blocks {