Fixing issue with scroll speed subscription not working in dev profile, removing speed code as redundant

This commit is contained in:
ellieplayswow 2025-02-19 19:30:40 +00:00
parent 9d60ca1564
commit 1e5123af17
2 changed files with 16 additions and 28 deletions

View file

@ -333,7 +333,7 @@ pub enum Message {
Rename(Option<Entity>),
ReplaceResult(ReplaceResult),
RestoreFromTrash(Option<Entity>),
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<f32>
auto_scroll_speed: Option<i16>
}
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))
);
}

View file

@ -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);