From 3336023614bb5ae8740f71c3df31030d6757081a Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 28 May 2021 00:01:17 +0900 Subject: ui: Menu rendering adjustments --- helix-term/src/ui/menu.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'helix-term/src') diff --git a/helix-term/src/ui/menu.rs b/helix-term/src/ui/menu.rs index 893c75e7..7be3be9d 100644 --- a/helix-term/src/ui/menu.rs +++ b/helix-term/src/ui/menu.rs @@ -230,7 +230,7 @@ impl Component for Menu { fn required_size(&mut self, viewport: (u16, u16)) -> Option<(u16, u16)> { let width = std::cmp::min(30, viewport.0); - const MAX: usize = 5; + const MAX: usize = 10; let height = std::cmp::min(self.options.len(), MAX); let height = std::cmp::min(height, viewport.1 as usize); @@ -242,9 +242,11 @@ impl Component for Menu { Some(self.size) } + // TODO: required size should re-trigger when we filter items so we can draw a smaller menu + fn render(&self, area: Rect, surface: &mut Surface, cx: &mut Context) { let style = cx.editor.theme.get("ui.text"); - let selected = Style::default().fg(Color::Rgb(255, 255, 255)); + let selected = cx.editor.theme.get("ui.menu.selected"); let scroll = self.scroll; @@ -289,13 +291,21 @@ impl Component for Menu { }, ); + // // TODO: set bg for the whole row if selected + // if line == self.cursor { + // surface.set_style( + // Rect::new(area.x, area.y + i as u16, area.width - 1, 1), + // selected, + // ) + // } + for (i, option) in (scroll..(scroll + win_height).min(len)).enumerate() { let is_marked = i >= scroll_line && i < scroll_line + scroll_height; if is_marked { let cell = surface.get_mut(area.x + area.width - 2, area.y + i as u16); cell.set_symbol("▐ "); - cell.set_style(selected); + // cell.set_style(selected); // cell.set_style(if is_marked { selected } else { style }); } } -- cgit v1.2.3-70-g09d2