Skip to content

Commit 81e4f5c

Browse files
committed
[Rust - agx] Scale scroll step by the size of the content view
1 parent d1f0b1e commit 81e4f5c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

rust_programs/libgui/src/scroll_view.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -855,10 +855,22 @@ impl UIElement for ScrollView {
855855
fn handle_mouse_scrolled(&self, _mouse_point: Point, delta_z: isize) {
856856
//println!("ScrollView.handle_mouse_scrolled({delta_z})");
857857
let mut scroll_offset = self.layer.scroll_offset();
858-
scroll_offset.y += delta_z * 20;
859858
self.layer.set_scroll_offset(scroll_offset);
860859
//self.draw()
861860
Bordered::draw(self);
861+
let content_frame = self.layer.total_content_frame();
862+
// Scale how much the mouse scrolls by based on how large the content view is
863+
// TODO(PT): Scale by how fast the user is scrolling
864+
let scroll_step = {
865+
if content_frame.height() > 10000 {
866+
10
867+
} else if content_frame.height() > 1000 {
868+
5
869+
} else {
870+
1
871+
}
872+
};
873+
scroll_offset.y += delta_z * scroll_step;
862874
}
863875

864876
fn handle_key_released(&self, key: KeyCode) {

0 commit comments

Comments
 (0)