Skip to content

Commit 1157086

Browse files
committed
disable egui's built-in arrow navigation
This feature was introduced in emilk/egui#3272. Since malakal implements its own keyboard navigation it conflicts with egui's built-in arrow navigation and causes the focus to jump around unexpectedly.
1 parent 1cbbfc9 commit 1157086

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/widget/schedule_ui/interaction.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use std::{collections::HashMap, sync::Arc};
33
use bimap::BiMap;
44
use chrono::{Duration, Timelike};
55
use eframe::egui::{
6-
self, text::LayoutJob, CursorIcon, Key, Label, LayerId, Modifiers, Rect,
7-
Response, Sense, Ui,
6+
self, text::LayoutJob, CursorIcon, EventFilter, Key, KeyboardShortcut, Label,
7+
LayerId, Modifiers, Rect, Response, Sense, Ui,
88
};
99
use egui_autocomplete::AutoCompleteTextEdit;
1010
use humantime;
@@ -490,9 +490,9 @@ impl ScheduleUi {
490490
}
491491

492492
pub(super) fn handle_hotkeys(&mut self, ui: &Ui) {
493-
self.handle_keyboard_focus_move(ui);
494-
self.handle_keyboard_focused_event_move(ui);
495493
self.handle_keyboard_focused_event_resize(ui);
494+
self.handle_keyboard_focused_event_move(ui);
495+
self.handle_keyboard_focus_move(ui);
496496
self.handle_keyboard_new_event(ui);
497497
self.handle_keyboard_delete_event(ui);
498498
}
@@ -503,7 +503,9 @@ impl ScheduleUi {
503503
modifiers: Modifiers,
504504
) -> Option<Direction> {
505505
use Direction::*;
506-
let pressed = |k| ui.input_mut(|input| input.consume_key(modifiers, k));
506+
let shortcut = |k| KeyboardShortcut::new(modifiers, k);
507+
let pressed =
508+
|k| ui.input_mut(|input| input.consume_shortcut(&shortcut(k)));
507509

508510
// do not interrupt interacting events
509511
if InteractingEvent::is_interacting(ui) {
@@ -694,6 +696,7 @@ impl ScheduleUi {
694696

695697
let button = egui::Button::new(layout).sense(Sense::click_and_drag());
696698
let resp = ui.put(rect, button);
699+
disable_built_in_keyboard_focus_navigation(&resp);
697700

698701
if clipped {
699702
// text is clipped, show a tooltip
@@ -802,9 +805,10 @@ impl ScheduleUi {
802805
let editor = AutoCompleteTextEdit::new(&mut event.title, &candidates)
803806
.max_suggestions(5)
804807
.highlight_matches(true);
805-
// uncomment the following to use pure egui textedit
806808

809+
// uncomment the following to use pure egui textedit
807810
// let editor = egui::TextEdit::singleline(&mut event.title);
811+
808812
let resp = ui.put(rect, editor);
809813

810814
// Anything dragging outside the textedit should be equivalent to
@@ -826,6 +830,7 @@ impl ScheduleUi {
826830
}
827831

828832
resp.request_focus();
833+
disable_built_in_keyboard_focus_navigation(&resp);
829834
None
830835
}
831836

@@ -1125,3 +1130,16 @@ fn find_adjacent_event(
11251130

11261131
Some(events[new_i as usize].id.clone())
11271132
}
1133+
1134+
fn disable_built_in_keyboard_focus_navigation(resp: &Response) {
1135+
// avoid built-in arrow navigation
1136+
let event_filter = EventFilter {
1137+
horizontal_arrows: true,
1138+
vertical_arrows: true,
1139+
..Default::default()
1140+
};
1141+
1142+
resp
1143+
.ctx
1144+
.memory_mut(|m| m.set_focus_lock_filter(resp.id, event_filter));
1145+
}

0 commit comments

Comments
 (0)