mirror of https://github.com/lapce/lapce.git
Highlight the currently hovered file
This commit is contained in:
parent
cf12bfe738
commit
dfb9358a99
|
@ -61,6 +61,7 @@ magenta = "#C678DD"
|
|||
|
||||
"panel.background" = "#21252B"
|
||||
"panel.current" = "#2C313A"
|
||||
"panel.hovered" = "#343A45"
|
||||
|
||||
"status.background" = "#21252B"
|
||||
|
||||
|
|
|
@ -60,6 +60,7 @@ magenta = "#A626A4"
|
|||
|
||||
"panel.background" = "#eaeaeb"
|
||||
"panel.current" = "#dbdbdc"
|
||||
"panel.hovered" = "#E4E4E6"
|
||||
|
||||
"status.background" = "#eaeaeb"
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ pub struct FileExplorerData {
|
|||
pub tab_id: WidgetId,
|
||||
pub widget_id: WidgetId,
|
||||
pub workspace: Option<FileNodeItem>,
|
||||
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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ pub fn paint_file_node_item(
|
|||
level: usize,
|
||||
current: usize,
|
||||
active: usize,
|
||||
hovered: Option<usize>,
|
||||
config: &Config,
|
||||
toggle_rects: &mut HashMap<usize, Rect>,
|
||||
) -> 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<usize>,
|
||||
}
|
||||
|
||||
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(),
|
||||
);
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue