Skip to content

Commit 6f25c1e

Browse files
authored
Merge pull request #68 from martinRenou/improve_layout
Improve layout
2 parents ce2296a + ea60f04 commit 6f25c1e

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ipycanvas/canvas.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ def __init__(self, *args, **kwargs):
177177
self._buffers_cache = []
178178

179179
super(Canvas, self).__init__(*args, **kwargs)
180-
self.layout.width = str(self.size[0]) + 'px'
181-
self.layout.height = str(self.size[1]) + 'px'
182180

183181
self.on_msg(self._handle_frontend_event)
184182

@@ -603,8 +601,6 @@ def __init__(self, n_canvases=3, *args, **kwargs):
603601
size = kwargs.get('size', (700, 500))
604602

605603
super(MultiCanvas, self).__init__(*args, _canvases=[Canvas(size=size) for _ in range(n_canvases)], **kwargs)
606-
self.layout.width = str(size[0]) + 'px'
607-
self.layout.height = str(size[1]) + 'px'
608604

609605
def __getitem__(self, key):
610606
"""Access one of the Canvas instances."""

src/widget.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,15 @@ class MultiCanvasView extends DOMWidgetView {
512512
// @ts-ignore
513513
return this.create_child_view(canvasModel).then((canvasView: CanvasView) => {
514514
canvasView.el.style.zIndex = index;
515-
canvasView.el.style.position = 'absolute';
515+
516+
if (index == 0) {
517+
// This will enforce the container to respect the children size.
518+
canvasView.el.style.position = 'relative';
519+
canvasView.el.style.float = 'left';
520+
} else {
521+
canvasView.el.style.position = 'absolute';
522+
}
523+
516524
this.container.appendChild(canvasView.el);
517525

518526
return canvasView;

0 commit comments

Comments
 (0)