1111back_start_y = 0
1212back_start_x = 0
1313short_movement_threshold = 10
14+ backbutton_visible = False
15+ downbutton_visible = False
16+
17+ def is_short_movement (dx , dy ):
18+ return dx < short_movement_threshold and dy < short_movement_threshold
1419
1520def _back_swipe_cb (event ):
1621 if drawer_open :
1722 print ("ignoring back gesture because drawer is open" )
1823 return
1924
20- global backbutton , back_start_y , back_start_x
25+ global backbutton , back_start_y , back_start_x , backbutton_visible
2126 event_code = event .get_code ()
2227 indev = lv .indev_active ()
2328 if not indev :
@@ -26,21 +31,25 @@ def _back_swipe_cb(event):
2631 indev .get_point (point )
2732 x = point .x
2833 y = point .y
34+ dx = abs (x - back_start_x )
35+ dy = abs (y - back_start_y )
2936 #print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
3037 if event_code == lv .EVENT .PRESSED :
31- smooth_show (backbutton )
3238 back_start_y = y
3339 back_start_x = x
3440 elif event_code == lv .EVENT .PRESSING :
35- magnetic_x = round (x / 10 )
36- backbutton .set_pos (magnetic_x ,back_start_y )
41+ should_show = not is_short_movement (dx , dy )
42+ if should_show != backbutton_visible :
43+ backbutton_visible = should_show
44+ smooth_show (backbutton ) if should_show else smooth_hide (backbutton )
45+ backbutton .set_pos (round (x / 10 ), back_start_y )
3746 elif event_code == lv .EVENT .RELEASED :
38- smooth_hide ( backbutton )
39- dx = abs ( x - back_start_x )
40- dy = abs ( y - back_start_y )
47+ if backbutton_visible :
48+ backbutton_visible = False
49+ smooth_hide ( backbutton )
4150 if x > min (100 , get_display_width () / 4 ):
4251 back_screen ()
43- elif dx < short_movement_threshold and dy < short_movement_threshold :
52+ elif is_short_movement ( dx , dy ) :
4453 # print("Short movement - treating as tap")
4554 obj = lv .indev_search_obj (lv .screen_active (), lv .point_t ({'x' : x , 'y' : y }))
4655 # print(f"Found object: {obj}")
@@ -62,7 +71,7 @@ def _top_swipe_cb(event):
6271 print ("ignoring top swipe gesture because drawer is open" )
6372 return
6473
65- global downbutton , down_start_x , down_start_y
74+ global downbutton , down_start_x , down_start_y , downbutton_visible
6675 event_code = event .get_code ()
6776 indev = lv .indev_active ()
6877 if not indev :
@@ -71,21 +80,27 @@ def _top_swipe_cb(event):
7180 indev .get_point (point )
7281 x = point .x
7382 y = point .y
83+ dx = abs (x - down_start_x )
84+ dy = abs (y - down_start_y )
7485 # print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
7586 if event_code == lv .EVENT .PRESSED :
76- smooth_show (downbutton )
7787 down_start_x = x
7888 down_start_y = y
7989 elif event_code == lv .EVENT .PRESSING :
80- magnetic_y = round (y / 10 )
81- downbutton .set_pos (down_start_x ,magnetic_y )
90+ should_show = not is_short_movement (dx , dy )
91+ if should_show != downbutton_visible :
92+ downbutton_visible = should_show
93+ smooth_show (downbutton ) if should_show else smooth_hide (downbutton )
94+ downbutton .set_pos (down_start_x , round (y / 10 ))
8295 elif event_code == lv .EVENT .RELEASED :
83- smooth_hide (downbutton )
96+ if downbutton_visible :
97+ downbutton_visible = False
98+ smooth_hide (downbutton )
8499 dx = abs (x - down_start_x )
85100 dy = abs (y - down_start_y )
86101 if y > min (80 , get_display_height () / 4 ):
87102 open_drawer ()
88- elif dx < short_movement_threshold and dy < short_movement_threshold :
103+ elif is_short_movement ( dx , dy ) :
89104 # print("Short movement - treating as tap")
90105 obj = lv .indev_search_obj (lv .screen_active (), lv .point_t ({'x' : x , 'y' : y }))
91106 # print(f"Found object: {obj}")
@@ -105,7 +120,7 @@ def _top_swipe_cb(event):
105120def handle_back_swipe ():
106121 global backbutton
107122 rect = lv .obj (lv .layer_top ())
108- rect .set_size (round ( NOTIFICATION_BAR_HEIGHT / 2 ) , lv .layer_top ().get_height ()- NOTIFICATION_BAR_HEIGHT ) # narrow because it overlaps buttons
123+ rect .set_size (NOTIFICATION_BAR_HEIGHT , lv .layer_top ().get_height ()- NOTIFICATION_BAR_HEIGHT ) # narrow because it overlaps buttons
109124 rect .set_scrollbar_mode (lv .SCROLLBAR_MODE .OFF )
110125 rect .set_scroll_dir (lv .DIR .NONE )
111126 rect .set_pos (0 , NOTIFICATION_BAR_HEIGHT )
@@ -139,7 +154,7 @@ def handle_back_swipe():
139154def handle_top_swipe ():
140155 global downbutton
141156 rect = lv .obj (lv .layer_top ())
142- rect .set_size (lv .pct (100 ), round ( NOTIFICATION_BAR_HEIGHT * 2 / 3 ) )
157+ rect .set_size (lv .pct (100 ), NOTIFICATION_BAR_HEIGHT )
143158 rect .set_pos (0 , 0 )
144159 rect .set_scrollbar_mode (lv .SCROLLBAR_MODE .OFF )
145160 style = lv .style_t ()
0 commit comments