开发者

how to get a GWT PopupPanel centered in a users current view port on mobile safari?

开发者 https://www.devze.com 2023-03-20 14:28 出处:网络
calling .center() makes the panel center on the entire page.. I\'d like to have it dead center of the current view port... additionally I\'d like to prevent scrolling.. but maybe I\'开发者_StackOverfl

calling .center() makes the panel center on the entire page.. I'd like to have it dead center of the current view port... additionally I'd like to prevent scrolling.. but maybe I'开发者_StackOverflowll come back to that one.


Dead center is left for an exercise for the user, but the key component is Window.getScrollTop() and Window.getScrollLeft()


The standard center() method does not do what you want. So you have to calculate the position yourself. There is one big problem that is your popup does not have a size before it is actually shown. The size of any DOM element can not be queried until it is fully attached to the DOM. You have to inherit the GWT popup class and overriding the onLoad() method to get the size of the popup. Try something like this:

public class CenteredDialogBox extends DialogBox {

    private Widget _parent;

    public CenteredDialogBox(Widget parent) {
        _parent = parent;
    }

    @Override
    public void onLoad() {
        super.onLoad();

        int parentMiddle = _parent.getAbsoluteLeft() + _parent.getOffsetWidth() / 2;
        int popupLeft = parentMiddle - getOffsetWidth() / 2;
        int parentCenter = _parent.getAbsoluteTop() + _parent.getOffsetHeight() / 2;
        int popupTop = parentCenter - getOffsetHeight() / 2;

        setPopupPosition(popupLeft, popupTop);
    }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消