From 1e5123af17907b3f8c8db0a6a6959b016cbb151e Mon Sep 17 00:00:00 2001 From: ellieplayswow <164806095+ellieplayswow@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:30:40 +0000 Subject: [PATCH] Fixing issue with scroll speed subscription not working in dev profile, removing speed code as redundant --- src/app.rs | 20 ++++++++++++++------ src/tab.rs | 24 ++---------------------- 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/src/app.rs b/src/app.rs index 5bce184..1aca306 100644 --- a/src/app.rs +++ b/src/app.rs @@ -333,7 +333,7 @@ pub enum Message { Rename(Option), ReplaceResult(ReplaceResult), RestoreFromTrash(Option), - ScrollTab(f32), + ScrollTab(i16), SearchActivate, SearchClear, SearchInput(String), @@ -552,7 +552,7 @@ pub struct App { tab_dnd_hover: Option<(Entity, Instant)>, nav_drag_id: DragId, tab_drag_id: DragId, - auto_scroll_speed: Option + auto_scroll_speed: Option } impl App { @@ -2800,7 +2800,7 @@ impl Application for App { } Message::ScrollTab(scroll_speed) => { let entity = self.tab_model.active(); - return self.update(Message::TabMessage(Some(entity), tab::Message::ScrollTab(scroll_speed))); + return self.update(Message::TabMessage(Some(entity), tab::Message::ScrollTab((scroll_speed as f32) / 10.0))); } Message::SearchActivate => { return if self.search_get().is_none() { @@ -2940,7 +2940,15 @@ impl Application for App { commands.push(self.update_config()); } tab::Command::AutoScroll(scroll_speed) => { - self.auto_scroll_speed = scroll_speed; + // converting an f32 to an i16 here by multiplying by 10 and casting to i16 + // further resolution isn't necessary + if let Some(scroll_speed_float) = scroll_speed { + self.auto_scroll_speed = Some((scroll_speed_float * 10.0) as i16); + } + else { + self.auto_scroll_speed = None; + } + } tab::Command::ChangeLocation(tab_title, tab_path, selection_paths) => { self.activate_nav_model_location(&tab_path); @@ -4727,8 +4735,8 @@ impl Application for App { if let Some(scroll_speed) = self.auto_scroll_speed { subscriptions.push( - iced::time::every(time::Duration::from_millis(10)) - .map(move |_| Message::ScrollTab(scroll_speed)) + iced::time::every(time::Duration::from_millis(10)).with(scroll_speed) + .map(|(scroll_speed, _)| Message::ScrollTab(scroll_speed)) ); } diff --git a/src/tab.rs b/src/tab.rs index 71a1304..f0a1071 100644 --- a/src/tab.rs +++ b/src/tab.rs @@ -84,7 +84,6 @@ const MAX_SEARCH_RESULTS: usize = 200; const THUMBNAIL_SIZE: u32 = (ICON_SIZE_GRID as u32) * (ICON_SCALE_MAX as u32); const DRAG_SCROLL_DISTANCE: f32 = 15.0; -const DRAG_SCROLL_RATIO_MAXIMUM: f32 = 3.0; //TODO: adjust for locales? const DATE_TIME_FORMAT: &str = "%b %-d, %-Y, %-I:%M %p"; @@ -2234,7 +2233,7 @@ impl Tab { // diff_y should be NEGATIVE here when close to y=0 (above the MouseArea) // and positive when below the viewport let diff_y = pos.y - drag_start_point.y; - let mut scroll_y: f32 = if diff_y > 0.0 { + let scroll_y: f32 = if diff_y > 0.0 { DRAG_SCROLL_DISTANCE } else if diff_y < 0.0 { DRAG_SCROLL_DISTANCE * -1.0 @@ -2242,25 +2241,6 @@ impl Tab { 0.0 }; - - // estimate distance and use that to control speed - // go up to 3x speed - let quarter_height = viewport.height / 4.0; - let cursor_y_distance = if diff_y > 0.0 { - pos.y - (viewport.y + viewport.height) - } else if diff_y < 0.0 { - pos.y - viewport.y - } else { - 0.0 - }.abs(); - - let mut speed_ratio = (cursor_y_distance / quarter_height) + 1.0; - if speed_ratio > DRAG_SCROLL_RATIO_MAXIMUM { - speed_ratio = DRAG_SCROLL_RATIO_MAXIMUM; - } - - scroll_y = scroll_y * speed_ratio; - let mut new_offset = Point { x: 0.0, y: scroll_y @@ -2274,7 +2254,7 @@ impl Tab { } if let Some(last_scroll_position) = self.last_scroll_position { - new_offset.x = (pos.x - last_scroll_position.x); + new_offset.x = pos.x - last_scroll_position.x; } self.virtual_cursor_offset = Some(new_offset);