|
1 | 1 | use egui::{style::ScrollAnimation, vec2, Context, Key, Modifiers, PointerButton};
|
2 | 2 |
|
| 3 | +fn any_widget_focused(ctx: &Context) -> bool { ctx.memory(|mem| mem.focused().is_some()) } |
| 4 | + |
3 | 5 | pub fn enter_pressed(ctx: &Context) -> bool {
|
| 6 | + if any_widget_focused(ctx) { |
| 7 | + return false; |
| 8 | + } |
4 | 9 | ctx.input_mut(|i| i.key_pressed(Key::Enter) || i.pointer.button_pressed(PointerButton::Extra2))
|
5 | 10 | }
|
6 | 11 |
|
7 | 12 | pub fn back_pressed(ctx: &Context) -> bool {
|
| 13 | + if any_widget_focused(ctx) { |
| 14 | + return false; |
| 15 | + } |
8 | 16 | ctx.input_mut(|i| {
|
9 | 17 | i.key_pressed(Key::Backspace) || i.pointer.button_pressed(PointerButton::Extra1)
|
10 | 18 | })
|
11 | 19 | }
|
12 | 20 |
|
13 | 21 | pub fn up_pressed(ctx: &Context) -> bool {
|
| 22 | + if any_widget_focused(ctx) { |
| 23 | + return false; |
| 24 | + } |
14 | 25 | ctx.input_mut(|i| i.key_pressed(Key::ArrowUp) || i.key_pressed(Key::W))
|
15 | 26 | }
|
16 | 27 |
|
17 | 28 | pub fn down_pressed(ctx: &Context) -> bool {
|
| 29 | + if any_widget_focused(ctx) { |
| 30 | + return false; |
| 31 | + } |
18 | 32 | ctx.input_mut(|i| i.key_pressed(Key::ArrowDown) || i.key_pressed(Key::S))
|
19 | 33 | }
|
20 | 34 |
|
@@ -44,12 +58,18 @@ pub fn check_scroll_hotkeys(ui: &mut egui::Ui, include_small_increments: bool) {
|
44 | 58 | }
|
45 | 59 |
|
46 | 60 | pub fn consume_up_key(ctx: &Context) -> bool {
|
| 61 | + if any_widget_focused(ctx) { |
| 62 | + return false; |
| 63 | + } |
47 | 64 | ctx.input_mut(|i| {
|
48 | 65 | i.consume_key(Modifiers::NONE, Key::ArrowUp) || i.consume_key(Modifiers::NONE, Key::W)
|
49 | 66 | })
|
50 | 67 | }
|
51 | 68 |
|
52 | 69 | pub fn consume_down_key(ctx: &Context) -> bool {
|
| 70 | + if any_widget_focused(ctx) { |
| 71 | + return false; |
| 72 | + } |
53 | 73 | ctx.input_mut(|i| {
|
54 | 74 | i.consume_key(Modifiers::NONE, Key::ArrowDown) || i.consume_key(Modifiers::NONE, Key::S)
|
55 | 75 | })
|
|
0 commit comments