From d5d84564a2a4114fa4dffebe58652f3d01b8fb16 Mon Sep 17 00:00:00 2001 From: Nate Levin Date: Mon, 14 Aug 2023 16:28:27 +1200 Subject: [PATCH] Add keyboard key scrolling --- src/settings.rs | 2 ++ src/storage/migrations/settings/settings2.rs | 2 ++ src/ui/mod.rs | 17 +++++++++++++++++ src/ui/settings/ui.rs | 4 ++++ 4 files changed, 25 insertions(+) diff --git a/src/settings.rs b/src/settings.rs index d5219828..90d23b88 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -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, diff --git a/src/storage/migrations/settings/settings2.rs b/src/storage/migrations/settings/settings2.rs index 54c1899c..241e770c 100644 --- a/src/storage/migrations/settings/settings2.rs +++ b/src/storage/migrations/settings/settings2.rs @@ -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, diff --git a/src/ui/mod.rs b/src/ui/mod.rs index 4103c2f5..0fc8c2b6 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -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 diff --git a/src/ui/settings/ui.rs b/src/ui/settings/ui.rs index 35061b25..cd47e748 100644 --- a/src/ui/settings/ui.rs +++ b/src/ui/settings/ui.rs @@ -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| {