Add keyboard key scrolling

This commit is contained in:
Nate Levin 2023-08-14 16:28:27 +12:00 committed by Mike Dilger
parent aded50d60f
commit d5d84564a2
4 changed files with 25 additions and 0 deletions

View File

@ -54,6 +54,7 @@ pub struct Settings {
pub posting_area_at_top: bool,
pub status_bar: bool,
pub image_resize_algorithm: String,
pub allow_key_scrolling: bool,
// Staletime settings
pub relay_list_becomes_stale_hours: u64,
@ -141,6 +142,7 @@ impl Default for Settings {
posting_area_at_top: true,
status_bar: false,
image_resize_algorithm: "CatmullRom".to_owned(),
allow_key_scrolling: true,
// Staletime settings
relay_list_becomes_stale_hours: 8,

View File

@ -55,6 +55,7 @@ pub struct Settings2 {
pub posting_area_at_top: bool,
pub status_bar: bool,
pub image_resize_algorithm: String,
pub allow_key_scrolling: bool,
// Staletime settings
pub relay_list_becomes_stale_hours: u64,
@ -142,6 +143,7 @@ impl Default for Settings2 {
posting_area_at_top: true,
status_bar: false,
image_resize_algorithm: "CatmullRom".to_owned(),
allow_key_scrolling: true,
// Staletime settings
relay_list_becomes_stale_hours: 8,

View File

@ -579,6 +579,23 @@ impl eframe::App for GossipUi {
self.future_scroll_offset = 0.0;
}
}
// use keys to scroll
if self.settings.allow_key_scrolling {
ctx.input(|i| {
if i.key_pressed(egui::Key::ArrowDown) {
self.current_scroll_offset -= 30.0;
}
if i.key_pressed(egui::Key::ArrowUp) {
self.current_scroll_offset = 30.0;
}
if i.key_pressed(egui::Key::PageUp) {
self.current_scroll_offset = 150.0;
}
if i.key_pressed(egui::Key::PageDown) {
self.current_scroll_offset -= 150.0;
}
});
}
if self.settings.theme.follow_os_dark_mode {
// detect if the OS has changed dark/light mode

View File

@ -15,6 +15,10 @@ pub(super) fn update(app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fra
&mut app.settings.posting_area_at_top,
"Show posting area at the top instead of the bottom",
);
ui.checkbox(
&mut app.settings.allow_key_scrolling,
"Allows the use of arrow and page keys for scrolling",
);
ui.add_space(20.0);
ui.horizontal(|ui| {