2

PopupPanel私はGWTで自分自身を書きました。他のウィジェットに関連するポップアップを表示したい。クラスの私の実装は次のようになります。

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);

            }
        }
    }

}

問題はそれoffsetWidthであり、offsetHeight常に10ですか?

Popover.ui.xmlは次のように見えます:

<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>
4

2 に答える 2

6

この問題を解決するために、PopupPanel'ssetPopupPositionAndShow()で使用されている手順に従いましたが、位置決め手順を遅延コマンドにしました。私のコードは拡張されなかったPopupPanelので、popupPanel変数は次のようになります。

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);
   }
});
于 2013-02-07T07:28:38.707 に答える
1

getOffsetWidth()getOffsetHeight()DOMが完全に構築されており、値を取得するコンテナーが表示され、アタッチされている場合にのみ機能します 。

showRelativeTo()の機能を使ってみませんPopupPanelか?

popup.showRelativeTo(SomeWidget);
于 2011-11-09T12:04:24.827 に答える