|
2 | 2 | import lvgl as lv |
3 | 3 | from .anim import smooth_show, smooth_hide |
4 | 4 | from .view import back_screen |
5 | | -from .topmenu import open_drawer, drawer_open |
| 5 | +from .topmenu import open_drawer, drawer_open, NOTIFICATION_BAR_HEIGHT |
6 | 6 | from .display import get_display_width, get_display_height |
7 | 7 |
|
8 | 8 | downbutton = None |
9 | 9 | backbutton = None |
10 | 10 | down_start_x = 0 |
11 | 11 | back_start_y = 0 |
12 | 12 |
|
| 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 |
13 | 15 | def _back_swipe_cb(event): |
14 | 16 | if drawer_open: |
| 17 | + print("ignoring back gesture because drawer is open") |
15 | 18 | 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() |
18 | 22 | indev = lv.indev_active() |
19 | 23 | if not indev: |
20 | 24 | return |
21 | 25 | point = lv.point_t() |
22 | 26 | 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: |
26 | 31 | smooth_show(backbutton) |
27 | 32 | back_start_y = y |
28 | | - elif code == lv.EVENT.PRESSING: |
| 33 | + elif event_code == lv.EVENT.PRESSING: |
29 | 34 | 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: |
32 | 37 | smooth_hide(backbutton) |
33 | 38 | if x > min(100, get_display_width() / 3): |
34 | 39 | back_screen() |
35 | 40 |
|
| 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 |
36 | 43 | def _top_swipe_cb(event): |
37 | 44 | if drawer_open: |
| 45 | + print("ignoring top swipe gesture because drawer is open") |
38 | 46 | 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() |
41 | 50 | indev = lv.indev_active() |
42 | 51 | if not indev: |
43 | 52 | return |
44 | 53 | point = lv.point_t() |
45 | 54 | 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: |
49 | 59 | smooth_show(downbutton) |
50 | 60 | 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: |
55 | 65 | smooth_hide(downbutton) |
56 | 66 | if y > min(80, get_display_height() / 3): |
57 | 67 | open_drawer() |
58 | 68 |
|
| 69 | + |
59 | 70 | def handle_back_swipe(): |
60 | 71 | global backbutton |
61 | 72 | 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 |
64 | 74 | 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) |
66 | 77 | style = lv.style_t() |
67 | 78 | style.init() |
68 | 79 | style.set_bg_opa(lv.OPA.TRANSP) |
69 | 80 | 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 |
70 | 87 | 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 |
72 | 90 | rect.add_event_cb(_back_swipe_cb, lv.EVENT.PRESSED, None) |
73 | 91 | rect.add_event_cb(_back_swipe_cb, lv.EVENT.PRESSING, None) |
74 | 92 | 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: |
76 | 95 | backbutton = lv.button(lv.layer_top()) |
77 | | - backbutton.set_pos(0, 200) |
| 96 | + backbutton.set_pos(0, round(lv.layer_top().get_height() / 2)) |
78 | 97 | backbutton.add_flag(lv.obj.FLAG.HIDDEN) |
79 | 98 | 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() |
84 | 103 |
|
85 | 104 | def handle_top_swipe(): |
86 | 105 | global downbutton |
87 | 106 | 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)) |
89 | 108 | rect.set_pos(0, 0) |
90 | 109 | rect.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF) |
91 | | - |
92 | 110 | style = lv.style_t() |
93 | 111 | style.init() |
94 | 112 | 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 |
95 | 118 | 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 |
97 | 121 | rect.add_event_cb(_top_swipe_cb, lv.EVENT.PRESSED, None) |
98 | 122 | rect.add_event_cb(_top_swipe_cb, lv.EVENT.PRESSING, None) |
99 | 123 | rect.add_event_cb(_top_swipe_cb, lv.EVENT.RELEASED, None) |
100 | | - |
| 124 | + # button with label that shows up during the dragging: |
101 | 125 | downbutton = lv.button(lv.layer_top()) |
102 | | - downbutton.set_pos(100, 0) |
| 126 | + downbutton.set_pos(0, round(lv.layer_top().get_height() / 2)) |
103 | 127 | downbutton.add_flag(lv.obj.FLAG.HIDDEN) |
104 | 128 | 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