-
-
Notifications
You must be signed in to change notification settings - Fork 18.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add render transform to Control nodes #87081
base: master
Are you sure you want to change the base?
Add render transform to Control nodes #87081
Conversation
I remember Node2D has properties. Vector2 | position | Vector2(0, 0) How are these different? Edit: Will review the proposal. |
One could argue that both |
I've gotten so used to the bug it may as well be a feature to me. 5 years ever since it has been reported, too. This "bug" does have its advantages in the same exact way as |
@Mickeon yeah, that's why I added render_rotation. So if the bug with rotation gets fixed eventually, people who used it for animation can switch to render_rotation and people who want rotated controls to actually use more space can finally do that. Same for scale and render_scale. |
How this would affect children of the animated node, if at all? In our games we're usually animating whole control-based scenes or Containers, like a playing card or something, frequently containing both Controls and Node2D, so the whole thing needs to be animated as a unit. I currently achieve that by applying an animation transform to the node but only after any parent Container does its layout. |
@djrain the current implementation sets the CanvasItem transform of the Control node, so it affects all children as well. |
c5123f0
to
ff160eb
Compare
@AThousandShips thanks for the review 🙌 applied everything and fixed code style issues |
ff160eb
to
f7ce79c
Compare
@AThousandShips now it should have everything except the px suffix |
7b26c72
to
5eed27e
Compare
5eed27e
to
891f968
Compare
d068334
to
d8bdea9
Compare
d8bdea9
to
7e3e661
Compare
dcadbb1
to
1383ae0
Compare
950d99d
to
e7a7125
Compare
Two things:
|
@Mickeon thanks for noticing, I was aware of it! I had a small fun project using the changes of this PR going on until today hence I didn't write the docs yet and didn't remove the WIP status. I'll get this PR ready in the next days hopefully. |
e7a7125
to
670b55d
Compare
@Mickeon I added the docs and removed the WIP status so the PR should be ready for review now 🙂 |
That's good, I... hmm... This is not a review but some thoughts:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested locally, it works as expected. There's the question of whether we should shift input coordinates as well, but this isn't always desired if you're using this for animation purposes. For instance, when hovering an UI element and shifting it upwards, if you held your mouse cursor on the bottom edge of the element, you could end up in a situation where the UI element is being hovered and unhovered continuously in a loop. Not shifting input coordinates prevents this kind of situation, at the cost of less a precise idea of where you can actually click the button (particularly for rotated buttons).
godotengine/godot-proposals#4338 would be a particularly good pairing with this PR, so that you can easily extend the clickable area of your buttons to cater for the space they can take during an animation.
Testing project: test_pr_87081.zip
cards.mp4
@Mickeon I can only speak for myself, but I've had more use for the newly added properties in contrast to existing I didn't measure it but I can't imagine the overhead being even noticable. The final transform is not calculated every frame but is cached iirc. |
First of all, amazing pull request, indeed very useful. I would only suggest to check if you're not setting the same value in the setters. To avoid a calling notify and a queue draw. |
This is an implementation of my proposal outlined in this discussion: godotengine/godot-proposals#7053 (comment)
tl;dr: Currently it's hard and complicated to animate Control nodes without breaking the layout, especially if the Control nodes are in deeply nested layout structures which is often the case. This PR adds new properties to Control nodes that specify a render transform that does not affect and is not affected by layouting (similar to CSS'
transform
). These make UI animations much less pain to work withrender_offset
: translationrender_scale
: scalerender_rotation
, rotationrender_transform_pivot
, pivot for scaling and rotatingrender_offset
andrender_transform_pivot
are relative to the size of the Control node by default (I think it's a very common usecase to rotate around and scale from the center) but it can be toggled to use absolute pixel values instead.Screencast.from.2024-01-11.17-10-13.webm
Considerations
Input is currently not affected by the render transform. That means if you e.g. apply a render offset to a button, the button is still clickable at its original position but drawn somewhere else. This might need some discussion whether that's desirable or not.