GWT - 当不可见时设置画布大小
我在隐藏面板中有一个画布。它是在面板可见之前创建的。问题 我想将其 DOM 宽度设置为 100%,但 setCoordinateSpaceWidth 遇到问题,因为我无法通过 getOffsetWidth 获取画布尺寸,因为画布不可见。我什至不认为我可以向 Canvas 添加 resizeevent ,也没有 VisibleEvent 。如果有人知道如何规避这个问题,我将不胜感激?
干杯,
托马斯
I have a canvas in a hidden panel. It is created before the panel is made visible. The problem I'd like to set its DOM width to 100% but I have a problem with the setCoordinateSpaceWidth then as I cannot get the canvas dimension via getOffsetWidth as the canvas is not visible. I don't even think I can add a resizeevent to Canvas nor is there a VisibleEvent. Would appreciate if anybody had an idea as to how to circumvent the problem?
Cheers,
Thomas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
(下面是一个潜在的解决方案,而不仅仅是“我也是”。继续阅读)
这里有类似的问题。
TabLayoutPanel 上选项卡中的画布。
第二个选项卡上的一些控件用于操作画布。
绘图失败,因为画布报告宽度为 0。
获取画布(或其容器元素)宽度的可靠方法或 VisibleEvent 都是完美的。
我的解决方案是向选项卡面板添加一个选择处理程序。
当我的画布面板变得可见时,我使用 ScheduleDeferred 调用启用在画布上绘图并强制重绘的方法。当选择画布以外的选项卡时,我会禁用在画布上绘图。
并不适合所有人,但可能会给你一个想法!
(One potential solution below, not just a "me too". Keep reading)
Similar problem here.
Canvas in a tab on a TabLayoutPanel.
Some controls on a second tab to manipulate the canvas.
Drawing fails because canvas reports a 0 width.
Either a reliable way to get the canvas (or it's container element) width or a VisibleEvent would be perfect.
My solution was to add a selectionHandler to the tab panel.
When my canvas' panel becomes visible, I use scheduleDeferred to call method that enables drawing on the canvas and forces a redraw. When a tab other than my canvas is selected, I disable drawing on my canvas.
Won't work for everyone, but may give you an idea!