Godot: Add offset centered option to Control nodes

Created on 12 Jun 2018  路  7Comments  路  Source: godotengine/godot

This is a feature request.

I would like to place Control (and actually any CanvasItem) node in a way that makes the center of the node to be at (0,0) and the node, if stretched will keep this center.

Sprite nodes has the centered property which does exactly this.
While it is possible to implement in script, It would be really helpful if other nodes could have this as a property.

Offset Centered enables:
offset_centered

Offset Centered disabled:
offset_centered_off

Control Node has no such option:
control_node

QA question regarding this: https://godotengine.org/qa/24127/sprites-option-centered-collisionshape2d-forced-centered

discussion enhancement editor

Most helpful comment

Regarding controls, there is pivot_offset property inside rect, that when set to half of the rect size will behave exactly like centered property in Sprite.
That said, I think there could be a checkbox to automatically update offset value to work the way how Sprite works, since I'm almost always need to set this value from the script in ready (ofset = size/2) because of how easy it's to forget correcting the offset value after changing control size.

All 7 comments

Regarding controls, there is pivot_offset property inside rect, that when set to half of the rect size will behave exactly like centered property in Sprite.
That said, I think there could be a checkbox to automatically update offset value to work the way how Sprite works, since I'm almost always need to set this value from the script in ready (ofset = size/2) because of how easy it's to forget correcting the offset value after changing control size.

@kubecz3k That would be great!

Regarding pivot_offset, see the third screen-shot, I set the pivot offset to (17.5, 9) which is half of size and the Control did not change it's position. Only the little "+" indicator changed to the center of the Control.

@alkhimey yes, the pivot_offset works as offset during rotation and scaling, which is very helpful when animating UI. However, maybe such full 'centered' option is possible to implement, I'm not sure, but I imagine it could be quite a hassle since many control elements are positioned by other controls in hierarchy.. in such case I'm not sure if this really is junior job

@alkhimey @kubecz3k Hi, I was just testing Godot today and I agree with the last point made by alkhimey I was trying out a simple button node, and when I used the pivot offset I noticed that the position property continues to work off the top-left corner of the node instead of the offset pivot as it should (and as other engines do).

I'm not necessarily in favor of the "centered" checkbox though, because I consider that it would be more coherent to have the canvas items / control nodes transforms to be relative to their offset pivot. So for example in this particular case if you put the pivot offset with a rect_size/2 value (i.e in the center of the node) every transform should work relative to that pivot, not only rotation and scale.

Edit: After re-reading my comment I feel that the position transform not being applied relative to the offset should be treated as a bug. I've been looking at the tracker for some time but this is the only issue that strictly references the problem with the pivot offset with a clear use case is this one. Let me know If I should report it like so or if we should leave it as part of this discussion for now.

developer can use rect_pivot_offset in gdscript as kubecz3k mentioned
also, can just position it in the center. you can use the size of the sprite to help.
this is normal because sometimes, when that text changes, it's good to re-update its position so it's center again

this feature already exists in godot! 馃拑

I don't understand what is being proposed here that is not already possible. What is missing that you can't do with setting the anchor values to 0.5 and setting the margin values to +/- size/2?

@aaronfranke Of course it is also possible to calculate the desired position manually, but what will happen when the control is resized? It will be required to update the position again.
I just what the point of reference to be the center of the control rather than the corner.

Was this page helpful?
0 / 5 - 0 ratings