mirror of https://github.com/lapce/lapce.git
fix scroll fade
This commit is contained in:
parent
786839a586
commit
beb7f41c8a
|
@ -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",
|
||||
|
|
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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, F: FnOnce(&mut PaletteViewData) -> V>(
|
|||
#[derive(Clone)]
|
||||
pub struct PaletteData {
|
||||
pub widget_id: WidgetId,
|
||||
pub scroll_id: WidgetId,
|
||||
status: PaletteStatus,
|
||||
proxy: Arc<LapceProxy>,
|
||||
palette_type: PaletteType,
|
||||
|
@ -415,9 +416,11 @@ impl PaletteData {
|
|||
pub fn new(proxy: Arc<LapceProxy>) -> 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<LapceTabData, Box<dyn Widget<LapceTabData>>>,
|
||||
content: WidgetPod<
|
||||
LapceTabData,
|
||||
LapceScrollNew<LapceTabData, Box<dyn Widget<LapceTabData>>>,
|
||||
LapceIdentityWrapper<
|
||||
LapceScrollNew<LapceTabData, Box<dyn Widget<LapceTabData>>>,
|
||||
>,
|
||||
>,
|
||||
preview: WidgetPod<LapceTabData, Box<dyn Widget<LapceTabData>>>,
|
||||
}
|
||||
|
@ -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),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<F>(
|
||||
&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
|
||||
|
|
Loading…
Reference in New Issue