From 5a9dddcdaf3443cb75934b4520993cf74740b0c5 Mon Sep 17 00:00:00 2001 From: Bryan Van de Ven Date: Tue, 14 Nov 2023 14:19:58 -0800 Subject: [PATCH] Support arrow keys for vscroll --- src/app.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/app.rs b/src/app.rs index ab68c3c..fc7fb1c 100644 --- a/src/app.rs +++ b/src/app.rs @@ -229,6 +229,9 @@ struct Context { #[serde(skip)] scale_factor: f32, + #[serde(skip)] + row_scroll_delta: i32, + #[serde(skip)] subheading_size: f32, @@ -1706,6 +1709,7 @@ impl Window { } } +#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)] enum PanDirection { Left, Right, @@ -1866,6 +1870,7 @@ impl ProfApp { RedoZoom, ResetZoom, Pan(PercentageInteger, PanDirection), + Scroll(i32), ExpandVertical, ShrinkVertical, ResetVertical, @@ -1903,6 +1908,10 @@ impl ProfApp { Actions::Pan(Percentage::from(1), PanDirection::Left) } else if i.key_pressed(egui::Key::ArrowRight) { Actions::Pan(Percentage::from(1), PanDirection::Right) + } else if i.key_pressed(egui::Key::ArrowUp) { + Actions::Scroll(1) + } else if i.key_pressed(egui::Key::ArrowDown) { + Actions::Scroll(-1) } else { Actions::NoAction } @@ -1914,6 +1923,10 @@ impl ProfApp { Actions::Pan(Percentage::from(5), PanDirection::Left) } else if i.key_pressed(egui::Key::ArrowRight) { Actions::Pan(Percentage::from(5), PanDirection::Right) + } else if i.key_pressed(egui::Key::ArrowUp) { + Actions::Scroll(5) + } else if i.key_pressed(egui::Key::ArrowDown) { + Actions::Scroll(-5) } else { Actions::NoAction } @@ -1925,6 +1938,7 @@ impl ProfApp { Actions::RedoZoom => ProfApp::redo_pan_zoom(cx), Actions::ResetZoom => ProfApp::zoom(cx, cx.total_interval), Actions::Pan(percent, dir) => ProfApp::pan(cx, percent, dir), + Actions::Scroll(rows) => cx.row_scroll_delta = rows, Actions::ExpandVertical => ProfApp::multiply_scale_factor(cx, 2.0), Actions::ShrinkVertical => ProfApp::multiply_scale_factor(cx, 0.5), Actions::ResetVertical => ProfApp::reset_scale_factor(cx), @@ -2068,6 +2082,8 @@ impl ProfApp { show_row("Zoom to Interval", "Click and Drag"); show_row("Pan 5%", "Left/Right Arrow"); show_row("Pan 1%", "Shift + Left/Right Arrow"); + show_row("Vertical Scroll", "Up/Down Arrow"); + show_row("Fine Vertical Scroll", "Shift + Up/Down Arrow"); show_row("Zoom In", "Ctrl + Plus/Equals"); show_row("Zoom Out", "Ctrl + Minus"); show_row("Undo Pan/Zoom", "Ctrl + Left Arrow"); @@ -2391,6 +2407,10 @@ impl eframe::App for ProfApp { // Just set this on every frame for now cx.row_height = row_height * cx.scale_factor; + let y_scroll_delta = cx.row_height * cx.row_scroll_delta as f32; + ui.scroll_with_delta(Vec2::new(0.0, y_scroll_delta)); + cx.row_scroll_delta = 0; + let mut remaining = windows.len(); // Only wrap in a frame if more than one profile if remaining > 1 {