Skip to content

Commit

Permalink
Add visibilty mode to as_sortable_control()
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Jun 2, 2024
1 parent 705b7a0 commit a15564f
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
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
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

0 comments on commit a15564f

Please sign in to comment.