style: hide mouse hover effects with keyboard interaction in miller views
2 files changed, +19 -1
+4-0src/widgets/hover_row.rs
| @@ -9,7 +9,11 @@ pub fn prev_frame_hover( | ||
| 9 | 9 | } |
| 10 | 10 | |
| 11 | 11 | /// Check hover for a pre-computed Id. |
| 12 | +/// Returns false when keyboard navigation is active (see `miller::keyboard_active`). | |
| 12 | 13 | pub fn check_hover(ctx: &egui::Context, id: egui::Id) -> (bool, egui::Id) { |
| 14 | + if super::miller::keyboard_active(ctx) { | |
| 15 | + return (false, id); | |
| 16 | + } | |
| 13 | 17 | let hovered = ctx.data(|d| d.get_temp::<bool>(id)).unwrap_or(false); |
| 14 | 18 | (hovered, id) |
| 15 | 19 | } |
+15-1src/widgets/miller.rs
| @@ -12,8 +12,16 @@ pub enum MillerAction { | ||
| 12 | 12 | None, |
| 13 | 13 | } |
| 14 | 14 | |
| 15 | +const KEYBOARD_ACTIVE_ID: &str = "miller_keyboard_active"; | |
| 16 | + | |
| 17 | +/// Returns true if keyboard navigation happened this frame (suppresses hover highlights). | |
| 18 | +pub fn keyboard_active(ctx: &egui::Context) -> bool { | |
| 19 | + ctx.data(|d| d.get_temp::<bool>(egui::Id::new(KEYBOARD_ACTIVE_ID))).unwrap_or(false) | |
| 20 | +} | |
| 21 | + | |
| 15 | 22 | /// Read J/K/H/L/Arrow/Home/End/G keys and return the corresponding action. |
| 16 | 23 | /// Pass `skip: true` to suppress (e.g., when a text input has focus). |
| 24 | +/// When a key is pressed, hover highlights are suppressed for this frame. | |
| 17 | 25 | pub fn read_miller_keys(ui: &Ui, skip: bool) -> MillerAction { |
| 18 | 26 | if skip { |
| 19 | 27 | return MillerAction::None; |
| @@ -34,7 +42,7 @@ pub fn read_miller_keys(ui: &Ui, skip: bool) -> MillerAction { | ||
| 34 | 42 | let go_top = ui.input(|i| i.key_pressed(egui::Key::G) || i.key_pressed(egui::Key::Home)); |
| 35 | 43 | let go_bottom = ui.input(|i| i.key_pressed(egui::Key::End)); |
| 36 | 44 | |
| 37 | - if down { | |
| 45 | + let action = if down { | |
| 38 | 46 | MillerAction::Down |
| 39 | 47 | } else if up { |
| 40 | 48 | MillerAction::Up |
| @@ -48,7 +56,13 @@ pub fn read_miller_keys(ui: &Ui, skip: bool) -> MillerAction { | ||
| 48 | 56 | MillerAction::GoBottom |
| 49 | 57 | } else { |
| 50 | 58 | MillerAction::None |
| 59 | + }; | |
| 60 | + | |
| 61 | + if action != MillerAction::None { | |
| 62 | + ui.ctx().data_mut(|d| d.insert_temp(egui::Id::new(KEYBOARD_ACTIVE_ID), true)); | |
| 51 | 63 | } |
| 64 | + | |
| 65 | + action | |
| 52 | 66 | } |
| 53 | 67 | |
| 54 | 68 | /// Apply a navigation action to a selection index. |