Skip to content

Commit 76f1952

Browse files
committed
Add scroll hotkeys
1 parent e448630 commit 76f1952

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

objdiff-gui/src/hotkeys.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use egui::{Context, Key, PointerButton};
1+
use egui::{style::ScrollAnimation, vec2, Context, Key, PointerButton};
22

33
pub fn enter_pressed(ctx: &Context) -> bool {
44
ctx.input_mut(|i| i.key_pressed(Key::Enter) || i.pointer.button_pressed(PointerButton::Extra2))
@@ -9,3 +9,36 @@ pub fn back_pressed(ctx: &Context) -> bool {
99
i.key_pressed(Key::Backspace) || i.pointer.button_pressed(PointerButton::Extra1)
1010
})
1111
}
12+
13+
pub fn up_pressed(ctx: &Context) -> bool {
14+
ctx.input_mut(|i| i.key_pressed(Key::ArrowUp) || i.key_pressed(Key::W))
15+
}
16+
17+
pub fn down_pressed(ctx: &Context) -> bool {
18+
ctx.input_mut(|i| i.key_pressed(Key::ArrowDown) || i.key_pressed(Key::S))
19+
}
20+
21+
pub fn page_up_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::PageUp)) }
22+
23+
pub fn page_down_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::PageDown)) }
24+
25+
pub fn home_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::Home)) }
26+
27+
pub fn end_pressed(ctx: &Context) -> bool { ctx.input_mut(|i| i.key_pressed(Key::End)) }
28+
29+
pub fn check_scroll_hotkeys(ui: &mut egui::Ui) {
30+
let ui_height = ui.available_rect_before_wrap().height();
31+
if up_pressed(ui.ctx()) {
32+
ui.scroll_with_delta_animation(vec2(0.0, ui_height / 10.0), ScrollAnimation::none());
33+
} else if down_pressed(ui.ctx()) {
34+
ui.scroll_with_delta_animation(vec2(0.0, -ui_height / 10.0), ScrollAnimation::none());
35+
} else if page_up_pressed(ui.ctx()) {
36+
ui.scroll_with_delta_animation(vec2(0.0, ui_height), ScrollAnimation::none());
37+
} else if page_down_pressed(ui.ctx()) {
38+
ui.scroll_with_delta_animation(vec2(0.0, -ui_height), ScrollAnimation::none());
39+
} else if home_pressed(ui.ctx()) {
40+
ui.scroll_with_delta_animation(vec2(0.0, f32::INFINITY), ScrollAnimation::none());
41+
} else if end_pressed(ui.ctx()) {
42+
ui.scroll_with_delta_animation(vec2(0.0, -f32::INFINITY), ScrollAnimation::none());
43+
}
44+
}

objdiff-gui/src/views/data_diff.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ fn data_table_ui(
179179
let left_diffs = left_section.map(|(_, section)| split_diffs(&section.data_diff));
180180
let right_diffs = right_section.map(|(_, section)| split_diffs(&section.data_diff));
181181

182+
hotkeys::check_scroll_hotkeys(ui);
183+
182184
render_table(ui, available_width, 2, config.code_font.size, total_rows, |row, column| {
183185
let i = row.index();
184186
let address = i * BYTES_PER_ROW;

objdiff-gui/src/views/extab_diff.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ pub fn extab_diff_ui(
235235
}
236236
});
237237

238+
hotkeys::check_scroll_hotkeys(ui);
239+
238240
// Table
239241
render_strips(ui, available_width, 2, |ui, column| {
240242
if column == 0 {

objdiff-gui/src/views/function_diff.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ fn asm_table_ui(
435435
};
436436
if left_len.is_some() && right_len.is_some() {
437437
// Joint view
438+
hotkeys::check_scroll_hotkeys(ui);
438439
render_table(
439440
ui,
440441
available_width,

objdiff-gui/src/views/symbol_diff.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,8 @@ pub fn symbol_list_ui(
649649
}
650650
}
651651

652+
hotkeys::check_scroll_hotkeys(ui);
653+
652654
ui.scope(|ui| {
653655
ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
654656
ui.style_mut().wrap_mode = Some(egui::TextWrapMode::Extend);

0 commit comments

Comments
 (0)