Merge pull request #92664 from KoBeWi/ultimate_final_solution_for_containers

Add visibilty mode to `as_sortable_control()`
This commit is contained in:
Rémi Verschelde 2024-06-07 23:29:48 +02:00
commit a6bb8b00d7
No known key found for this signature in database
GPG Key ID: C3336907360768E1
9 changed files with 35 additions and 23 deletions

View File

@ -243,8 +243,8 @@ Size2 BoxContainer::get_minimum_size() const {
bool first = true;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
if (!c || !c->is_visible() || c->is_set_as_top_level()) {
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
if (!c) {
continue;
}

View File

@ -139,9 +139,15 @@ void Container::queue_sort() {
pending_sort = true;
}
Control *Container::as_sortable_control(Node *p_node) const {
Control *Container::as_sortable_control(Node *p_node, SortableVisbilityMode p_visibility_mode) const {
Control *c = Object::cast_to<Control>(p_node);
if (!c || !c->is_visible_in_tree() || c->is_set_as_top_level()) {
if (!c || c->is_set_as_top_level()) {
return nullptr;
}
if (p_visibility_mode == SortableVisbilityMode::VISIBLE && !c->is_visible()) {
return nullptr;
}
if (p_visibility_mode == SortableVisbilityMode::VISIBLE_IN_TREE && !c->is_visible_in_tree()) {
return nullptr;
}
return c;

View File

@ -41,8 +41,14 @@ class Container : public Control {
void _child_minsize_changed();
protected:
enum class SortableVisbilityMode {
VISIBLE,
VISIBLE_IN_TREE,
IGNORE,
};
void queue_sort();
Control *as_sortable_control(Node *p_node) const;
Control *as_sortable_control(Node *p_node, SortableVisbilityMode p_visibility_mode = SortableVisbilityMode::VISIBLE_IN_TREE) const;
virtual void add_child_notify(Node *p_child) override;
virtual void move_child_notify(Node *p_child) override;

View File

@ -60,8 +60,8 @@ void GraphElement::_resort() {
Size2 GraphElement::get_minimum_size() const {
Size2 minsize;
for (int i = 0; i < get_child_count(); i++) {
Control *child = Object::cast_to<Control>(get_child(i));
if (!child || child->is_set_as_top_level()) {
Control *child = as_sortable_control(get_child(i), SortableVisbilityMode::IGNORE);
if (!child) {
continue;
}

View File

@ -130,8 +130,8 @@ bool GraphNode::_get(const StringName &p_name, Variant &r_ret) const {
void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const {
int idx = 0;
for (int i = 0; i < get_child_count(false); i++) {
Control *child = Object::cast_to<Control>(get_child(i, false));
if (!child || child->is_set_as_top_level()) {
Control *child = as_sortable_control(get_child(i, false), SortableVisbilityMode::IGNORE);
if (!child) {
continue;
}
@ -658,8 +658,8 @@ void GraphNode::_port_pos_update() {
int slot_index = 0;
for (int i = 0; i < get_child_count(false); i++) {
Control *child = Object::cast_to<Control>(get_child(i, false));
if (!child || child->is_set_as_top_level()) {
Control *child = as_sortable_control(get_child(i, false), SortableVisbilityMode::IGNORE);
if (!child) {
continue;
}

View File

@ -36,8 +36,8 @@ Size2 MarginContainer::get_minimum_size() const {
Size2 max;
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
if (!c || !c->is_visible() || c->is_set_as_top_level()) {
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
if (!c) {
continue;
}

View File

@ -35,7 +35,7 @@
Size2 PanelContainer::get_minimum_size() const {
Size2 ms;
for (int i = 0; i < get_child_count(); i++) {
Control *c = as_sortable_control(get_child(i));
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
if (!c) {
continue;
}

View File

@ -42,7 +42,7 @@ Size2 ScrollContainer::get_minimum_size() const {
largest_child_min_size = Size2();
for (int i = 0; i < get_child_count(); i++) {
Control *c = as_sortable_control(get_child(i));
Control *c = as_sortable_control(get_child(i), SortableVisbilityMode::VISIBLE);
if (!c) {
continue;
}

View File

@ -362,8 +362,8 @@ void TabContainer::_on_mouse_exited() {
Vector<Control *> TabContainer::_get_tab_controls() const {
Vector<Control *> controls;
for (int i = 0; i < get_child_count(); i++) {
Control *control = Object::cast_to<Control>(get_child(i));
if (!control || control->is_set_as_top_level() || control == tab_bar || children_removing.has(control)) {
Control *control = as_sortable_control(get_child(i), SortableVisbilityMode::IGNORE);
if (!control || control == tab_bar || children_removing.has(control)) {
continue;
}
@ -539,8 +539,8 @@ void TabContainer::add_child_notify(Node *p_child) {
return;
}
Control *c = Object::cast_to<Control>(p_child);
if (!c || c->is_set_as_top_level()) {
Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
if (!c) {
return;
}
c->hide();
@ -569,8 +569,8 @@ void TabContainer::move_child_notify(Node *p_child) {
return;
}
Control *c = Object::cast_to<Control>(p_child);
if (c && !c->is_set_as_top_level()) {
Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
if (c) {
tab_bar->move_tab(c->get_meta("_tab_index"), get_tab_idx_from_control(c));
}
@ -584,8 +584,8 @@ void TabContainer::remove_child_notify(Node *p_child) {
return;
}
Control *c = Object::cast_to<Control>(p_child);
if (!c || c->is_set_as_top_level()) {
Control *c = as_sortable_control(p_child, SortableVisbilityMode::IGNORE);
if (!c) {
return;
}