The 2nd method appears to work. See comments below.
On Oct 18, 7:50 am, Uemit <
uemit.se...@gmail.com> wrote:
> I think there are two ways to do that.
>
> 1.) Call forceLayout() on your LayoutContainer. This will call onResize on
> all client widgets which implement the RequireResize interface.
> In the onResize method of your canvas widget you can retrieve the available
> width by calling getParent().getOffsetWidth() (instead of getParent() you
> can call it on a container panel etc)
>
I called forceLayout after adding the container to it's parent but the
size available via getElement().getClientWidth() when onSize is called
is -22,0. It would appear the layout engine has not actually done
it's job yet so the sizes are not apportioned.
> 2.) When the canvas widget gets constructed you can issue a deferred command
> and set the size in it:
>
> Scheduler.get().scheduleDeferred(new ScheduledCommand() {
> @Override
> public void execute() {
> canvasWidget.onResize();
> }
> });
This 2nd approach works! I'm a bit worried about timing since #1 did
not work though. Can I know for sure the size has been set by the
time it has been scheduled?
I decided to combine the two suggestions so after I've added my layout
to the DOM I use the Scheduler trick to call onResize() on the
container. This allows other child views that have also been added
during the creation process to get notified including the layout that
contains the Canvas element.
I could have called forceLayout() but since the layout seemed to have
already been done by the time the scheduler callback occurred I just
used onResize().
This seems like something that should be in the framework - calling
onResize() when a layout has been added to the DOM.
Thanks for the tip!