-
-
Notifications
You must be signed in to change notification settings - Fork 101
Description
Describe the project you are working on
A multi-platform tower defense game called Rift Riff with a lot of responsive & dynamic UI.
Describe the problem or limitation you are having in your project
Godot's Control and Container system is top-of-class, modular, fantastic to work with, and I have been able to build any layout I and my graphic designer could dream up… except one thing! While there is a way to define a minimum size of a Control, there is no way to define a maximum size of a Control inside a container. We needed this in our game in a few places, all having to do with dynamic (localized) Label and RichTextLabel nodes growing and shrinking the panel it is part of.
To be more specific, there are several places in our project where we want a panel with auto-wrapping text to be as small as possible, wrapping around the text as closely as possible, but up to a certain size. This last thing is currently not possible without a bit of scripting, because text wrapping relies on setting a custom_minimum_size which stops a label to shrink further down, and setting the custom_minimum_size smaller disables growing the label altogether. The hacky fix we applied (which can probably be cleaned up / be improved) is to create a script that derives from label and toggles wrapping and custom_minimum_size depending on it's size:
Hacky fix to give labels a max_width
class_name LabelWithMaxWidth
extends Label
@export var max_width: float
func _ready() -> void:
resized.connect(_on_label_resized)
autowrap_mode = TextServer.AUTOWRAP_OFF
custom_minimum_size = Vector2.ZERO
_on_label_resized()
func set_text_and_adjust_width(_text: String) -> void:
text = _text
autowrap_mode = TextServer.AUTOWRAP_OFF
custom_minimum_size = Vector2.ZERO
func _on_label_resized() -> void:
if size.x > max_width:
autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
custom_minimum_size = Vector2(max_width, 0.0)
Here's a video of the desired behavior in action that uses a slightly modified version of the above script so it works in the editor:
Screen.Recording.2025-11-01.at.13.13.05.mp4
This use case was just our use case though. Other users have had other use cases related to the ScrollContainer as per this proposal and this PR, both unmerged at the time of writing, but the use case is similar: people want a scroll container to shrink to the smallest possible size, but also grow up to a maximum size.
This proposal also addresses the same issue as this proposal attempted to address.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
This proposal supersedes #8333 and godotengine/godot#94171 with a more general solution that comes in two parts: adding a new property to controls, and a compatibility breaking change. These two parts can and probably should be separate PRs, but they are conceptually tied hence why I am proposing them in one proposal.
Part 1
Add a custom_maximum_size to Control. Much like custom_minimum_size, this property will be taken into account when a container positions and sizes this Control, also taking grow and shrink directions into account. If a minimum and maximum size are set, both will be respected as much as possible. If the maximum size is smaller than the minimum size, the minimum size takes precedent.
Part 2
Change the auto-wrap mode from requiring a custom_minimum_size to requiring a custom_maximum_size. This is a compatibility-breaking change, but makes a lot more conceptual sense for auto-wrapping to use as a cutoff point. A minimum size can still be set, but is not required.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I don't know C++ nor anything about the implementation of Container positioning and sizing, but the above descriptions should be a good starting point.
If this enhancement will not be used often, can it be worked around with a few lines of script?
See the script used above.
Is there a reason why this should be core and not an add-on in the asset library?
It is a conceptual sister to custom_minimum_size which is already part of Control nodes.