Handle components with negative position

Hi, first I’d like to thank juce team for such an awesome library.

I got some draggable child components which are located freely in the parent component, parent has also to perform panning, zooming and must be able to create childs at runtime with an arbitrary position, every child component has a mouseDown and mouseDrag override, and ones dragged I use setTopLeftCorner to position them relative to parents bounds, the parent also has overrided childBoundsChanged and has to resize when a node goes out of localBounds, up to this point everything works fine but when any child would go with a negative position, it’s clipped out. Doesn’t matter how I resize and reposition the parent component, those nodes are always out of localBounds and gone like forever.

I’ve tried to use setPaintingIsUnclipped(true) on parent and childs and can draw them but can’t make hitTest work outside parentsBounds, and I guess even if I somehow make it work it’s not a good solution anyway.

In the end, I wan’t to accomplish a nodeGraph behavior with infinite large bounds in all directions, and can have a very large amount of childs nodes.

Any better approach suggestions or for now is there a proper way to get childs components with negative position work the same way as they would when are within positive parentBounds?

1 Like

There are two options:

  1. you can change the matrix of the component using Component::setTransform()
  2. use a Viewport, that gives you a virtual component with scrollbars

The setPaintingUnclipped you set on the child component, because this shall be painted outside of it’s localBounds.
If you want to fiddle around, you can make a child a mouseListener of it’s parent, that way it will receive the events of it’s parent even if it’s outside (but you may get events twice, and I don’t think it’s a good way to do it).

  1. you can change the matrix of the component using Component::setTransform()

I intended to use transform for panning and zooming the parent component, the problem is, child components can be dragged outside the parent bounds in negative direction, and transforming the parent will not help to get them visible. I could resize the parent and move all children in visible area, but that will be very ineffective.

Example: Main component “window” which intercepts mouse and keyboard events for things like panning and zooming and sets transform of its child component - “viewer”.
The “viewer”'s job is to refit to a large number of children components with any position and size.
Children components can be dragged in any direction inside the viewer, and the problem is when the go beyond in negative position like setBounds(-100,-100,width,height), and there is no way to make them visible again inside “viewer” except moving all the children so all of them have positive position.