Skip to content

Commit

Permalink
Support arrow keys for vscroll
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv committed Nov 14, 2023
1 parent 99e0642 commit 5a9dddc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ struct Context {
#[serde(skip)]
scale_factor: f32,

#[serde(skip)]
row_scroll_delta: i32,

#[serde(skip)]
subheading_size: f32,

Expand Down Expand Up @@ -1706,6 +1709,7 @@ impl Window {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
enum PanDirection {
Left,
Right,
Expand Down Expand Up @@ -1866,6 +1870,7 @@ impl ProfApp {
RedoZoom,
ResetZoom,
Pan(PercentageInteger, PanDirection),
Scroll(i32),
ExpandVertical,
ShrinkVertical,
ResetVertical,
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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),
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5a9dddc

Please sign in to comment.