|
| 1 | +.. currentmodule:: m5ui |
| 2 | + |
| 3 | +M5Canvas |
| 4 | +======== |
| 5 | + |
| 6 | +.. include:: ../refs/m5ui.canvas.ref |
| 7 | + |
| 8 | +M5Canvas is a powerful graphics widget that provides a drawable surface for creating custom graphics, animations, and visual effects in the user interface. It supports drawing operations, sprite management, and advanced graphics rendering. |
| 9 | + |
| 10 | + |
| 11 | +UiFlow2 Example |
| 12 | +--------------- |
| 13 | + |
| 14 | +draw basic shapes |
| 15 | +^^^^^^^^^^^^^^^^^ |
| 16 | + |
| 17 | +Open the |cores3_canvas_basic_example.m5f2| project in UiFlow2. |
| 18 | + |
| 19 | +This example demonstrates how to create a canvas and draw basic shapes like rectangles, circles, and lines. |
| 20 | + |
| 21 | +UiFlow2 Code Block: |
| 22 | + |
| 23 | + |cores3_canvas_basic_example.png| |
| 24 | + |
| 25 | +Example output: |
| 26 | + |
| 27 | + A canvas with various colored shapes including rectangles, circles, and lines. |
| 28 | + |
| 29 | + |
| 30 | +MicroPython Example |
| 31 | +------------------- |
| 32 | + |
| 33 | +draw basic shapes |
| 34 | +^^^^^^^^^^^^^^^^^ |
| 35 | + |
| 36 | +This example demonstrates how to create a canvas and draw basic shapes programmatically. |
| 37 | + |
| 38 | +MicroPython Code Block: |
| 39 | + |
| 40 | + .. literalinclude:: ../../../examples/m5ui/canvas/cores3_canvas_basic_example.py |
| 41 | + :language: python |
| 42 | + :linenos: |
| 43 | + |
| 44 | +Example output: |
| 45 | + |
| 46 | + A canvas displaying various geometric shapes with different colors. |
| 47 | + |
| 48 | + |
| 49 | +**API** |
| 50 | +------- |
| 51 | + |
| 52 | +M5Canvas |
| 53 | +^^^^^^^^ |
| 54 | + |
| 55 | +.. autoclass:: m5ui.canvas.M5Canvas |
| 56 | + :members: |
| 57 | + :member-order: bysource |
| 58 | + |
| 59 | + .. py:method:: set_flag(flag, value) |
| 60 | +
|
| 61 | + Set a flag on the object. If ``value`` is True, the flag is added; if False, the flag is removed. |
| 62 | + |
| 63 | + :param int flag: The flag to set. |
| 64 | + :param bool value: If True, the flag is added; if False, the flag is removed. |
| 65 | + :return: None |
| 66 | + |
| 67 | + UiFlow2 Code Block: |
| 68 | + |
| 69 | + |set_flag.png| |
| 70 | + |
| 71 | + MicroPython Code Block: |
| 72 | + |
| 73 | + .. code-block:: python |
| 74 | +
|
| 75 | + canvas_0.set_flag(lv.obj.FLAG.HIDDEN, True) |
| 76 | +
|
| 77 | + .. py:method:: toggle_flag(flag) |
| 78 | +
|
| 79 | + Toggle a flag on the object. If the flag is set, it is removed; if not set, it is added. |
| 80 | + |
| 81 | + :param int flag: The flag to toggle. |
| 82 | + :return: None |
| 83 | + |
| 84 | + UiFlow2 Code Block: |
| 85 | + |
| 86 | + |toggle_flag.png| |
| 87 | + |
| 88 | + MicroPython Code Block: |
| 89 | + |
| 90 | + .. code-block:: python |
| 91 | +
|
| 92 | + canvas_0.toggle_flag(lv.obj.FLAG.HIDDEN) |
| 93 | +
|
| 94 | +
|
| 95 | + .. py:method:: set_pos(x, y) |
| 96 | +
|
| 97 | + Set the position of the canvas. |
| 98 | + |
| 99 | + :param int x: The x-coordinate of the canvas. |
| 100 | + :param int y: The y-coordinate of the canvas. |
| 101 | + :return: None |
| 102 | + |
| 103 | + UiFlow2 Code Block: |
| 104 | + |
| 105 | + |set_pos.png| |
| 106 | + |
| 107 | + MicroPython Code Block: |
| 108 | + |
| 109 | + .. code-block:: python |
| 110 | +
|
| 111 | + canvas_0.set_pos(100, 100) |
| 112 | +
|
| 113 | + .. py:method:: set_x(x) |
| 114 | +
|
| 115 | + Set the x-coordinate of the canvas. |
| 116 | + |
| 117 | + :param int x: The x-coordinate of the canvas. |
| 118 | + :return: None |
| 119 | + |
| 120 | + UiFlow2 Code Block: |
| 121 | + |
| 122 | + |set_x.png| |
| 123 | + |
| 124 | + MicroPython Code Block: |
| 125 | + |
| 126 | + .. code-block:: python |
| 127 | +
|
| 128 | + canvas_0.set_x(100) |
| 129 | +
|
| 130 | + .. py:method:: set_y(y) |
| 131 | +
|
| 132 | + Set the y-coordinate of the canvas. |
| 133 | + |
| 134 | + :param int y: The y-coordinate of the canvas. |
| 135 | + :return: None |
| 136 | + |
| 137 | + UiFlow2 Code Block: |
| 138 | + |
| 139 | + |set_y.png| |
| 140 | + |
| 141 | + MicroPython Code Block: |
| 142 | + |
| 143 | + .. code-block:: python |
| 144 | +
|
| 145 | + canvas_0.set_y(100) |
| 146 | +
|
| 147 | + .. py:method:: align_to(obj, align, x, y) |
| 148 | +
|
| 149 | + Align the canvas to another object. |
| 150 | + |
| 151 | + :param lv.obj obj: The object to align to. |
| 152 | + :param int align: The alignment type. |
| 153 | + :param int x: The x-offset from the aligned object. |
| 154 | + :param int y: The y-offset from the aligned object. |
| 155 | + :return: None |
| 156 | + |
| 157 | + UiFlow2 Code Block: |
| 158 | + |
| 159 | + |align_to.png| |
| 160 | + |
| 161 | + MicroPython Code Block: |
| 162 | + |
| 163 | + .. code-block:: python |
| 164 | +
|
| 165 | + canvas_0.align_to(page_0, lv.ALIGN.CENTER, 0, 0) |
| 166 | +
|
| 167 | + .. py:method:: set_size(width, height) |
| 168 | +
|
| 169 | + Set the size of the canvas. |
| 170 | + |
| 171 | + :param int width: The width of the canvas. |
| 172 | + :param int height: The height of the canvas. |
| 173 | + :return: None |
| 174 | + |
| 175 | + UiFlow2 Code Block: |
| 176 | + |
| 177 | + |set_size.png| |
| 178 | + |
| 179 | + MicroPython Code Block: |
| 180 | + |
| 181 | + .. code-block:: python |
| 182 | +
|
| 183 | + canvas_0.set_size(200, 100) |
| 184 | +
|
| 185 | + .. py:method:: set_width(width) |
| 186 | +
|
| 187 | + Set the width of the canvas. |
| 188 | + |
| 189 | + :param int width: The width of the canvas. |
| 190 | + :return: None |
| 191 | + |
| 192 | + UiFlow2 Code Block: |
| 193 | + |
| 194 | + |set_width.png| |
| 195 | + |
| 196 | + MicroPython Code Block: |
| 197 | + |
| 198 | + .. code-block:: python |
| 199 | +
|
| 200 | + canvas_0.set_width(200) |
| 201 | +
|
| 202 | + .. py:method:: set_height(height) |
| 203 | +
|
| 204 | + Set the height of the canvas. |
| 205 | + |
| 206 | + :param int height: The height of the canvas. |
| 207 | + :return: None |
| 208 | + |
| 209 | + UiFlow2 Code Block: |
| 210 | + |
| 211 | + |set_height.png| |
| 212 | + |
| 213 | + MicroPython Code Block: |
| 214 | + |
| 215 | + .. code-block:: python |
| 216 | +
|
| 217 | + canvas_0.set_height(100) |
| 218 | +
|
| 219 | + .. py:method:: get_width() |
| 220 | +
|
| 221 | + Get the width of the canvas. |
| 222 | + |
| 223 | + :return: The width of the canvas. |
| 224 | + :rtype: int |
| 225 | + |
| 226 | + UiFlow2 Code Block: |
| 227 | + |
| 228 | + |get_width.png| |
| 229 | + |
| 230 | + MicroPython Code Block: |
| 231 | + |
| 232 | + .. code-block:: python |
| 233 | +
|
| 234 | + width = canvas_0.get_width() |
| 235 | +
|
| 236 | + .. py:method:: get_height() |
| 237 | +
|
| 238 | + Get the height of the canvas. |
| 239 | + |
| 240 | + :return: The height of the canvas. |
| 241 | + :rtype: int |
| 242 | + |
| 243 | + UiFlow2 Code Block: |
| 244 | + |
| 245 | + |get_height.png| |
| 246 | + |
| 247 | + MicroPython Code Block: |
| 248 | + |
| 249 | + .. code-block:: python |
| 250 | +
|
| 251 | + height = canvas_0.get_height() |
0 commit comments