1

我有一个带有一些 IButton 的 HStack。我可以使用 darg & drop 移动 HStack 中的按钮。现在一个想要在IButton最终集成到HStack后有一个通知。我想确定 HStack 中拖动按钮的位置。我只找到了一个 DropHander(用于 Hstack)和 DragRepositionStopHandler(用于 Button)。释放鼠标按钮后,两者都会触发事件。此时按钮不在 HStack 中。我的问题是:在将项目添加到布局小部件后,是否会有 EventHander 触发事件?

提前致谢。

梅德罗德

4

1 回答 1

0

After the DropEvent is fired, your Button is in position and about to become member of the HStack. Nothing can actually stop this. So when you receive this event all you have to do at the HStack is to retrieve the source of the event and call its getAbsoluteLeft and getAbsoluteTop methods. This will give you the position of the Button within the browser. If you want to receive the position within the HSTack, add them to the Left and Top coordinates of the HStack, respectively. Something like the following can be used:

HStack hStack = new HStack();
hStack.addDropHandler(new DropHandler() {

        @Override
        public void onDrop(DropEvent event) {
            Object source = event.getSource();
            if (source instanceof BaseWidget) { //This shall cover all Buttons and UI elements.
                int buttonLeftPosition = ((BaseWidget) source).getAbsoluteLeft();
                int buttonTopPosition = ((BaseWidget) source).getAbsoluteTop();
            }
        }
    });
于 2012-08-08T10:45:10.933 回答