From beb7f41c8a8020b9892fce2a65b01306b1279fa9 Mon Sep 17 00:00:00 2001 From: Dongdong Zhou Date: Mon, 20 Sep 2021 17:51:51 +0100 Subject: [PATCH] fix scroll fade --- Cargo.lock | 6 +++--- core/src/completion.rs | 17 ++++++++++++----- core/src/editor.rs | 32 +++++++++++++++++++++++++------- core/src/palette.rs | 37 ++++++++++++++++++++++++++----------- core/src/scroll.rs | 32 +++++++++++++------------------- 5 files changed, 79 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d63c610..8f0eddc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1025,7 +1025,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "druid" version = "0.7.0" -source = "git+https://github.com/lapce/druid#a29f4f47218a9144285ddf2c466e7f1f28d7b3e9" +source = "git+https://github.com/lapce/druid#e121a48816c6b9b742d6fb941a8da0abf10123e3" dependencies = [ "console_error_panic_hook", "druid-derive", @@ -1049,7 +1049,7 @@ dependencies = [ [[package]] name = "druid-derive" version = "0.4.0" -source = "git+https://github.com/lapce/druid#a29f4f47218a9144285ddf2c466e7f1f28d7b3e9" +source = "git+https://github.com/lapce/druid#e121a48816c6b9b742d6fb941a8da0abf10123e3" dependencies = [ "proc-macro2 1.0.29", "quote 1.0.9", @@ -1059,7 +1059,7 @@ dependencies = [ [[package]] name = "druid-shell" version = "0.7.0" -source = "git+https://github.com/lapce/druid#a29f4f47218a9144285ddf2c466e7f1f28d7b3e9" +source = "git+https://github.com/lapce/druid#e121a48816c6b9b742d6fb941a8da0abf10123e3" dependencies = [ "anyhow", "bitflags", diff --git a/core/src/completion.rs b/core/src/completion.rs index e5c1cd64..b5238b7f 100644 --- a/core/src/completion.rs +++ b/core/src/completion.rs @@ -466,11 +466,18 @@ pub fn ensure_item_visble( 0.0, data.completion.index as f64 * line_height, )); - self.completion.widget_mut().inner_mut().scroll_to_visible( - rect, - |d| ctx.request_timer(d), - env, - ); + if self + .completion + .widget_mut() + .inner_mut() + .scroll_to_visible(rect, env) + { + ctx.submit_command(Command::new( + LAPCE_UI_COMMAND, + LapceUICommand::ResetFade, + Target::Widget(self.scroll_id), + )); + } } } diff --git a/core/src/editor.rs b/core/src/editor.rs index 5fd5a73e..72bd9472 100644 --- a/core/src/editor.rs +++ b/core/src/editor.rs @@ -477,7 +477,13 @@ pub fn ensure_cursor_center( ); let scroll = self.editor.widget_mut().inner_mut(); scroll.set_child_size(size); - scroll.scroll_to_visible(rect, |d| ctx.request_timer(d), env); + if scroll.scroll_to_visible(rect, env) { + ctx.submit_command(Command::new( + LAPCE_UI_COMMAND, + LapceUICommand::ResetFade, + Target::Widget(self.scroll_id), + )); + } } pub fn ensure_rect_visible( @@ -487,11 +493,18 @@ pub fn ensure_rect_visible( rect: Rect, env: &Env, ) { - self.editor.widget_mut().inner_mut().scroll_to_visible( - rect, - |d| ctx.request_timer(d), - env, - ); + if self + .editor + .widget_mut() + .inner_mut() + .scroll_to_visible(rect, env) + { + ctx.submit_command(Command::new( + LAPCE_UI_COMMAND, + LapceUICommand::ResetFade, + Target::Widget(self.scroll_id), + )); + } } pub fn ensure_cursor_visible( @@ -514,7 +527,12 @@ pub fn ensure_cursor_visible( let scroll = self.editor.widget_mut().inner_mut(); scroll.set_child_size(size); let old_scroll_offset = scroll.offset(); - if scroll.scroll_to_visible(rect, |d| ctx.request_timer(d), env) { + if scroll.scroll_to_visible(rect, env) { + ctx.submit_command(Command::new( + LAPCE_UI_COMMAND, + LapceUICommand::ResetFade, + Target::Widget(self.scroll_id), + )); if let Some(position) = position { match position { EnsureVisiblePosition::CenterOfWindow => { diff --git a/core/src/palette.rs b/core/src/palette.rs index f73406e9..24543ceb 100644 --- a/core/src/palette.rs +++ b/core/src/palette.rs @@ -47,7 +47,7 @@ keypress::{KeyPressData, KeyPressFocus}, movement::Movement, proxy::LapceProxy, - scroll::{LapceScroll, LapceScrollNew}, + scroll::{LapceIdentityWrapper, LapceScroll, LapceScrollNew}, state::LapceFocus, state::LapceWorkspace, state::LapceWorkspaceType, @@ -346,6 +346,7 @@ fn with_mut V>( #[derive(Clone)] pub struct PaletteData { pub widget_id: WidgetId, + pub scroll_id: WidgetId, status: PaletteStatus, proxy: Arc, palette_type: PaletteType, @@ -415,9 +416,11 @@ impl PaletteData { pub fn new(proxy: Arc) -> Self { let (sender, receiver) = unbounded(); let widget_id = WidgetId::next(); + let scroll_id = WidgetId::next(); let preview_editor = WidgetId::next(); Self { widget_id, + scroll_id, status: PaletteStatus::Inactive, proxy, palette_type: PaletteType::File, @@ -1921,7 +1924,9 @@ pub struct PaletteContainer { input: WidgetPod>>, content: WidgetPod< LapceTabData, - LapceScrollNew>>, + LapceIdentityWrapper< + LapceScrollNew>>, + >, >, preview: WidgetPod>>, } @@ -1934,10 +1939,13 @@ pub fn new(data: &PaletteData, preview_editor: &LapceEditorData) -> Self { .background(LapceTheme::EDITOR_BACKGROUND) .padding((padding, padding, padding, padding)) .lens(PaletteViewLens); - let content = LapceScrollNew::new( - NewPaletteContent::new().lens(PaletteViewLens).boxed(), - ) - .vertical(); + let content = LapceIdentityWrapper::wrap( + LapceScrollNew::new( + NewPaletteContent::new().lens(PaletteViewLens).boxed(), + ) + .vertical(), + data.scroll_id, + ); let preview = LapceEditorView::new(preview_editor); Self { content_size: Size::ZERO, @@ -1958,11 +1966,18 @@ fn ensure_item_visble( let rect = Size::new(width, line_height) .to_rect() .with_origin(Point::new(0.0, palette.index as f64 * line_height)); - self.content.widget_mut().scroll_to_visible( - rect, - |d| ctx.request_timer(d), - env, - ); + if self + .content + .widget_mut() + .inner_mut() + .scroll_to_visible(rect, env) + { + ctx.submit_command(Command::new( + LAPCE_UI_COMMAND, + LapceUICommand::ResetFade, + Target::Widget(palette.scroll_id), + )); + } } } diff --git a/core/src/scroll.rs b/core/src/scroll.rs index ffefbfc3..5af15de9 100644 --- a/core/src/scroll.rs +++ b/core/src/scroll.rs @@ -1414,20 +1414,24 @@ pub fn draw_bars(&self, ctx: &mut PaintCtx, port: &ViewportNew, env: &Env) { // Vertical bar if let Some(bounds) = self.calc_vertical_bar_bounds(port, env) { - let rect = (bounds - scroll_offset) - .inset(-edge_width / 2.0) - .to_rounded_rect(radius); + let rect = (bounds - scroll_offset).inset(-edge_width / 2.0); ctx.render_ctx.fill(rect, &brush); ctx.render_ctx.stroke(rect, &border_brush, edge_width); } // Horizontal bar if let Some(bounds) = self.calc_horizontal_bar_bounds(port, env) { - let rect = (bounds - scroll_offset) - .inset(-edge_width / 2.0) - .to_rounded_rect(radius); - ctx.render_ctx.fill(rect, &brush); - ctx.render_ctx.stroke(rect, &border_brush, edge_width); + let rect = (bounds - scroll_offset).inset(-edge_width / 2.0); + ctx.render_ctx.fill( + rect, + &env.get(theme::SCROLLBAR_COLOR).with_alpha(self.opacity), + ); + ctx.render_ctx.stroke( + rect, + &env.get(theme::SCROLLBAR_BORDER_COLOR) + .with_alpha(self.opacity), + edge_width, + ); } } @@ -1740,18 +1744,8 @@ pub fn scroll_to(&mut self, point: Point) -> bool { /// /// If the target region is larger than the viewport, we will display the /// portion that fits, prioritizing the portion closest to the origin. - pub fn scroll_to_visible( - &mut self, - region: Rect, - request_timer: F, - env: &Env, - ) -> bool - where - F: FnOnce(Duration) -> TimerToken, - { + pub fn scroll_to_visible(&mut self, region: Rect, env: &Env) -> bool { if self.clip.pan_to_visible(region) { - self.scroll_component - .reset_scrollbar_fade(request_timer, env); true } else { false