Skip to content

Commit 94230c1

Browse files
committed
Default the layout to the canvas size
1 parent 9b8cd22 commit 94230c1

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

examples/introduction.ipynb

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"metadata": {},
2525
"outputs": [],
2626
"source": [
27-
"c = ipycanvas.Canvas()\n",
28-
"c.layout.height = '200px'\n",
27+
"c = ipycanvas.Canvas(size=(200, 200))\n",
2928
"\n",
3029
"c"
3130
]
@@ -50,10 +49,7 @@
5049
"metadata": {},
5150
"outputs": [],
5251
"source": [
53-
"c = ipycanvas.Canvas(stroke_style='red', size=(700, 200))\n",
54-
"c.layout.width = '700px'\n",
55-
"c.layout.height = '200px'\n",
56-
"\n",
52+
"c = ipycanvas.Canvas(stroke_style='red', size=(200, 200))\n",
5753
"c"
5854
]
5955
},
@@ -64,7 +60,6 @@
6460
"outputs": [],
6561
"source": [
6662
"# Draw smiley face\n",
67-
"# c.stroke_style='red'\n",
6863
"c.begin_path()\n",
6964
"c.arc(75, 75, 50, 0, pi * 2, True) # Outer circle\n",
7065
"c.move_to(110, 75)\n",
@@ -82,8 +77,7 @@
8277
"metadata": {},
8378
"outputs": [],
8479
"source": [
85-
"c = ipycanvas.Canvas(size=(700, 200))\n",
86-
"c.layout.height = '200px'\n",
80+
"c = ipycanvas.Canvas(size=(200, 200))\n",
8781
"\n",
8882
"c"
8983
]
@@ -112,8 +106,7 @@
112106
"metadata": {},
113107
"outputs": [],
114108
"source": [
115-
"c = ipycanvas.Canvas(size=(700, 200))\n",
116-
"c.layout.height = '200px'\n",
109+
"c = ipycanvas.Canvas(size=(150, 150))\n",
117110
"\n",
118111
"c"
119112
]
@@ -210,8 +203,6 @@
210203
"outputs": [],
211204
"source": [
212205
"c = ipycanvas.Canvas(size=(150, 150))\n",
213-
"c.layout.width = '150px'\n",
214-
"c.layout.height = '150px'\n",
215206
"\n",
216207
"c"
217208
]

ipycanvas/canvas.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class Canvas(DOMWidget):
2525
stroke_style = Color('black').tag(sync=True)
2626
global_alpha = Float(1.0).tag(sync=True)
2727

28+
def __init__(self, *args, **kwargs):
29+
super(Canvas, self).__init__(*args, **kwargs)
30+
self.layout.width = str(self.size[0]) + 'px'
31+
self.layout.height = str(self.size[1]) + 'px'
32+
2833
# Rectangles methods
2934
def fill_rect(self, x, y, width, height):
3035
"""Draw a filled rectangle."""

0 commit comments

Comments
 (0)