How to implement resize handlers / adorners like the ones in the godot editor

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By timothyp

The editor has these resize handlers / adorners for nodes:

screenshot of the godot editor
Screenshot on pasteboard

And I am wondering how I can implement these (or re-use them) at runtime.
Imagine I have a ColorRect which I want the user to be able to resize at runtime.
No matter how far I zoom in or out, those handlers should always remain the same size.

I tried adding a CanvasLayer but that just sticks to the top left corner,
it’s not confined to the Node to which it is attached.

Any ideas?

:bust_in_silhouette: Reply From: jtarallo

No matter how far I zoom in or out, those handlers should always remain the same size.

Regarding this, you could add them as a scalable node and calculate their scale based on your camera zoom so that they remain the same.

Regarding the handlers themselves, you’d have to program a bit of logic to do the mapping of handlers’ position to the resizeable node’s size. You could export some bools to define which size axis that particular handle modifies, and add the logic in the handler’s class itself to do the modifications to its parent.

Also, you’d need a bit of logic to move the connected nodes if you need to. For example, if I move the top left handle upwards, the top right handle must move upwards also.

I can’t think of any more complexity than what I mentioned, although I never tried this before so I don’t know if the effect would be the one desired. Let me know if I can be of more help, maybe go a bit more in depth.

Hope it helps.

If you need further explanation, I can try to go a bit more in-depth.

Turns out Godot draws them manually in their editor.
So I am now doing the same. What I have so far works with just a few issues:

  • Resizing that involves changing position makes the whole thing shake a bit
  • It does not have a good way of setting the minimum size based on
    the current camera scale
  • I have no idea yet how re-usable this is in Godot and if it’s even the correct way

I’ll put a gist up on Github just in case anyone wants it or wants to modify it.
(Since it is to long to be posted here)

	
	
	
	

timothyp | 2020-06-08 11:19