diff options
author | Ville Hakulinen <ville.hakulinen@gmail.com> | 2020-07-16 16:55:59 +0300 |
---|---|---|
committer | Ville Hakulinen <ville.hakulinen@gmail.com> | 2020-07-16 16:55:59 +0300 |
commit | fc62e9674c5d0f269ea0bd9530130664e6f10491 (patch) | |
tree | 9d0fe48178a9af8b3711a74d647cb35cc604c51c | |
parent | 473b13dced42b0c5a6ec819e8ab83dea9c9ac8e7 (diff) |
Show MsgSeparator on the messages grid
-rw-r--r-- | src/ui/color.rs | 2 | ||||
-rw-r--r-- | src/ui/state.rs | 62 | ||||
-rw-r--r-- | src/ui/ui.rs | 8 | ||||
-rw-r--r-- | src/ui/window.rs | 9 |
4 files changed, 54 insertions, 27 deletions
diff --git a/src/ui/color.rs b/src/ui/color.rs index 1048764..c73faba 100644 --- a/src/ui/color.rs +++ b/src/ui/color.rs @@ -16,6 +16,8 @@ pub enum HlGroup { Wildmenu, WildmenuSel, + + MsgSeparator, } #[derive(Default)] diff --git a/src/ui/state.rs b/src/ui/state.rs index 2a333d1..7153cfe 100644 --- a/src/ui/state.rs +++ b/src/ui/state.rs @@ -79,8 +79,8 @@ pub(crate) struct UIState { pub resize_on_flush: Option<ResizeOptions>, /// Flag for flush to update GUI colors on components that depend on - /// hl gruops. - pub hl_groups_changed: bool, + /// highlight defs and groups. + pub hl_changed: bool, pub font: Font, pub line_space: i64, @@ -258,22 +258,7 @@ impl UIState { #[cfg(feature = "libwebkit2gtk")] self.cursor_tooltip.set_colors(fg, bg); - // Set the background for our main window. - CssProviderExt::load_from_data( - &self.css_provider, - format!( - "* {{ - background: #{bg}; - }} - - frame > border {{ - border: none; - }}", - bg = bg.to_hex() - ) - .as_bytes(), - ) - .unwrap(); + self.hl_changed = true; } fn hl_attr_define(&mut self, HlAttrDefine { id, hl }: HlAttrDefine) { @@ -299,10 +284,13 @@ impl UIState { self.hl_defs.set_hl_group(HlGroup::TablineFill, evt.hl_id) } "Normal" => self.hl_defs.set_hl_group(HlGroup::Cmdline, evt.hl_id), + "MsgSeparator" => { + self.hl_defs.set_hl_group(HlGroup::MsgSeparator, evt.hl_id) + } _ => None, }; - self.hl_groups_changed = true; + self.hl_changed = true; } fn option_set(&mut self, opt: OptionSet) { @@ -412,13 +400,43 @@ impl UIState { self.tabline.set_line_space(opts.line_space, &self.hl_defs); } - if self.hl_groups_changed { + if self.hl_changed { self.popupmenu.set_colors(&self.hl_defs); self.tabline.set_colors(&self.hl_defs); self.cmdline.set_colors(&self.hl_defs); self.cmdline.wildmenu_set_colors(&self.hl_defs); - self.hl_groups_changed = false; + let msgsep = self + .hl_defs + .get_hl_group(&HlGroup::MsgSeparator) + .cloned() + .unwrap_or_default() + .foreground; + + // Set the styles for our main window. + CssProviderExt::load_from_data( + &self.css_provider, + format!( + "* {{ + background: #{bg}; + }} + + frame > border {{ + border: none; + }} + + #message-grid-contianer frame.scrolled {{ + border-top: 1px solid #{msgsep} + }} + ", + bg = self.hl_defs.default_bg.to_hex(), + msgsep = msgsep.unwrap_or(self.hl_defs.default_fg).to_hex(), + ) + .as_bytes(), + ) + .unwrap(); + + self.hl_changed = false; } } @@ -692,7 +710,7 @@ impl UIState { let base_metrics = base_grid.get_grid_metrics(); let grid = self.grids.get(&e.grid).unwrap(); let h = base_metrics.height - e.row as f64 * base_metrics.cell_height; - self.msg_window.set_pos(&grid, e.row as f64, h); + self.msg_window.set_pos(&grid, e.row as f64, h, e.scrolled); } fn handle_redraw_event( diff --git a/src/ui/ui.rs b/src/ui/ui.rs index 0a3d492..d1849df 100644 --- a/src/ui/ui.rs +++ b/src/ui/ui.rs @@ -93,11 +93,11 @@ impl UI { overlay.add(&grid.widget()); let windows_container = gtk::Fixed::new(); - windows_container.set_widget_name("Windows contianer"); + windows_container.set_widget_name("windows-contianer"); let windows_float_container = gtk::Fixed::new(); - windows_float_container.set_widget_name("Floating windows contianer"); + windows_float_container.set_widget_name("windows-contianer-float"); let msg_window_container = gtk::Fixed::new(); - msg_window_container.set_widget_name("Message grid contianer"); + msg_window_container.set_widget_name("message-grid-contianer"); overlay.add_overlay(&windows_container); overlay.add_overlay(&msg_window_container); overlay.add_overlay(&windows_float_container); @@ -238,7 +238,7 @@ impl UI { resize_source_id: source_id, hl_defs, resize_on_flush: None, - hl_groups_changed: false, + hl_changed: false, font, line_space, current_mode: None, diff --git a/src/ui/window.rs b/src/ui/window.rs index 7fddbb2..fa4f1e7 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -30,7 +30,7 @@ impl MsgWindow { /// on the `grid` and `row`, we can't calculate the height automatically. /// The height is mainly needed so we don't show any artifacts that /// will likely be visible on the `grid`'s drawingarea from earlier renders. - pub fn set_pos(&self, grid: &Grid, row: f64, h: f64) { + pub fn set_pos(&self, grid: &Grid, row: f64, h: f64, scrolled: bool) { let w = grid.widget(); // Only add/change the child widget if its different @@ -45,6 +45,13 @@ impl MsgWindow { self.frame.add(&w); } + let c = self.frame.get_style_context(); + if scrolled { + c.add_class("scrolled"); + } else { + c.remove_class("scrolled"); + } + let metrics = grid.get_grid_metrics(); let w = metrics.cols * metrics.cell_width; self.frame |