Skip to content

Commit 6e04f87

Browse files
Visual cues for back swipe
1 parent a730a0e commit 6e04f87

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

internal_filesystem/lib/mpos/ui/__init__.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@
3333
hide_bar_animation_start_value = show_bar_animation_end_value
3434
hide_bar_animation_end_value = show_bar_animation_start_value
3535

36+
back_start_y = 0
37+
38+
# Widgets:
3639
notification_bar = None
40+
backbutton = None
3741

3842
foreground_app_name=None
3943

@@ -579,52 +583,60 @@ def back_swipe_cb(event):
579583
print("ignoring back gesture because drawer is open")
580584
return
581585

586+
global backbutton, back_start_y
582587
event_code = event.get_code()
583-
#name = mpos.ui.get_event_name(event_code)
584-
#print(f"back_swipe_cb {event_code} and {name}")
585-
586-
#xa = rect.get_x_aligned()
587-
#ya = rect.get_y_aligned()
588-
#print(f"xa, ya: {xa},{ya}")
589-
590-
#obj = e.get_target()
591-
#lvobj = lv.obj(obj)
592-
#pos = lvobj.get_pos() # Get current position
593-
#print(f"pos: {lvobj.get_x()}, {lvobj.get_y()}")
594-
588+
name = mpos.ui.get_event_name(event_code)
595589
indev = lv.indev_active()
596590
if indev:
597591
point = lv.point_t()
598592
indev.get_point(point)
599593
x = point.x
600594
y = point.y
601-
print(f"pos: {x}, {y}")
602-
#rect.set_pos(x, 0)
603-
if event_code == lv.EVENT.RELEASED and x > 60: # TODO: use display_width / 3 here
604-
mpos.ui.back_screen()
605-
#rect.set_pos(0,0)
606-
#rect.set_pos(xa + point.x, ya + point.y)
607-
#rect.set_pos(point.x, point.y)
608-
595+
#print(f"visual_back_swipe_cb event_code={event_code} and event_name={name} and pos: {x}, {y}")
596+
if event_code == lv.EVENT.PRESSED:
597+
mpos.ui.anim.smooth_show(backbutton)
598+
back_start_y = y
599+
elif event_code == lv.EVENT.PRESSING:
600+
magnetic_x = round(x / 10)
601+
backbutton.set_pos(magnetic_x,back_start_y)
602+
elif event_code == lv.EVENT.RELEASED:
603+
mpos.ui.anim.smooth_hide(backbutton)
604+
if x > min(100,horizontal_resolution / 3):
605+
mpos.ui.back_screen()
609606

610607
def handle_back_swipe():
608+
global backbutton
611609
rect = lv.obj(lv.layer_top())
612610
rect.set_size(round(NOTIFICATION_BAR_HEIGHT/2), lv.layer_top().get_height()-NOTIFICATION_BAR_HEIGHT) # narrow because it overlaps buttons
613611
rect.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
612+
rect.set_scroll_dir(lv.DIR.NONE)
614613
rect.set_pos(0, NOTIFICATION_BAR_HEIGHT)
615614
style = lv.style_t()
616615
style.init()
617616
style.set_bg_opa(lv.OPA.TRANSP)
618-
#style.set_bg_opa(15)
619617
style.set_border_width(0)
620618
style.set_radius(0)
621-
#style.set_border_color(lv.color_hex(0xFF0000)) # White border for visibility
622-
#style.set_border_opa(lv.OPA._50) # 50% opacity for the border
619+
if False: # debug the back swipe zone with a red border
620+
style.set_bg_opa(15)
621+
style.set_border_width(4)
622+
style.set_border_color(lv.color_hex(0xFF0000)) # Red border for visibility
623+
style.set_border_opa(lv.OPA._50) # 50% opacity for the border
623624
rect.add_style(style, 0)
624625
#rect.add_flag(lv.obj.FLAG.CLICKABLE) # Make the object clickable
625626
#rect.add_flag(lv.obj.FLAG.GESTURE_BUBBLE) # Allow dragging
626-
#rect.add_event_cb(drag_event_cb, lv.EVENT.PRESSING, None)
627+
rect.add_event_cb(back_swipe_cb, lv.EVENT.PRESSED, None)
628+
rect.add_event_cb(back_swipe_cb, lv.EVENT.PRESSING, None)
627629
rect.add_event_cb(back_swipe_cb, lv.EVENT.RELEASED, None)
630+
#rect.add_event_cb(back_swipe_cb, lv.EVENT.ALL, None)
631+
# button with label that shows up during the dragging:
632+
backbutton = lv.button(lv.layer_top())
633+
backbutton.set_pos(0, round(lv.layer_top().get_height() / 2))
634+
backbutton.add_flag(lv.obj.FLAG.HIDDEN)
635+
backbutton.add_state(lv.STATE.DISABLED)
636+
backlabel = lv.label(backbutton)
637+
backlabel.set_text(lv.SYMBOL.LEFT)
638+
backlabel.set_style_text_font(lv.font_montserrat_18, 0)
639+
backlabel.center()
628640

629641
# Would be better to somehow save other events, like clicks, and pass them down to the layers below if released with x < 60
630642
def top_swipe_cb(event):

0 commit comments

Comments
 (0)