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