cdglabs / apparatus

A hybrid graphics editor and programming environment for creating interactive diagrams.
http://aprt.us/
MIT License
1.03k stars 58 forks source link

Dragging Anchors Error #54

Closed zindlerb closed 8 years ago

zindlerb commented 8 years ago

When you drag an Anchor in the outline into a spot where it will render it throws an exception ("Not implemented") because the Graphic.Anchor does not implement the render or hitDetect methods.

image

I see 3 ways to resolve this:

  1. Don't allow Anchors to be dragged. This is the simplest and might make sense since there is not much that can be done with draggable anchors.
  2. Make anchors renderable. They could be represented as little circles. I don't know if this is a good idea because anchors are more of an abstract concept than a shape.
  3. Only make anchors draggable to areas that don't render. I think this would mean it could only be reordered within itself and dragged within other shapes.

I'd be willing to do a pr for this. Let me know if any of these sound good.

joshuahhh commented 8 years ago

Good point!

I think the ideal solution would be a version of your idea 3. In particular, it would be nice to know where in the element tree is a "rendering context" and where in the tree is a "anchor-collection context", and to prevent dragging renderable elements to anchor-collection contexts or dragging anchors to rendering contexts. I can think of a few complications in making this determination:

  1. Groups can be in rendering or anchor contexts. (See how collectAnchors descends through Groups in the definition of Graphic.Path.)
  2. Not all Paths should be able to take anchors. Circle and Text are secretly Paths, but they override the rendering code which cares about anchor descendants. So really, you shouldn't be able to give them children at all.

But these aren't huge problems, and I still think this version of idea 3 would be ideal.

(Your idea 1 isn't great, since dragging anchors within a path serves the useful function of reordering the points on the path. Your idea 2 is interesting, but I agree that it might be confusing to present anchors as independent graphical elements.)

What do you think? If you are interested in taking this on, I would be happy to help however I can.

zindlerb commented 8 years ago

I agree. I can do a pr for this. I'll message you if I have any questions 👍

zindlerb commented 8 years ago

I made a pr for this here https://github.com/cdglabs/apparatus/pull/56. Let me know if this looks like a reasonable approach. Thanks!