Skip to content

Commit

Permalink
Support arrow keys for vscroll (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
bryevdv authored Dec 13, 2023
1 parent b630017 commit 90f9660
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 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 @@ -1707,6 +1710,7 @@ impl Window {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
enum PanDirection {
Left,
Right,
Expand Down Expand Up @@ -1738,6 +1742,7 @@ impl ProfApp {
result.windows.clear();

result.cx.scale_factor = 1.0;
result.cx.row_scroll_delta = 0;

#[cfg(not(target_arch = "wasm32"))]
{
Expand Down Expand Up @@ -1867,6 +1872,7 @@ impl ProfApp {
RedoZoom,
ResetZoom,
Pan(PercentageInteger, PanDirection),
Scroll(i32),
ExpandVertical,
ShrinkVertical,
ResetVertical,
Expand Down Expand Up @@ -1904,6 +1910,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 @@ -1915,6 +1925,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 @@ -1926,6 +1940,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 @@ -2069,6 +2084,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 @@ -2392,6 +2409,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 90f9660

Please sign in to comment.