Improve get_tab_control() in TabContainer
This commit is contained in:
parent
2327a82357
commit
8b5d3c7bac
2 changed files with 44 additions and 18 deletions
|
|
@ -51,6 +51,14 @@ int TabContainer::_get_tab_height() const {
|
|||
return height;
|
||||
}
|
||||
|
||||
Control *TabContainer::_as_tab_control(Node *p_child) const {
|
||||
Control *control = as_sortable_control(p_child, SortableVisibilityMode::IGNORE);
|
||||
if (!control || control == internal_container || children_removing.has(control)) {
|
||||
return nullptr;
|
||||
}
|
||||
return control;
|
||||
}
|
||||
|
||||
void TabContainer::_get_property_list(List<PropertyInfo> *p_list) const {
|
||||
List<PropertyInfo> properties;
|
||||
property_helper.get_property_list(&properties);
|
||||
|
|
@ -104,8 +112,8 @@ void TabContainer::_notification(int p_what) {
|
|||
if (child_node->is_part_of_edited_scene()) {
|
||||
continue;
|
||||
}
|
||||
Control *control = as_sortable_control(child_node, SortableVisibilityMode::IGNORE);
|
||||
if (!control || control == internal_container || children_removing.has(control)) {
|
||||
Control *control = _as_tab_control(child_node);
|
||||
if (!control) {
|
||||
DisplayServer::get_singleton()->accessibility_update_add_child(ae, child_node->get_accessibility_element());
|
||||
} else {
|
||||
if (!tab_panels.has(child_node)) {
|
||||
|
|
@ -361,15 +369,14 @@ void TabContainer::_update_margins() {
|
|||
|
||||
Vector<Control *> TabContainer::_get_tab_controls() const {
|
||||
Vector<Control *> controls;
|
||||
for (int i = 0; i < get_child_count(); i++) {
|
||||
Control *control = as_sortable_control(get_child(i), SortableVisibilityMode::IGNORE);
|
||||
if (!control || control == internal_container || children_removing.has(control)) {
|
||||
continue;
|
||||
ERR_THREAD_GUARD_V(controls);
|
||||
|
||||
for (Node *child : iterate_children()) {
|
||||
Control *control = _as_tab_control(child);
|
||||
if (control) {
|
||||
controls.push_back(control);
|
||||
}
|
||||
|
||||
controls.push_back(control);
|
||||
}
|
||||
|
||||
return controls;
|
||||
}
|
||||
|
||||
|
|
@ -694,12 +701,24 @@ bool TabContainer::get_deselect_enabled() const {
|
|||
}
|
||||
|
||||
Control *TabContainer::get_tab_control(int p_idx) const {
|
||||
Vector<Control *> controls = _get_tab_controls();
|
||||
if (p_idx >= 0 && p_idx < controls.size()) {
|
||||
return controls[p_idx];
|
||||
} else {
|
||||
if (p_idx < 0) {
|
||||
return nullptr;
|
||||
}
|
||||
ERR_THREAD_GUARD_V(nullptr);
|
||||
|
||||
for (Node *child : iterate_children()) {
|
||||
Control *control = _as_tab_control(child);
|
||||
if (!control) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p_idx > 0) {
|
||||
p_idx--;
|
||||
} else {
|
||||
return control;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Control *TabContainer::get_current_tab_control() const {
|
||||
|
|
@ -713,14 +732,20 @@ int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const {
|
|||
int TabContainer::get_tab_idx_from_control(Control *p_child) const {
|
||||
ERR_FAIL_NULL_V(p_child, -1);
|
||||
ERR_FAIL_COND_V(p_child->get_parent() != this, -1);
|
||||
ERR_THREAD_GUARD_V(-1);
|
||||
|
||||
Vector<Control *> controls = _get_tab_controls();
|
||||
for (int i = 0; i < controls.size(); i++) {
|
||||
if (controls[i] == p_child) {
|
||||
return i;
|
||||
int idx = 0;
|
||||
for (Node *child : iterate_children()) {
|
||||
Control *control = _as_tab_control(child);
|
||||
if (!control) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (control == p_child) {
|
||||
return idx;
|
||||
}
|
||||
idx++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -124,6 +124,7 @@ private:
|
|||
HashMap<Node *, RID> tab_panels;
|
||||
|
||||
int _get_tab_height() const;
|
||||
Control *_as_tab_control(Node *p_child) const;
|
||||
Vector<Control *> _get_tab_controls() const;
|
||||
void _on_theme_changed();
|
||||
void _repaint();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue