0 votes

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?

in Engine by (23 points)

1 Answer

0 votes

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.

by (380 points)

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)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.