diff --git a/defaults/dark-theme.toml b/defaults/dark-theme.toml index be0bb661..069d3eb1 100644 --- a/defaults/dark-theme.toml +++ b/defaults/dark-theme.toml @@ -61,6 +61,7 @@ magenta = "#C678DD" "panel.background" = "#21252B" "panel.current" = "#2C313A" +"panel.hovered" = "#343A45" "status.background" = "#21252B" diff --git a/defaults/light-theme.toml b/defaults/light-theme.toml index 72bedcd7..b3f7ea03 100644 --- a/defaults/light-theme.toml +++ b/defaults/light-theme.toml @@ -60,6 +60,7 @@ magenta = "#A626A4" "panel.background" = "#eaeaeb" "panel.current" = "#dbdbdc" +"panel.hovered" = "#E4E4E6" "status.background" = "#eaeaeb" diff --git a/lapce-data/src/config.rs b/lapce-data/src/config.rs index 666d5e2a..0f7cb0cd 100644 --- a/lapce-data/src/config.rs +++ b/lapce-data/src/config.rs @@ -76,6 +76,7 @@ impl LapceTheme { pub const PANEL_BACKGROUND: &'static str = "panel.background"; pub const PANEL_CURRENT: &'static str = "panel.current"; + pub const PANEL_HOVERED: &'static str = "panel.hovered"; pub const STATUS_BACKGROUND: &'static str = "status.background"; diff --git a/lapce-data/src/explorer.rs b/lapce-data/src/explorer.rs index 8db50685..8f334faa 100644 --- a/lapce-data/src/explorer.rs +++ b/lapce-data/src/explorer.rs @@ -22,7 +22,7 @@ pub struct FileExplorerData { pub tab_id: WidgetId, pub widget_id: WidgetId, pub workspace: Option, - pub index: usize, + pub active_selected: usize, #[allow(dead_code)] count: usize, @@ -82,7 +82,7 @@ pub fn new( children: HashMap::new(), children_open_count: 0, }), - index: 0, + active_selected: 0, count: 0, } } diff --git a/lapce-ui/src/explorer.rs b/lapce-ui/src/explorer.rs index 6e70f462..c4d53b68 100644 --- a/lapce-ui/src/explorer.rs +++ b/lapce-ui/src/explorer.rs @@ -38,6 +38,7 @@ pub fn paint_file_node_item( level: usize, current: usize, active: usize, + hovered: Option, config: &Config, toggle_rects: &mut HashMap, ) -> usize { @@ -58,6 +59,16 @@ pub fn paint_file_node_item( .with_size(Size::new(width, line_height)), config.get_color_unchecked(LapceTheme::PANEL_CURRENT), ); + } else if Some(current) == hovered { + ctx.fill( + Rect::ZERO + .with_origin(Point::new( + 0.0, + current as f64 * line_height - line_height, + )) + .with_size(Size::new(width, line_height)), + config.get_color_unchecked(LapceTheme::PANEL_HOVERED), + ); } let y = current as f64 * line_height - line_height; let svg_y = y + 4.0; @@ -136,6 +147,7 @@ pub fn paint_file_node_item( level + 1, i + 1, active, + hovered, config, toggle_rects, ); @@ -329,11 +341,15 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) { pub struct FileExplorerFileList { line_height: f64, + hovered: Option, } impl FileExplorerFileList { pub fn new() -> Self { - Self { line_height: 25.0 } + Self { + line_height: 25.0, + hovered: None, + } } } @@ -359,8 +375,19 @@ fn event( * (workspace.children_open_count + 1 + 1) as f64 { ctx.set_cursor(&Cursor::Pointer); + let hovered = Some( + ((mouse_event.pos.y + self.line_height) + / self.line_height) + as usize, + ); + + if hovered != self.hovered { + ctx.request_paint(); + self.hovered = hovered; + } } else { ctx.clear_cursor(); + self.hovered = None; } } } @@ -410,7 +437,7 @@ fn event( Target::Widget(data.id), )); } - file_explorer.index = index; + file_explorer.active_selected = index; } } _ => (), @@ -420,10 +447,13 @@ fn event( fn lifecycle( &mut self, _ctx: &mut LifeCycleCtx, - _event: &LifeCycle, + event: &LifeCycle, _data: &LapceTabData, _env: &Env, ) { + if let LifeCycle::HotChanged(false) = event { + self.hovered = None; + } } fn update( @@ -469,7 +499,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, _env: &Env) { let rect = ctx.region().bounding_box(); let size = ctx.size(); let width = size.width; - let index = data.file_explorer.index; + let index = data.file_explorer.active_selected; let min = (rect.y0 / self.line_height).floor() as usize; let max = (rect.y1 / self.line_height) as usize + 2; let level = 0; @@ -487,6 +517,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, _env: &Env) { level + 1, i + 1, index, + self.hovered, &data.config, &mut HashMap::new(), ); diff --git a/lapce-ui/src/picker.rs b/lapce-ui/src/picker.rs index a7a45260..aa897acc 100644 --- a/lapce-ui/src/picker.rs +++ b/lapce-ui/src/picker.rs @@ -693,6 +693,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, _env: &Env) { level + 1, i + 1, index, + None, &data.config, &mut self.toggle_rects, );