|
| 1 | +.. currentmodule:: m5ui |
| 2 | + |
| 3 | +M5Scale |
| 4 | +======== |
| 5 | + |
| 6 | +.. include:: ../refs/m5ui.scale.ref |
| 7 | + |
| 8 | +M5Scale is a widget that can be used to create scales in the user interface. Scale Widgets show linear or circular scales with configurable ranges, tick counts, placement, labeling, and subsections (Sections) with custom styling. |
| 9 | + |
| 10 | + |
| 11 | +UiFlow2 Example |
| 12 | +--------------- |
| 13 | + |
| 14 | +scale example |
| 15 | +^^^^^^^^^^^^^^ |
| 16 | + |
| 17 | +Open the |cores3_scroll_example.m5f2| project in UiFlow2. |
| 18 | + |
| 19 | +This example demonstrates how to create a scale widget with a range of values and custom styling. |
| 20 | + |
| 21 | +UiFlow2 Code Block: |
| 22 | + |
| 23 | + |cores3_scroll_example.png| |
| 24 | + |
| 25 | +Example output: |
| 26 | + |
| 27 | + None |
| 28 | + |
| 29 | + |
| 30 | +MicroPython Example |
| 31 | +------------------- |
| 32 | + |
| 33 | +scroll example |
| 34 | +^^^^^^^^^^^^^^^ |
| 35 | + |
| 36 | +This example demonstrates how to create a scale widget with a range of values and custom styling. |
| 37 | + |
| 38 | +MicroPython Code Block: |
| 39 | + |
| 40 | + .. literalinclude:: ../../../examples/m5ui/scale/cores3_scroll_example.py |
| 41 | + :language: python |
| 42 | + :linenos: |
| 43 | + |
| 44 | +Example output: |
| 45 | + |
| 46 | + None |
| 47 | + |
| 48 | + |
| 49 | +**API** |
| 50 | +------- |
| 51 | + |
| 52 | +M5Scale |
| 53 | +^^^^^^^^ |
| 54 | + |
| 55 | +.. autoclass:: m5ui.scale.M5Scale |
| 56 | + :members: |
| 57 | + |
| 58 | + .. py:method:: set_flag(flag, value) |
| 59 | +
|
| 60 | + Set a flag on the object. If ``value`` is True, the flag is added; if False, the flag is removed. |
| 61 | + |
| 62 | + :param int flag: The flag to set. |
| 63 | + :param bool value: If True, the flag is added; if False, the flag is removed. |
| 64 | + |
| 65 | + UiFlow2 Code Block: |
| 66 | + |
| 67 | + |set_flag.png| |
| 68 | + |
| 69 | + MicroPython Code Block: |
| 70 | + |
| 71 | + .. code-block:: python |
| 72 | +
|
| 73 | + scale_0.set_flag(lv.obj.FLAG.HIDDEN, True) |
| 74 | +
|
| 75 | + .. py:method:: set_range(start_pos, end_pos) |
| 76 | +
|
| 77 | + Set the range of the scale. |
| 78 | + |
| 79 | + :param int start_pos: The start position of the scale. |
| 80 | + :param int end_pos: The end position of the scale. |
| 81 | + |
| 82 | + UiFlow2 Code Block: |
| 83 | + |
| 84 | + |set_range.png| |
| 85 | + |
| 86 | + MicroPython Code Block: |
| 87 | + |
| 88 | + .. code-block:: python |
| 89 | +
|
| 90 | + scale_0.set_range(0, 100) |
| 91 | +
|
| 92 | + .. py:method:: set_major_tick_every(tick_every) |
| 93 | +
|
| 94 | + Set the interval for major ticks on the scale. |
| 95 | + |
| 96 | + :param int tick_every: The interval for major ticks. |
| 97 | + |
| 98 | + UiFlow2 Code Block: |
| 99 | + |
| 100 | + |set_major_tick_every.png| |
| 101 | + |
| 102 | + MicroPython Code Block: |
| 103 | + |
| 104 | + .. code-block:: python |
| 105 | +
|
| 106 | + scale_0.set_major_tick_every(10) |
| 107 | +
|
| 108 | + .. py:method:: set_total_tick_count(tick_count) |
| 109 | +
|
| 110 | + Set the total tick count of the scale. |
| 111 | + |
| 112 | + :param int tick_count: The total tick count. |
| 113 | + |
| 114 | + UiFlow2 Code Block: |
| 115 | + |
| 116 | + |set_total_tick_count.png| |
| 117 | + |
| 118 | + MicroPython Code Block: |
| 119 | + |
| 120 | + .. code-block:: python |
| 121 | +
|
| 122 | + scale_0.set_total_tick_count(11) |
| 123 | +
|
| 124 | + .. py:method:: set_label_show(label_show) |
| 125 | +
|
| 126 | + Set the visibility of the scale labels. |
| 127 | + |
| 128 | + :param bool label_show: If True, the labels are shown; if False, they are hidden. |
| 129 | + |
| 130 | + UiFlow2 Code Block: |
| 131 | + |
| 132 | + |set_label_show.png| |
| 133 | + |
| 134 | + MicroPython Code Block: |
| 135 | + |
| 136 | + .. code-block:: python |
| 137 | +
|
| 138 | + scale_0.set_label_show(True) |
| 139 | +
|
| 140 | +
|
| 141 | + .. py:method:: set_mode(show_mode) |
| 142 | +
|
| 143 | + Set the display mode of the scale. |
| 144 | + |
| 145 | + :param int show_mode: The display mode. |
| 146 | + |
| 147 | + Optional: |
| 148 | + |
| 149 | + - `lv.SCALE.MODE.HORIZONTAL_TOP`: Horizontal top scale. |
| 150 | + - `lv.SCALE.MODE.HORIZONTAL_BOTTOM`: Horizontal bottom scale. |
| 151 | + - `lv.SCALE.MODE.VERTICAL_LEFT`: Vertical left scale. |
| 152 | + - `lv.SCALE.MODE.VERTICAL_RIGHT`: Vertical right scale. |
| 153 | + - `lv.SCALE.MODE.ROUND_INNER`: Round inner scale. |
| 154 | + - `lv.SCALE.MODE.ROUND_OUTER`: Round outer scale. |
| 155 | + |
| 156 | + UiFlow2 Code Block: |
| 157 | + |
| 158 | + |set_mode.png| |
| 159 | + |
| 160 | + MicroPython Code Block: |
| 161 | + |
| 162 | + .. code-block:: python |
| 163 | +
|
| 164 | + scale_0.set_mode(lv.SCALE.MODE.HORIZONTAL_TOP) |
| 165 | +
|
| 166 | + .. py:method:: set_text_src(text_src) |
| 167 | +
|
| 168 | + Set the source of the scale label text. |
| 169 | + |
| 170 | + :param list text_src: The source of the scale label text. |
| 171 | + |
| 172 | + UiFlow2 Code Block: |
| 173 | + |
| 174 | + |set_text_src.png| |
| 175 | + |
| 176 | + MicroPython Code Block: |
| 177 | + |
| 178 | + .. code-block:: python |
| 179 | +
|
| 180 | + scale_0.set_text_src(["0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100", None]) |
| 181 | +
|
| 182 | + .. py:method:: set_line_color(color, opa, part) |
| 183 | +
|
| 184 | + Set the color of the line. |
| 185 | + |
| 186 | + :param int color: The color to set. |
| 187 | + :param int opa: The opacity of the color. |
| 188 | + :param int part: The part of the object to apply the style to (e.g., lv.PART.MAIN). |
| 189 | + |
| 190 | + UiFlow2 Code Block: |
| 191 | + |
| 192 | + |set_line_color.png| |
| 193 | + |
| 194 | + MicroPython Code Block: |
| 195 | + |
| 196 | + .. code-block:: python |
| 197 | +
|
| 198 | + scale_0.set_line_color(0xFF0000, 255, lv.PART.MAIN) |
| 199 | + scale_0.set_line_color(0x00FF00, 255, lv.PART.ITEMS) |
| 200 | + scale_0.set_line_color(0x0000FF, 255, lv.PART.INDICATOR) |
| 201 | +
|
| 202 | + .. py:method:: set_style_line_width(width, part) |
| 203 | +
|
| 204 | + Set the line width of the scale. |
| 205 | + |
| 206 | + :param int width: The line width to set. |
| 207 | + :param int part: The part of the object to apply the style to (e.g., lv.PART.MAIN). |
| 208 | + |
| 209 | + UiFlow2 Code Block: |
| 210 | + |
| 211 | + |set_style_line_width.png| |
| 212 | + |
| 213 | + MicroPython Code Block: |
| 214 | + |
| 215 | + .. code-block:: python |
| 216 | +
|
| 217 | + scale_0.set_style_line_width(2, lv.PART.MAIN) |
| 218 | + scale_0.set_style_line_width(2, lv.PART.ITEMS) |
| 219 | + scale_0.set_style_line_width(2, lv.PART.INDICATOR) |
| 220 | +
|
| 221 | + .. py:method:: set_text_color(color, opa, part) |
| 222 | +
|
| 223 | + Set the color of the text. |
| 224 | + |
| 225 | + :param int color: The color to set. |
| 226 | + :param int opa: The opacity of the color. |
| 227 | + :param int part: The part of the object to apply the style to lv.PART.INDICATOR. |
| 228 | + |
| 229 | + UiFlow2 Code Block: |
| 230 | + |
| 231 | + |set_text_color.png| |
| 232 | + |
| 233 | + MicroPython Code Block: |
| 234 | + |
| 235 | + .. code-block:: python |
| 236 | +
|
| 237 | + scale_0.set_text_color(0xFF0000, 255, lv.PART.INDICATOR) |
| 238 | +
|
| 239 | +
|
| 240 | + .. py:method:: set_style_text_font(font, part) |
| 241 | +
|
| 242 | + Set the font of the scale label text. |
| 243 | + |
| 244 | + :param lv.lv_font_t font: The font to set. |
| 245 | + :param int part: The part of the object to apply the style to lv.PART.INDICATOR. |
| 246 | + |
| 247 | + UiFlow2 Code Block: |
| 248 | + |
| 249 | + |set_style_text_font.png| |
| 250 | + |
| 251 | + MicroPython Code Block: |
| 252 | + |
| 253 | + .. code-block:: python |
| 254 | +
|
| 255 | + scale_0.set_style_text_font(lv.font_montserrat_14, lv.PART.INDICATOR) |
| 256 | +
|
| 257 | + .. py:method:: set_pos(x, y) |
| 258 | +
|
| 259 | + Set the position of the scale. |
| 260 | + |
| 261 | + :param int x: The x-coordinate of the scale. |
| 262 | + :param int y: The y-coordinate of the scale. |
| 263 | + |
| 264 | + UiFlow2 Code Block: |
| 265 | + |
| 266 | + |set_pos.png| |
| 267 | + |
| 268 | + MicroPython Code Block: |
| 269 | + |
| 270 | + .. code-block:: python |
| 271 | +
|
| 272 | + scale_0.set_pos(100, 100) |
| 273 | +
|
| 274 | +
|
| 275 | + .. py:method:: set_x(x) |
| 276 | +
|
| 277 | + Set the x-coordinate of the scale. |
| 278 | + |
| 279 | + :param int x: The x-coordinate of the scale. |
| 280 | + |
| 281 | + UiFlow2 Code Block: |
| 282 | + |
| 283 | + |set_x.png| |
| 284 | + |
| 285 | + MicroPython Code Block: |
| 286 | + |
| 287 | + .. code-block:: python |
| 288 | +
|
| 289 | + scale_0.set_x(100) |
| 290 | +
|
| 291 | +
|
| 292 | + .. py:method:: set_y(y) |
| 293 | +
|
| 294 | + Set the y-coordinate of the scale. |
| 295 | + |
| 296 | + :param int y: The y-coordinate of the scale. |
| 297 | + |
| 298 | + UiFlow2 Code Block: |
| 299 | + |
| 300 | + |set_y.png| |
| 301 | + |
| 302 | + MicroPython Code Block: |
| 303 | + |
| 304 | + .. code-block:: python |
| 305 | +
|
| 306 | + scale_0.set_y(100) |
| 307 | +
|
| 308 | +
|
| 309 | + .. py:method:: set_size(width, height) |
| 310 | +
|
| 311 | + Set the size of the scale. |
| 312 | + |
| 313 | + :param int width: The width of the scale. |
| 314 | + :param int height: The height of the scale. |
| 315 | + |
| 316 | + UiFlow2 Code Block: |
| 317 | + |
| 318 | + |set_size.png| |
| 319 | + |
| 320 | + MicroPython Code Block: |
| 321 | + |
| 322 | + .. code-block:: python |
| 323 | +
|
| 324 | + scale_0.set_size(100, 50) |
| 325 | +
|
| 326 | +
|
| 327 | + .. py:method:: set_width(width) |
| 328 | +
|
| 329 | + Set the width of the scale. |
| 330 | + |
| 331 | + :param int width: The width of the scale. |
| 332 | + |
| 333 | + UiFlow2 Code Block: |
| 334 | + |
| 335 | + |set_width.png| |
| 336 | + |
| 337 | + |set_width1.png| |
| 338 | + |
| 339 | + MicroPython Code Block: |
| 340 | + |
| 341 | + .. code-block:: python |
| 342 | +
|
| 343 | + scale_0.set_width(100) |
| 344 | +
|
| 345 | + .. py:method:: set_height(height) |
| 346 | + |
| 347 | + Set the height of the scale. |
| 348 | + |
| 349 | + :param int height: The height of the scale. |
| 350 | + |
| 351 | + UiFlow2 Code Block: |
| 352 | + |
| 353 | + |set_height.png| |
| 354 | + |
| 355 | + MicroPython Code Block: |
| 356 | + |
| 357 | + .. code-block:: python |
| 358 | +
|
| 359 | + scale_0.set_height(50) |
| 360 | +
|
| 361 | + .. py:method:: align_to(obj, align, x, y) |
| 362 | +
|
| 363 | + Align the scale to another object. |
| 364 | + |
| 365 | + :param lv.obj obj: The object to align to. |
| 366 | + :param int align: The alignment type. |
| 367 | + :param int x: The x-offset from the aligned object. |
| 368 | + :param int y: The y-offset from the aligned object. |
| 369 | + |
| 370 | + UiFlow2 Code Block: |
| 371 | + |
| 372 | + |align_to.png| |
| 373 | + |
| 374 | + MicroPython Code Block: |
| 375 | + |
| 376 | + .. code-block:: python |
| 377 | +
|
| 378 | + scale_0.align_to(page_0, lv.ALIGN.CENTER, 0, 0) |
0 commit comments