LayoutPanel animation with Canvas

98 views
Skip to first unread message

RyanZA

unread,
Aug 8, 2012, 5:29:36 PM8/8/12
to google-we...@googlegroups.com
I have a layout panel with two child panels, with one of the children being a HTML5 canvas.

It all works well until I try to use the animate() method of the parent canvas to move the children around. It makes the canvas lose its image and reset to transparent.
Any idea why animate() would do this, and any workarounds to animate panel movement while not making the canvas redraw?

Ümit Seren

unread,
Aug 10, 2012, 10:37:46 AM8/10/12
to google-we...@googlegroups.com
Looks more like a browser/javascript issue than a GWT issue. LayoutPanels using CSS absolute positioning for animation.
On which browsers do you have this issue? Firefox? chrome?

RyanZA

unread,
Aug 10, 2012, 11:23:50 AM8/10/12
to google-we...@googlegroups.com
I found the cause - in onResize() I was setting the size of the canvas to match the container. Doing that causes the canvas to be cleared. onResize() is called on the canvas even though it was not changing size - a sibling was changing size only. So it may be a minor bug in LayoutPanel in that it calls onResize() on all children during an animation, not just the children being animated.

I changed the onResize() to only set the pixel size of the canvas when it actually differed from the current size, which seems to fix it.

Code:

        int width = this.getElement().getParentElement().getClientWidth();
        int height = this.getElement().getParentElement().getClientHeight();
       
        if (this.getCoordinateSpaceWidth() != width)
            this.setCoordinateSpaceWidth(width);
        if (this.getCoordinateSpaceHeight() != height)
            this.setCoordinateSpaceHeight(height);
Reply all
Reply to author
Forward
0 new messages