|
| 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) |
0 commit comments