From 022e1f437d0eb1531580cc08ca6bb574dab14c3b Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 21 Nov 2019 15:42:01 +0200 Subject: [PATCH] ui/pager: reflow on resize --- ui/src/components/utilities.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ui/src/components/utilities.rs b/ui/src/components/utilities.rs index da486101..f2e7c0dc 100644 --- a/ui/src/components/utilities.rs +++ b/ui/src/components/utilities.rs @@ -287,6 +287,8 @@ pub struct Pager { height: usize, width: usize, dirty: bool, + + initialised: bool, content: CellBuffer, movement: Option, id: ComponentId, @@ -436,6 +438,10 @@ impl Pager { ((0, i), (width.saturating_sub(1), i)), None, ); + if l.starts_with("⤷") { + content[(0, i)].set_fg(Color::Byte(240)); + content[(0, i)].set_attrs(Attr::Bold); + } } } pub fn cursor_pos(&self) -> usize { @@ -452,6 +458,21 @@ impl Component for Pager { return; } + if !self.initialised { + let width = width!(area); + let lines: Vec = self + .text + .split_lines_reflow(Reflow::All, Some(width.saturating_sub(2))); + let height = lines.len() + 2; + let mut content = CellBuffer::new(width, height, Cell::with_char(' ')); + content.set_ascii_drawing(self.content.ascii_drawing); + Pager::print_string(&mut content, lines); + self.content = content; + self.height = height; + self.width = width; + self.initialised = true; + } + self.dirty = false; let height = height!(area); @@ -602,6 +623,7 @@ impl Component for Pager { return true; } UIEvent::Resize => { + self.initialised = false; self.dirty = true; } _ => {}