|
33 | 33 | hide_bar_animation_start_value = show_bar_animation_end_value |
34 | 34 | hide_bar_animation_end_value = show_bar_animation_start_value |
35 | 35 |
|
| 36 | +back_start_y = 0 |
| 37 | + |
| 38 | +# Widgets: |
36 | 39 | notification_bar = None |
| 40 | +backbutton = None |
37 | 41 |
|
38 | 42 | foreground_app_name=None |
39 | 43 |
|
@@ -579,52 +583,60 @@ def back_swipe_cb(event): |
579 | 583 | print("ignoring back gesture because drawer is open") |
580 | 584 | return |
581 | 585 |
|
| 586 | + global backbutton, back_start_y |
582 | 587 | 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) |
595 | 589 | indev = lv.indev_active() |
596 | 590 | if indev: |
597 | 591 | point = lv.point_t() |
598 | 592 | indev.get_point(point) |
599 | 593 | x = point.x |
600 | 594 | 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() |
609 | 606 |
|
610 | 607 | def handle_back_swipe(): |
| 608 | + global backbutton |
611 | 609 | rect = lv.obj(lv.layer_top()) |
612 | 610 | rect.set_size(round(NOTIFICATION_BAR_HEIGHT/2), lv.layer_top().get_height()-NOTIFICATION_BAR_HEIGHT) # narrow because it overlaps buttons |
613 | 611 | rect.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) |
| 612 | + rect.set_scroll_dir(lv.DIR.NONE) |
614 | 613 | rect.set_pos(0, NOTIFICATION_BAR_HEIGHT) |
615 | 614 | style = lv.style_t() |
616 | 615 | style.init() |
617 | 616 | style.set_bg_opa(lv.OPA.TRANSP) |
618 | | - #style.set_bg_opa(15) |
619 | 617 | style.set_border_width(0) |
620 | 618 | 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 |
623 | 624 | rect.add_style(style, 0) |
624 | 625 | #rect.add_flag(lv.obj.FLAG.CLICKABLE) # Make the object clickable |
625 | 626 | #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) |
627 | 629 | 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() |
628 | 640 |
|
629 | 641 | # Would be better to somehow save other events, like clicks, and pass them down to the layers below if released with x < 60 |
630 | 642 | def top_swipe_cb(event): |
|
0 commit comments