You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/basic_usage.rst
+37-3Lines changed: 37 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,13 +36,47 @@ that does not need to update much while other objects moves a lot on the screen.
36
36
Resize Canvas
37
37
-------------
38
38
39
-
You can dynamically resize the ``Canvas`` and ``MultiCanvas``, note that this will clear the canvas.
39
+
The ``Canvas`` and ``MultiCanvas`` have two sizes: the size of the color buffer in pixels, and the actual size
40
+
displayed on the screen.
41
+
42
+
Color buffer size
43
+
^^^^^^^^^^^^^^^^^
44
+
45
+
The color buffer size can dynamically be updated through the ``width`` and ``height`` properties (value in pixels), note that this will clear the canvas.
40
46
41
47
.. code:: Python
42
48
43
49
canvas.width =300
44
50
canvas.height =600
45
51
52
+
Screen size
53
+
^^^^^^^^^^^
54
+
55
+
The size on the screen can be updated through the ``layout`` property, which comes from ipywidgets (see https://ipywidgets.readthedocs.io/en/latest/examples/Widget%20Styling.html#The-layout-attribute). The ``layout`` property is an object which contains CSS properties for the canvas.
56
+
57
+
The default value for the ``width`` and ``height`` of the layout is "auto", this means the canvas will take the same screen size as the actual color buffer size: a ``Canvas`` of
58
+
size ``800x600`` will take ``800x600`` pixels on the screen.
59
+
60
+
.. code:: Python
61
+
62
+
canvas.layout.width ='auto'
63
+
canvas.layout.height ='auto'
64
+
65
+
In order to get a "responsive" ``Canvas`` which takes as much space as available while still respecting the aspect ratio, you will need to set the ``width``
66
+
property to ``100%``, the ``height`` will automatically get computed:
67
+
68
+
.. code:: Python
69
+
70
+
canvas.layout.width ='100%'
71
+
canvas.layout.height ='auto'
72
+
73
+
One can also set the screen size value in pixels:
74
+
75
+
.. code:: Python
76
+
77
+
canvas.layout.width ='200px'
78
+
canvas.layout.height ='500px'
79
+
46
80
Clear Canvas
47
81
------------
48
82
@@ -63,9 +97,9 @@ Optimizing drawings
63
97
64
98
By default, the Python ``Canvas`` object sends all the drawings commands like ``fill_rect``
65
99
and ``arc`` one by one through the widgets communication layer. This communication is limited
66
-
to 1000 commands/s and it can be extremely slow to send commands one after the other.
100
+
to 1000 commands/s and it can be extremely slow to send commands one after the other.
67
101
You can increase this limit via internal Jupyter `parameters <https://github.com/martinRenou/ipycanvas/issues/102>`_,
68
-
however this is not recommended as it can lead to instability. Instead we provide a ``hold_canvas``
102
+
however this is not recommended as it can lead to instability. Instead we provide a ``hold_canvas``
69
103
context manager which allows you to hold all the commands and send them in a single batch at the end. For
70
104
optimal performance you should try to use ``hold_canvas`` as much as possible.
0 commit comments