Qooxdoo:SVG 和元素动作问题
我需要绘制一些表之间的关系,就像在 Wwwsqldesigner 中制作的那样。
但我之前想了解一下Qooxdoo的一些方面。
如果我将所有结构放入 SVG 中,并使用带有内部文本的可拖动矩形来显示表格关系,我可以定义“onDrag”函数来重绘 SVG 的部分(如路径)吗?
或者我必须通过父元素的鼠标反应重新绘制 svg 元素 (就像它在 freedraw 中实现的那样)?如果是这样,我如何找到光标下被单击的元素?
I need to draw relations between some tables, like it is made in Wwwsqldesigner.
But I want to know some aspects of Qooxdoo before.
If I put all structure into SVG, and using draggable rectangles with inner text to show table relations, can I define "onDrag" function to redraw parts of SVG like paths?
Or I have to redraw svg elements with reactions on mouse of parent element
(like it is realised in freedraw)? If it is so, how can I find element under cursor, that being clicked?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SVG contrib 负责区分 qooxdoo 事件和本机 (DOM) 事件,因此您甚至可以“以 qooxdoo 方式”执行此操作,并直接在 SVG 元素上注册单击处理程序:
事件对象为您提供 DOM 元素,但不是 qooxdoo 对象。但是您可以通过使用 qooxdoo 的一些内部结构来找出用户单击了哪个 qooxdoo 对象,如下所示:
SVG 元素类不支持拖动事件。但是您可以使用 mousedown 和 mouseup 事件来实现自己拖动。在 SVG contrib 中,svg.behavior.Draggable 中有一个基本实现,您可以像这样使用它:
目前,Draggable 类还不是很有用,并且没有很多功能,但您可以将它用作如何自行实施的示例。
顺便说一句,Draggable 类将 mousedown 侦听器附加到 SVG 元素,并将 mousemove 和 mouseup 侦听器附加到元素的父级(如 freedraw 演示)。这是因为如果您移动鼠标的速度足够快,则可以在拖动时将鼠标移出矩形。即使用户没有释放鼠标按钮,这也会导致拖动停止。
The SVG contrib takes care of the distinction between qooxdoo events and native (DOM) events, so you can even do it "the qooxdoo way", and register the click handler straight on the SVG element:
The event object gives you the DOM element, but not the qooxdoo object. But you can find out which qooxdoo object the user clicked at, by using some of qooxdoo's internals like this:
The SVG element classes do not support a drag event. But you can implement dragging yourself using mousedown and mouseup events. In the SVG contrib, there is a basic implementation of that in svg.behavior.Draggable, which you use like this:
Currently, the Draggable class is not all that useful yet and does not have many features, but you can use it as an example of how to make your own implementation.
By the way, the Draggable class attaches the mousedown listener to the SVG element, and the mousemove and mouseup listeners to the element's parent (like the freedraw demo). This is because it's possible to move the mouse out of the rectangle while dragging, if you move the mouse quick enough. That would cause the dragging to stop even if the user didn't release the mouse button.
您可以向 DOM 元素注册点击事件:
You can register a click event to the DOM element: