Skip to content

Commit a038e9d

Browse files
Tinyu-Zhaolbuque
authored andcommitted
lib/m5ui: Add LVGL List widget and docs.
Signed-off-by: tinyu <tinyu@m5stack.com>
1 parent 4f10ac4 commit a038e9d

File tree

8 files changed

+454
-0
lines changed

8 files changed

+454
-0
lines changed

docs/en/m5ui/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Classes
3434

3535
page.rst
3636
arc.rst
37+
list.rst
3738
bar.rst
3839
button.rst
3940
calendar.rst

docs/en/m5ui/list.rst

Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
.. currentmodule:: m5ui
2+
3+
M5List
4+
=======
5+
6+
.. include:: ../refs/m5ui.list.ref
7+
8+
M5List is a widget that can be used to create lists in user interfaces. It is basically a rectangle with vertical layout to which Buttons and Text can be added.
9+
10+
11+
UiFlow2 Example
12+
---------------
13+
14+
list example
15+
^^^^^^^^^^^^
16+
17+
Open the |cores3_list_example.m5f2| project in UiFlow2.
18+
19+
This example demonstrates how to create a list that displays a series of items.
20+
21+
UiFlow2 Code Block:
22+
23+
|cores3_list_example.png|
24+
25+
Example output:
26+
27+
None
28+
29+
30+
MicroPython Example
31+
-------------------
32+
33+
list example
34+
^^^^^^^^^^^^
35+
36+
This example demonstrates how to create a list that displays a series of items.
37+
38+
MicroPython Code Block:
39+
40+
.. literalinclude:: ../../../examples/m5ui/list/cores3_list_example.py
41+
:language: python
42+
:linenos:
43+
44+
Example output:
45+
46+
None
47+
48+
49+
**API**
50+
-------
51+
52+
M5List
53+
^^^^^^^
54+
55+
.. autoclass:: m5ui.list.M5List
56+
:members:
57+
58+
.. py:method:: add_text(text:str)
59+
60+
Add text to the list end.
61+
62+
:param str text: The text to add.
63+
64+
UiFlow2 Code Block:
65+
66+
|add_text.png|
67+
68+
MicroPython Code Block:
69+
70+
.. code-block:: python
71+
72+
text_0 = list_0.add_text("Item 1")
73+
74+
.. py:method:: add_button(icon, text)
75+
76+
Add a button to the list end.
77+
78+
:param int icon: The icon to display on the button, `refer icon list <https://docs.lvgl.io/9.3/details/main-modules/font.html#special-fonts>`_ .
79+
:param str text: The text to display on the button.
80+
81+
UiFlow2 Code Block:
82+
83+
|add_button.png|
84+
85+
MicroPython Code Block:
86+
87+
.. code-block:: python
88+
89+
button_0 = list_0.add_button(lv.SYMBOL.BULLET, "Button0")
90+
91+
.. py:method:: move_background()
92+
93+
Move the background of the list to the end.
94+
95+
UiFlow2 Code Block:
96+
97+
|move_background.png|
98+
99+
MicroPython Code Block:
100+
101+
.. code-block:: python
102+
103+
button_0.move_background()
104+
text_0.move_background()
105+
106+
107+
.. py:method:: move_foreground()
108+
109+
Move the foreground of the list to the end.
110+
111+
UiFlow2 Code Block:
112+
113+
|move_foreground.png|
114+
115+
MicroPython Code Block:
116+
117+
.. code-block:: python
118+
119+
button_0.move_foreground()
120+
text_0.move_foreground()
121+
122+
.. py:method:: move_to_index(index)
123+
124+
Move the item at the specified index to the end of the list.
125+
126+
UiFlow2 Code Block:
127+
128+
|move_to_index.png|
129+
130+
MicroPython Code Block:
131+
132+
.. code-block:: python
133+
134+
button_0.move_to_index(0)
135+
text_0.move_to_index(1)
136+
137+
.. py:method:: delete()
138+
139+
Delete the item from the list.
140+
141+
UiFlow2 Code Block:
142+
143+
|delete.png|
144+
145+
MicroPython Code Block:
146+
147+
.. code-block:: python
148+
149+
button_0.delete()
150+
text_0.delete()
151+
list_0.delete()
152+
153+
.. py:method:: add_event_cb(handler, event, user_data)
154+
155+
Add an event callback to the button. The callback will be called when the specified event occurs.
156+
157+
:param function handler: The callback function to call.
158+
:param int event: The event to listen for.
159+
:param Any user_data: Optional user data to pass to the callback.
160+
:return: None
161+
162+
UiFlow2 Code Block:
163+
164+
|event.png|
165+
166+
MicroPython Code Block:
167+
168+
.. code-block:: python
169+
170+
def button0_event_handler(event_struct):
171+
code = event_struct.code
172+
obj = event_struct.get_target_obj()
173+
if code == lv.EVENT.CLICKED:
174+
print("Clicked: list1" + list_0.get_button_text(obj))
175+
176+
177+
def button1_event_handler(event_struct):
178+
code = event_struct.code
179+
obj = event_struct.get_target_obj()
180+
if code == lv.EVENT.CLICKED:
181+
print("Clicked: list1" + list_0.get_button_text(obj))
182+
183+
184+
button_0.add_event_cb(button0_event_handler, lv.EVENT.CLICKED, None)
185+
button_1.add_event_cb(button1_event_handler, lv.EVENT.CLICKED, None)
186+
187+
.. py:method:: set_flag(flag, value)
188+
189+
Set a flag on the object. If ``value`` is True, the flag is added; if False, the flag is removed.
190+
191+
:param int flag: The flag to set.
192+
:param bool value: If True, the flag is added; if False, the flag is removed.
193+
:return: None
194+
195+
UiFlow2 Code Block:
196+
197+
|set_flag.png|
198+
199+
MicroPython Code Block:
200+
201+
.. code-block:: python
202+
203+
label_0.set_flag(lv.obj.FLAG.HIDDEN, True)
204+
205+
.. py:method:: set_pos(x, y)
206+
207+
Set the position of the label.
208+
209+
:param int x: The x-coordinate of the label.
210+
:param int y: The y-coordinate of the label.
211+
:return: None
212+
213+
UiFlow2 Code Block:
214+
215+
|set_pos.png|
216+
217+
MicroPython Code Block:
218+
219+
.. code-block:: python
220+
221+
label_0.set_pos(100, 100)
222+
223+
224+
.. py:method:: set_x(x)
225+
226+
Set the x-coordinate of the label.
227+
228+
:param int x: The x-coordinate of the label.
229+
:return: None
230+
231+
UiFlow2 Code Block:
232+
233+
|set_x.png|
234+
235+
MicroPython Code Block:
236+
237+
.. code-block:: python
238+
239+
label_0.set_x(100)
240+
241+
242+
.. py:method:: set_y(y)
243+
244+
Set the y-coordinate of the label.
245+
246+
:param int y: The y-coordinate of the label.
247+
:return: None
248+
249+
UiFlow2 Code Block:
250+
251+
|set_y.png|
252+
253+
MicroPython Code Block:
254+
255+
.. code-block:: python
256+
257+
label_0.set_y(100)
258+
259+
260+
.. py:method:: set_size(width, height)
261+
262+
Set the size of the label.
263+
264+
:param int width: The width of the label.
265+
:param int height: The height of the label.
266+
:return: None
267+
268+
UiFlow2 Code Block:
269+
270+
|set_size.png|
271+
272+
MicroPython Code Block:
273+
274+
.. code-block:: python
275+
276+
label_0.set_size(100, 50)
277+
278+
279+
.. py:method:: set_width(width)
280+
281+
Set the width of the label.
282+
283+
:param int width: The width of the label.
284+
:return: None
285+
286+
UiFlow2 Code Block:
287+
288+
|set_width.png|
289+
290+
MicroPython Code Block:
291+
292+
.. code-block:: python
293+
294+
label_0.set_width(100)
295+
296+
297+
.. py:method:: align_to(obj, align, x, y)
298+
299+
Align the label to another object.
300+
301+
:param lv.obj obj: The object to align to.
302+
:param int align: The alignment type.
303+
:param int x: The x-offset from the aligned object.
304+
:param int y: The y-offset from the aligned object.
305+
:return: None
306+
307+
UiFlow2 Code Block:
308+
309+
|align_to.png|
310+
311+
MicroPython Code Block:
312+
313+
.. code-block:: python
314+
315+
label_0.align_to(page_0, lv.ALIGN.CENTER, 0, 0)

docs/en/refs/m5ui.list.ref

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
.. |align_to.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/align_to.png
3+
.. |event.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/event.png
4+
.. |set_flag.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/set_flag.png
5+
.. |set_pos.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/set_pos.png
6+
.. |set_size.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/set_size.png
7+
.. |set_width.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/set_width.png
8+
.. |set_x.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/set_x.png
9+
.. |set_y.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/set_y.png
10+
.. |add_text.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/add_text.png
11+
.. |add_button.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/add_button.png
12+
.. |move_foreground.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/move_foreground.png
13+
.. |move_to_index.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/move_to_index.png
14+
.. |move_background.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/move_background.png
15+
.. |delete.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/delete.png
16+
17+
.. |cores3_list_example.png| image:: https://static-cdn.m5stack.com/mpy_docs/m5ui/label/cores3_list_example.png
18+
19+
.. |cores3_list_example.m5f2| raw:: html
20+
21+
<a
22+
href="https://uiflow2.m5stack.com/?example=https://raw.githubusercontent.com/m5stack/uiflow-micropython/develop/examples/m5ui/label/cores3_list_example.m5f2"
23+
target="_blank"
24+
>
25+
cores3_list_example.m5f2
26+
</a>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":"V2.0","versionNumber":"V2.3.0","type":"cores3","components":[{"name":"page0","type":"lvgl_page","layer":0,"screenId":"builtin","screenName":"","id":"zGUSgLk%P9BF_bji","createTime":1750906906496,"backgroundColor":"#ffffff","isLVGL":true,"isSelected":true},{"name":"label0","type":"lvgl_label","layer":1,"screenId":"builtin","screenName":"","id":"ktg+xZQJ^lvI#N=M","createTime":1750907034945,"x":60,"y":110,"color":"#000000","backgroundColor":"#ffffff","bg_opacity":0,"text":"It is a circularly scrolling text. ","font":"lv.font_montserrat_14","pageId":"zGUSgLk%P9BF_bji","isLVGL":true,"isSelected":false,"width":207,"height":15}],"resources":[{"hardware":["hardware_button","hardware_pin_button","imu","speaker","touch","als","mic","sdcard"]}],"units":[],"hats":[],"bases":[],"i2cs":[],"blockly":"<block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"50\" y=\"51\"><mutation isBegin=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_begin\" id=\"h^WDhC_Sfxe`T#-Bq?0C\"><next><block type=\"lvgl_page_screen_load\" id=\"XnobnY])ej65P;.Sw-Zo\"><field name=\"NAME\">page0</field><next><block type=\"lvgl_label_set_long_mode\" id=\"W4skIJcVcH:I{r%*wUd/\"><field name=\"NAME\">label0</field><field name=\"OPTION\">SCROLL_CIRCULAR</field><next><block type=\"lvgl_label_set_width\" id=\"LI2ACFi|nBvkqyww3Xb*\"><field name=\"NAME\">label0</field><value name=\"VALUE\"><shadow type=\"math_number\" id=\"3w=1@49joOEy4p#Igu=]\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">150</field></shadow></value><next><block type=\"lvgl_label_set_align\" id=\"NKEo#E23Z2]C|k/^co9Q\"><mutation pageId=\"zGUSgLk%P9BF_bji\"></mutation><field name=\"NAME\">label0</field><field name=\"OPTION\">CENTER</field><field name=\"OBJ\">page0</field><value name=\"X\"><shadow type=\"math_number\" id=\"q89ty$rbQGY+}tXJx4*3\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">0</field></shadow></value><value name=\"Y\"><shadow type=\"math_number\" id=\"^[cE7xCHwH$rkQi.}cO}\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">0</field></shadow></value></block></next></block></next></block></next></block></next></block></statement></block><block type=\"basic_on_loop\" id=\"loop_block\" deletable=\"false\" x=\"450\" y=\"50\"><mutation isUpdate=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_update\" id=\"8eQ!L~hf?1qJ4;Y2L-J$\"></block></statement></block>","screen":[{"simulationName":"Built-in","type":"builtin","width":320,"height":240,"scale":0.77,"screenName":"","blockId":"","screenColorType":0,"rotation":1,"id":"builtin","createTime":1750906899526}],"logicWhenNum":0,"customList":[]}

0 commit comments

Comments
 (0)