Skip to content

Commit 7a5288b

Browse files
Add down swipe cues
1 parent 6e04f87 commit 7a5288b

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

internal_filesystem/lib/mpos/ui/__init__.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
hide_bar_animation_start_value = show_bar_animation_end_value
3434
hide_bar_animation_end_value = show_bar_animation_start_value
3535

36+
down_start_x = 0
3637
back_start_y = 0
3738

3839
# Widgets:
3940
notification_bar = None
41+
downbutton = None
4042
backbutton = None
4143

4244
foreground_app_name=None
@@ -585,7 +587,7 @@ def back_swipe_cb(event):
585587

586588
global backbutton, back_start_y
587589
event_code = event.get_code()
588-
name = mpos.ui.get_event_name(event_code)
590+
#name = mpos.ui.get_event_name(event_code)
589591
indev = lv.indev_active()
590592
if indev:
591593
point = lv.point_t()
@@ -640,37 +642,34 @@ def handle_back_swipe():
640642

641643
# Would be better to somehow save other events, like clicks, and pass them down to the layers below if released with x < 60
642644
def top_swipe_cb(event):
643-
#global rect
645+
if drawer_open:
646+
print("ignoring top swipe gesture because drawer is open")
647+
return
644648

649+
global downbutton, down_start_x
645650
event_code = event.get_code()
646651
name = mpos.ui.get_event_name(event_code)
647-
print(f"top_swipe_cb {event_code} and {name}")
648-
649-
#xa = rect.get_x_aligned()
650-
#ya = rect.get_y_aligned()
651-
#print(f"xa, ya: {xa},{ya}")
652-
653-
#obj = e.get_target()
654-
#lvobj = lv.obj(obj)
655-
#pos = lvobj.get_pos() # Get current position
656-
#print(f"pos: {lvobj.get_x()}, {lvobj.get_y()}")
657-
658652
indev = lv.indev_active()
659653
if indev:
660654
point = lv.point_t()
661655
indev.get_point(point)
662656
x = point.x
663657
y = point.y
664-
print(f"pos: {x}, {y}")
665-
#rect.set_pos(x, 0)
666-
if event_code == lv.EVENT.RELEASED and y > 60: # TODO: use display_height / 3 here, or better: an animation for more feedback
667-
mpos.ui.open_drawer()
668-
#rect.set_pos(0,0)
669-
#rect.set_pos(xa + point.x, ya + point.y)
670-
#rect.set_pos(point.x, point.y)
658+
print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
659+
if event_code == lv.EVENT.PRESSED:
660+
mpos.ui.anim.smooth_show(downbutton)
661+
down_start_x = x
662+
elif event_code == lv.EVENT.PRESSING:
663+
magnetic_y = round(y/ 10)
664+
downbutton.set_pos(down_start_x,magnetic_y)
665+
elif event_code == lv.EVENT.RELEASED:
666+
mpos.ui.anim.smooth_hide(downbutton)
667+
if y > min(80,vertical_resolution / 3):
668+
mpos.ui.open_drawer()
671669

672670

673671
def handle_top_swipe():
672+
global downbutton
674673
rect = lv.obj(lv.layer_top())
675674
rect.set_size(lv.pct(100), round(NOTIFICATION_BAR_HEIGHT*2/3))
676675
rect.set_pos(0, 0)
@@ -686,8 +685,18 @@ def handle_top_swipe():
686685
rect.add_style(style, 0)
687686
#rect.add_flag(lv.obj.FLAG.CLICKABLE) # Make the object clickable
688687
#rect.add_flag(lv.obj.FLAG.GESTURE_BUBBLE) # Allow dragging
689-
#rect.add_event_cb(drag_event_cb, lv.EVENT.PRESSING, None)
688+
rect.add_event_cb(top_swipe_cb, lv.EVENT.PRESSED, None)
689+
rect.add_event_cb(top_swipe_cb, lv.EVENT.PRESSING, None)
690690
rect.add_event_cb(top_swipe_cb, lv.EVENT.RELEASED, None)
691+
# button with label that shows up during the dragging:
692+
downbutton = lv.button(lv.layer_top())
693+
downbutton.set_pos(0, round(lv.layer_top().get_height() / 2))
694+
downbutton.add_flag(lv.obj.FLAG.HIDDEN)
695+
downbutton.add_state(lv.STATE.DISABLED)
696+
downlabel = lv.label(downbutton)
697+
downlabel.set_text(lv.SYMBOL.DOWN)
698+
downlabel.set_style_text_font(lv.font_montserrat_18, 0)
699+
downlabel.center()
691700

692701

693702
def pct_of_display_width(percent):

0 commit comments

Comments
 (0)