GWT: PopupPanel setPopupPositionAndShow () entrega offsetWidth y offsetHeight incorrectos

Yo he escrito el mío PopupPanel in GWT. I want to show the popup relative to an other widget. My implementation of the class looks like the following:

public class Popover extends PopupPanel implements PositionCallback {

    private static final Binder binder = GWT.create(Binder.class);
    private UIObject relative;

    interface Binder extends UiBinder<Widget, Popover> {
    }

    public Popover() {
        setWidget(binder.createAndBindUi(this));
        setStylePrimaryName("popover");
    }

    public void show(UIObject relative) {

        this.relative = relative;
        setPopupPositionAndShow(this);

    }

    public void setPosition(int offsetWidth, int offsetHeight) {

        if (relative != null) {

            int left = relative.getAbsoluteLeft();
            int top = relative.getAbsoluteTop();
            int width = relative.getOffsetWidth();
            int height = relative.getOffsetHeight();

            int topCenter = top + height / 2 - offsetHeight / 2;


            if (offsetWidth < left) {
                setPopupPosition(left - offsetWidth, topCenter);
            } else {
                setPopupPosition(left + width, topCenter);

            }
        }
    }

}

El problema es que offsetWidth y offsetHeight es siempre 10?

My Popover.ui.xml se parece a lo siguiente:

<g:FlowPanel stylePrimaryName="popover">
    <g:FlowPanel stylePrimaryName="arrow" />
    <g:FlowPanel stylePrimaryName="inner">
        <g:Label stylePrimaryName="title" text="New Label" />
        <g:FlowPanel stylePrimaryName="content">
            <g:Label text="Hallo" />
        </g:FlowPanel>
    </g:FlowPanel>
</g:FlowPanel>

preguntado el 08 de noviembre de 11 a las 17:11

Please post the contents of Popover.ui.xml -

Updated the post with the Popover.ui.xml -

How about the CSS that goes with those primary style names? -

2 Respuestas

To solve this issue, I followed the steps used by PopupPanel's setPopupPositionAndShow(), but I made the positioning step a deferred command. My code didn't extend PopupPanel, por lo tanto, la popupPanel variable:

popupPanel.setVisible(false);
popupPanel.show();

// Pausing until the event loop is clear appears to give the browser
// sufficient time to apply CSS styling.  We use the popup's offset
// width and height to calculate the display position, but those
// dimensions are not accurate until styling has been applied.
Scheduler.get().scheduleDeferred(new ScheduledCommand() {
   @Override
   public void execute() {
      yourMethodToSetPositionGoesHere(popupPanel);
      popupPanel.setVisible(true);
   }
});

Respondido 15 Feb 13, 18:02

getOffsetWidth() y getOffsetHeight() only work if the DOM is fully constructed and the container for which you want to get the value is visible and attached.

¿Por qué no usas el showRelativeTo() función de la PopupPanel?

popup.showRelativeTo(SomeWidget);

Respondido 15 Feb 13, 18:02

The position of popup.showRelativeTo(SomeWidget); is not as i want it to. Most of my popups must be shown left or right of the relativeWidget. The showRelativeTo method displays the PopupPanel nearly always under the relativeWidget =(. - user1036071

ok I see. Did you try to specify explicit sizes for your FlowPanels? - esperanza

FYI: popup.showRelativeTo(SomeWidget) still ends up calling getOffsetWidth(). - Glen Pierce

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.