BTW, here's the uibinder composite "MyComposite", and the code that
uses it:
public class MyComposite extends Composite {
private static MyCompositeUiBinder uiBinder =
GWT.create(MyCompositeUiBinder.class);
interface MyCompositeUiBinder extends UiBinder<Widget, MyComposite> {
}
public MyComposite() {
initWidget(uiBinder.createAndBindUi(this));
}
}
public class MyEntryPoint implements EntryPoint {
public void onModuleLoad() {
final MyComposite myComposite = new MyComposite();
rootPanel.add(myComposite);
rootPanel.add(new Label("" + myComposite.getOffsetWidth()));
DeferredCommand.addCommand(new Command() {
@Override
public void execute() {
rootPanel.add(new Label("" +
myComposite.getOffsetWidth()));
}
});
}
}
The first label shows 987 (or whatever the width of <body> is), the
second label shows 80.
On Jun 6, 9:58 pm, Chris Lercher <[email protected]> wrote:
> Hi,
>
> I want to perform a size calculation on a composite generated by
> UiBinder, using UIObject.getOffsetWidth(). The composite's ui.xml
> (simplified) looks like this:
>
> <ui:style>
> .test {
> width: 80px;
> height: 50px;
> }
> </ui:style>
> <g:HTMLPanel styleName="{style.test}">
> </g:HTMLPanel>
>
> When I execute getOffsetWidth() during onModuleLoad(), the result is
> 987 (the same as the body's width in my case). That's quite
> understandable: I assume, the CSS from the ui.xml isn't applied yet.
>
> So I put getOffsetWidth() in a DeferredCommand, and now it returns 80,
> which is correct.
>
> But I'm a bit worried, that this may actually be a race condition: Can
> I be sure, that the CSS will be fully loaded, before the
> DeferredCommand gets its turn? Or is there a better place to put that
> code?
>
> Thanks
> Chris
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.