Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visibility mode to as_sortable_control() #92664

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scene/gui/box_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 8 additions & 2 deletions scene/gui/container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion scene/gui/container.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions scene/gui/graph_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
8 changes: 4 additions & 4 deletions scene/gui/graph_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions scene/gui/margin_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion scene/gui/panel_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion scene/gui/scroll_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions scene/gui/tab_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}

Expand All @@ -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;
}

Expand Down
Loading