Add "desired size" to Control

A `Control` can define `get_desired_size()` which allows it to grow based on its content without increasing its minimum size.
This new size will be respected by parent `Container`s.
Currently used by `Label` and `TabBar`.
This commit is contained in:
StarryWorm
2026-04-11 18:18:18 -04:00
committed by Enzo Novoselic
parent 6d6e822c68
commit 05737cd449
33 changed files with 454 additions and 72 deletions
+11 -3
View File
@@ -996,13 +996,13 @@ bool GraphNode::is_ignoring_valid_connection_type() const {
return ignore_invalid_connection_type;
}
Size2 GraphNode::get_minimum_size() const {
Size2 GraphNode::_get_minimum_size(bool p_use_desired_sizes) const {
Ref<StyleBox> sb_panel = theme_cache.panel;
Ref<StyleBox> sb_titlebar = theme_cache.titlebar;
Ref<StyleBox> sb_slot = theme_cache.slot;
int separation = theme_cache.separation;
Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size();
Size2 minsize = (p_use_desired_sizes ? titlebar_hbox->get_bound_desired_size() : titlebar_hbox->get_minimum_size()) + sb_titlebar->get_minimum_size();
for (int i = 0; i < get_child_count(false); i++) {
Control *child = as_sortable_control(get_child(i, false));
@@ -1010,7 +1010,7 @@ Size2 GraphNode::get_minimum_size() const {
continue;
}
Size2i size = child->get_bound_minimum_size();
Size2i size = p_use_desired_sizes ? child->get_bound_desired_size() : child->get_bound_minimum_size();
size.width += sb_panel->get_minimum_size().width;
if (slot_table.has(i)) {
size += slot_table[i].draw_stylebox ? sb_slot->get_minimum_size() : Size2();
@@ -1029,6 +1029,14 @@ Size2 GraphNode::get_minimum_size() const {
return minsize;
}
Size2 GraphNode::get_minimum_size() const {
return _get_minimum_size(false);
}
Size2 GraphNode::get_desired_size() const {
return _get_minimum_size(true);
}
void GraphNode::_port_pos_update() {
int edgeofs = theme_cache.port_h_offset;
int separation = theme_cache.separation;