Skip to content

Commit 71ab5d1

Browse files
Fix top swipe gesture
1 parent a2af392 commit 71ab5d1

File tree

2 files changed

+63
-39
lines changed

2 files changed

+63
-39
lines changed

internal_filesystem/lib/mpos/ui/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
screen_stack
55
)
66
from .widget import handle_back_swipe, handle_top_swipe
7-
from .topmenu import open_bar, close_bar, open_drawer, drawer_open
7+
from .topmenu import open_bar, close_bar, open_drawer, drawer_open, NOTIFICATION_BAR_HEIGHT
88
from .focus import save_and_clear_current_focusgroup
99
from .display import (
1010
get_display_width, get_display_height,
@@ -18,7 +18,7 @@
1818
__all__ = [
1919
"setContentView", "back_screen", "empty_screen_stack",
2020
"handle_back_swipe", "handle_top_swipe",
21-
"open_bar", "close_bar", "open_drawer", "drawer_open",
21+
"open_bar", "close_bar", "open_drawer", "drawer_open", "NOTIFICATION_BAR_HEIGHT",
2222
"save_and_clear_current_focusgroup",
2323
"get_display_width", "get_display_height",
2424
"pct_of_display_width", "pct_of_display_height",

internal_filesystem/lib/mpos/ui/widget.py

Lines changed: 61 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,107 +2,131 @@
22
import lvgl as lv
33
from .anim import smooth_show, smooth_hide
44
from .view import back_screen
5-
from .topmenu import open_drawer, drawer_open
5+
from .topmenu import open_drawer, drawer_open, NOTIFICATION_BAR_HEIGHT
66
from .display import get_display_width, get_display_height
77

88
downbutton = None
99
backbutton = None
1010
down_start_x = 0
1111
back_start_y = 0
1212

13+
14+
# Would be better to somehow save other events, like clicks, and pass them down to the layers below if released with x < 60
1315
def _back_swipe_cb(event):
1416
if drawer_open:
17+
print("ignoring back gesture because drawer is open")
1518
return
16-
global back_start_y, backbutton
17-
code = event.get_code()
19+
20+
global backbutton, back_start_y
21+
event_code = event.get_code()
1822
indev = lv.indev_active()
1923
if not indev:
2024
return
2125
point = lv.point_t()
2226
indev.get_point(point)
23-
x, y = point.x, point.y
24-
25-
if code == lv.EVENT.PRESSED:
27+
x = point.x
28+
y = point.y
29+
#print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
30+
if event_code == lv.EVENT.PRESSED:
2631
smooth_show(backbutton)
2732
back_start_y = y
28-
elif code == lv.EVENT.PRESSING:
33+
elif event_code == lv.EVENT.PRESSING:
2934
magnetic_x = round(x / 10)
30-
backbutton.set_pos(magnetic_x, back_start_y)
31-
elif code == lv.EVENT.RELEASED:
35+
backbutton.set_pos(magnetic_x,back_start_y)
36+
elif event_code == lv.EVENT.RELEASED:
3237
smooth_hide(backbutton)
3338
if x > min(100, get_display_width() / 3):
3439
back_screen()
3540

41+
42+
# Would be better to somehow save other events, like clicks, and pass them down to the layers below if released with x < 60
3643
def _top_swipe_cb(event):
3744
if drawer_open:
45+
print("ignoring top swipe gesture because drawer is open")
3846
return
39-
global down_start_x, downbutton
40-
code = event.get_code()
47+
48+
global downbutton, down_start_x
49+
event_code = event.get_code()
4150
indev = lv.indev_active()
4251
if not indev:
4352
return
4453
point = lv.point_t()
4554
indev.get_point(point)
46-
x, y = point.x, point.y
47-
48-
if code == lv.EVENT.PRESSED:
55+
x = point.x
56+
y = point.y
57+
#print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
58+
if event_code == lv.EVENT.PRESSED:
4959
smooth_show(downbutton)
5060
down_start_x = x
51-
elif code == lv.EVENT.PRESSING:
52-
magnetic_y = round(y / 10)
53-
downbutton.set_pos(down_start_x, magnetic_y)
54-
elif code == lv.EVENT.RELEASED:
61+
elif event_code == lv.EVENT.PRESSING:
62+
magnetic_y = round(y/ 10)
63+
downbutton.set_pos(down_start_x,magnetic_y)
64+
elif event_code == lv.EVENT.RELEASED:
5565
smooth_hide(downbutton)
5666
if y > min(80, get_display_height() / 3):
5767
open_drawer()
5868

69+
5970
def handle_back_swipe():
6071
global backbutton
6172
rect = lv.obj(lv.layer_top())
62-
rect.set_size(round(60), lv.layer_top().get_height() - 80)
63-
rect.set_pos(0, 80)
73+
rect.set_size(round(NOTIFICATION_BAR_HEIGHT/2), lv.layer_top().get_height()-NOTIFICATION_BAR_HEIGHT) # narrow because it overlaps buttons
6474
rect.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
65-
75+
rect.set_scroll_dir(lv.DIR.NONE)
76+
rect.set_pos(0, NOTIFICATION_BAR_HEIGHT)
6677
style = lv.style_t()
6778
style.init()
6879
style.set_bg_opa(lv.OPA.TRANSP)
6980
style.set_border_width(0)
81+
style.set_radius(0)
82+
if False: # debug the back swipe zone with a red border
83+
style.set_bg_opa(15)
84+
style.set_border_width(4)
85+
style.set_border_color(lv.color_hex(0xFF0000)) # Red border for visibility
86+
style.set_border_opa(lv.OPA._50) # 50% opacity for the border
7087
rect.add_style(style, 0)
71-
88+
#rect.add_flag(lv.obj.FLAG.CLICKABLE) # Make the object clickable
89+
#rect.add_flag(lv.obj.FLAG.GESTURE_BUBBLE) # Allow dragging
7290
rect.add_event_cb(_back_swipe_cb, lv.EVENT.PRESSED, None)
7391
rect.add_event_cb(_back_swipe_cb, lv.EVENT.PRESSING, None)
7492
rect.add_event_cb(_back_swipe_cb, lv.EVENT.RELEASED, None)
75-
93+
#rect.add_event_cb(back_swipe_cb, lv.EVENT.ALL, None)
94+
# button with label that shows up during the dragging:
7695
backbutton = lv.button(lv.layer_top())
77-
backbutton.set_pos(0, 200)
96+
backbutton.set_pos(0, round(lv.layer_top().get_height() / 2))
7897
backbutton.add_flag(lv.obj.FLAG.HIDDEN)
7998
backbutton.add_state(lv.STATE.DISABLED)
80-
lbl = lv.label(backbutton)
81-
lbl.set_text(lv.SYMBOL.LEFT)
82-
lbl.set_style_text_font(lv.font_montserrat_18, 0)
83-
lbl.center()
99+
backlabel = lv.label(backbutton)
100+
backlabel.set_text(lv.SYMBOL.LEFT)
101+
backlabel.set_style_text_font(lv.font_montserrat_18, 0)
102+
backlabel.center()
84103

85104
def handle_top_swipe():
86105
global downbutton
87106
rect = lv.obj(lv.layer_top())
88-
rect.set_size(lv.pct(100), 60)
107+
rect.set_size(lv.pct(100), round(NOTIFICATION_BAR_HEIGHT*2/3))
89108
rect.set_pos(0, 0)
90109
rect.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
91-
92110
style = lv.style_t()
93111
style.init()
94112
style.set_bg_opa(lv.OPA.TRANSP)
113+
#style.set_bg_opa(15)
114+
style.set_border_width(0)
115+
style.set_radius(0)
116+
#style.set_border_color(lv.color_hex(0xFF0000)) # White border for visibility
117+
#style.set_border_opa(lv.OPA._50) # 50% opacity for the border
95118
rect.add_style(style, 0)
96-
119+
#rect.add_flag(lv.obj.FLAG.CLICKABLE) # Make the object clickable
120+
#rect.add_flag(lv.obj.FLAG.GESTURE_BUBBLE) # Allow dragging
97121
rect.add_event_cb(_top_swipe_cb, lv.EVENT.PRESSED, None)
98122
rect.add_event_cb(_top_swipe_cb, lv.EVENT.PRESSING, None)
99123
rect.add_event_cb(_top_swipe_cb, lv.EVENT.RELEASED, None)
100-
124+
# button with label that shows up during the dragging:
101125
downbutton = lv.button(lv.layer_top())
102-
downbutton.set_pos(100, 0)
126+
downbutton.set_pos(0, round(lv.layer_top().get_height() / 2))
103127
downbutton.add_flag(lv.obj.FLAG.HIDDEN)
104128
downbutton.add_state(lv.STATE.DISABLED)
105-
lbl = lv.label(downbutton)
106-
lbl.set_text(lv.SYMBOL.DOWN)
107-
lbl.set_style_text_font(lv.font_montserrat_18, 0)
108-
lbl.center()
129+
downlabel = lv.label(downbutton)
130+
downlabel.set_text(lv.SYMBOL.DOWN)
131+
downlabel.set_style_text_font(lv.font_montserrat_18, 0)
132+
downlabel.center()

0 commit comments

Comments
 (0)