1
- use egui:: { Context , Key , PointerButton } ;
1
+ use egui:: { style :: ScrollAnimation , vec2 , Context , Key , PointerButton } ;
2
2
3
3
pub fn enter_pressed ( ctx : & Context ) -> bool {
4
4
ctx. input_mut ( |i| i. key_pressed ( Key :: Enter ) || i. pointer . button_pressed ( PointerButton :: Extra2 ) )
@@ -9,3 +9,36 @@ pub fn back_pressed(ctx: &Context) -> bool {
9
9
i. key_pressed ( Key :: Backspace ) || i. pointer . button_pressed ( PointerButton :: Extra1 )
10
10
} )
11
11
}
12
+
13
+ pub fn up_pressed ( ctx : & Context ) -> bool {
14
+ ctx. input_mut ( |i| i. key_pressed ( Key :: ArrowUp ) || i. key_pressed ( Key :: W ) )
15
+ }
16
+
17
+ pub fn down_pressed ( ctx : & Context ) -> bool {
18
+ ctx. input_mut ( |i| i. key_pressed ( Key :: ArrowDown ) || i. key_pressed ( Key :: S ) )
19
+ }
20
+
21
+ pub fn page_up_pressed ( ctx : & Context ) -> bool { ctx. input_mut ( |i| i. key_pressed ( Key :: PageUp ) ) }
22
+
23
+ pub fn page_down_pressed ( ctx : & Context ) -> bool { ctx. input_mut ( |i| i. key_pressed ( Key :: PageDown ) ) }
24
+
25
+ pub fn home_pressed ( ctx : & Context ) -> bool { ctx. input_mut ( |i| i. key_pressed ( Key :: Home ) ) }
26
+
27
+ pub fn end_pressed ( ctx : & Context ) -> bool { ctx. input_mut ( |i| i. key_pressed ( Key :: End ) ) }
28
+
29
+ pub fn check_scroll_hotkeys ( ui : & mut egui:: Ui ) {
30
+ let ui_height = ui. available_rect_before_wrap ( ) . height ( ) ;
31
+ if up_pressed ( ui. ctx ( ) ) {
32
+ ui. scroll_with_delta_animation ( vec2 ( 0.0 , ui_height / 10.0 ) , ScrollAnimation :: none ( ) ) ;
33
+ } else if down_pressed ( ui. ctx ( ) ) {
34
+ ui. scroll_with_delta_animation ( vec2 ( 0.0 , -ui_height / 10.0 ) , ScrollAnimation :: none ( ) ) ;
35
+ } else if page_up_pressed ( ui. ctx ( ) ) {
36
+ ui. scroll_with_delta_animation ( vec2 ( 0.0 , ui_height) , ScrollAnimation :: none ( ) ) ;
37
+ } else if page_down_pressed ( ui. ctx ( ) ) {
38
+ ui. scroll_with_delta_animation ( vec2 ( 0.0 , -ui_height) , ScrollAnimation :: none ( ) ) ;
39
+ } else if home_pressed ( ui. ctx ( ) ) {
40
+ ui. scroll_with_delta_animation ( vec2 ( 0.0 , f32:: INFINITY ) , ScrollAnimation :: none ( ) ) ;
41
+ } else if end_pressed ( ui. ctx ( ) ) {
42
+ ui. scroll_with_delta_animation ( vec2 ( 0.0 , -f32:: INFINITY ) , ScrollAnimation :: none ( ) ) ;
43
+ }
44
+ }
0 commit comments