Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

Fix `Label` not autowrapping with max size

Enzo Novoselic02d671b3dd37
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 26fc944743a..a0a55b9e2a4 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -2095,6 +2095,11 @@ void Control::grow_to_desired_size() {
}
}
+bool Control::is_expanded_by_desired_size() const {
+ ERR_READ_THREAD_GUARD_V(false);
+ return data.expanded_by_desired_size;
+}
+
void Control::add_child_notify(Node *p_child) {
CanvasItem::add_child_notify(p_child);
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 44709c6508c..a54ee635c96 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -618,6 +618,7 @@ public:
void update_desired_size();
void grow_to_desired_size();
+ bool is_expanded_by_desired_size() const;
void set_block_maximum_size_adjust(bool p_block);
void set_block_minimum_size_adjust(bool p_block);
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 4de80ad7403..768b15002ae 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -154,7 +154,11 @@ void Label::_shape() const {
if (maximum_width <= 0) {
maximum_width = 1;
}
- width = maximum_width;
+ if (width > 0 && !is_expanded_by_desired_size()) {
+ width = MIN(width, maximum_width);
+ } else {
+ width = maximum_width;
+ }
}
if (text_dirty) {