如何防止将GWT DialogBox拖出屏幕? [英] How to prevent GWT DialogBox from being dragged out of the screen?
本文介绍了如何防止将GWT DialogBox拖出屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一个简单的解决方案,可以将我的GWT DialogBox
拖出屏幕。主机有CSS规则 overflow:hidden
,因为我不希望任何滚动条出现。
显然我需要以某种方式将聆听者附着到拖拽上并防止将其带到外面的移动。我只能看到 onMouseMove
, beginDragging
, endDragging
方法 DialogBox
。
解决方案
以下方式:
@Override
保护无效endDragging(MouseUpEvent事件)
{
int genericMargin = 60;
int leftMargin = - (this.getOffsetWidth() - genericMargin);
int lowerMargin = Window.getClientHeight() - genericMargin;
int rightMargin = Window.getClientWidth() - genericMargin;
int upperMargin = 0;
if(this.getAbsoluteLeft()> rightMargin)
{this.setPopupPosition(rightMargin,this.getPopupTop());如果(this.getAbsoluteLeft()< leftMargin)
{this.setPopupPosition(leftMargin,this.getPopupTop());}
if }
$ b $ if(this.getAbsoluteTop()> lowerMargin)
{this.setPopupPosition(this.getPopupLeft(),lowerMargin);}
if(this .getAbsoluteTop()< upperMargin)
{this.setPopupPosition(this.getPopupLeft(),upperMargin);}
super.endDragging(event);
}
顺便说一下,它正确地工作! ;)
I am looking for a simple solution for the issue that my GWT DialogBox
can be dragged out of the screen. The host has the CSS rule overflow:hidden
because I do not want any scrollbars to appear.
Obviously I need to attach somehow a listener to the dragging and prevent moves that would bring it outside. I can only see onMouseMove
, beginDragging
, endDragging
methods in DialogBox
.
解决方案
"We" have worked around this issue in the following way:
@Override
protected void endDragging(MouseUpEvent event)
{
int genericMargin = 60;
int leftMargin = -(this.getOffsetWidth() - genericMargin);
int lowerMargin = Window.getClientHeight() - genericMargin;
int rightMargin = Window.getClientWidth() - genericMargin;
int upperMargin = 0;
if (this.getAbsoluteLeft() > rightMargin)
{this.setPopupPosition(rightMargin, this.getPopupTop()); }
if (this.getAbsoluteLeft() < leftMargin)
{ this.setPopupPosition(leftMargin, this.getPopupTop()); }
if (this.getAbsoluteTop() > lowerMargin)
{ this.setPopupPosition(this.getPopupLeft(), lowerMargin);}
if (this.getAbsoluteTop() < upperMargin)
{ this.setPopupPosition(this.getPopupLeft(), upperMargin);}
super.endDragging(event);
}
BTW it correctly works as it is! ;)
这篇关于如何防止将GWT DialogBox拖出屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文