ui/pager: reflow on resize

jmap
Manos Pitsidianakis 2019-11-21 15:42:01 +02:00
parent c62c04e1e7
commit 022e1f437d
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 22 additions and 0 deletions

View File

@ -287,6 +287,8 @@ pub struct Pager {
height: usize, height: usize,
width: usize, width: usize,
dirty: bool, dirty: bool,
initialised: bool,
content: CellBuffer, content: CellBuffer,
movement: Option<PageMovement>, movement: Option<PageMovement>,
id: ComponentId, id: ComponentId,
@ -436,6 +438,10 @@ impl Pager {
((0, i), (width.saturating_sub(1), i)), ((0, i), (width.saturating_sub(1), i)),
None, 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 { pub fn cursor_pos(&self) -> usize {
@ -452,6 +458,21 @@ impl Component for Pager {
return; return;
} }
if !self.initialised {
let width = width!(area);
let lines: Vec<String> = 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; self.dirty = false;
let height = height!(area); let height = height!(area);
@ -602,6 +623,7 @@ impl Component for Pager {
return true; return true;
} }
UIEvent::Resize => { UIEvent::Resize => {
self.initialised = false;
self.dirty = true; self.dirty = true;
} }
_ => {} _ => {}