获取组件可见区域的全局坐标
我试图确定当前在舞台上渲染的可见矩形的全局坐标。
具体来说,如果画布具有明确的高度和宽度,并且是具有滚动条的面板的子级,则滚动条可以“隐藏”画布的一部分。 ContentToGlobal(x,y) 提供内容当时的全局位置,但内容坐标可以滚动到父面板的边界之外,并继续给出不可见的 x,y 坐标。
有没有办法确定没有被任何东西隐藏的可见矩形?
I am trying to determine the global coordinates of the visible rectangle that is currently rendered on the stage.
Specifically, if a canvas has an explicit height and width and is a child of a panel that has a scrollbar, the scrollbar can "hide" a part of the canvas. ContentToGlobal(x,y) provides the global position of the content at the time, but content coordinates can scroll off the boundaries of the parent panel and continue to give x,y coordinates that are not visible.
Is there a way to determine the viewable rectangle that is not hidden by anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明, UIComponent 类有一个未记录的公共函数,它正是我所寻找的。
这是从类中提取出来的,并被记录为私有,但实际上是一个可公开访问的函数,可以在任何 UI 对象上使用。
由于这不在任何地方的文档中,我想它可能容易受到未来变化的影响。
It turns out that the UIComponent class has an undocumented public function that does exactly what I was looking for.
This is pulled from the class and is documented as private but is actually a publicly accessible function that can be used on any UI object.
Since this isn't in the documentation anywehere, I imagine it may be susceptible to future changes.
不,没有直接的解决方案。
您应该手动计算可见矩形:
使用示例:
No, there is no straightforward solution.
You should calculate the visible rectangle manually:
Example of usage: