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

Save current tab in TabBar and TabContainer #83893

Merged
merged 1 commit into from
Oct 27, 2023
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
13 changes: 10 additions & 3 deletions scene/gui/tab_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ void TabBar::_shape(int p_tab) {

void TabBar::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (scroll_to_selected) {
ensure_tab_visible(current);
}
} break;

case NOTIFICATION_INTERNAL_PROCESS: {
Input *input = Input::get_singleton();

Expand Down Expand Up @@ -1745,7 +1751,10 @@ void TabBar::_bind_methods() {
ADD_SIGNAL(MethodInfo("tab_hovered", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("active_tab_rearranged", PropertyInfo(Variant::INT, "idx_to")));

ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab");
// "current_tab" property must come after "tab_count", otherwise the property isn't loaded correctly.
ADD_ARRAY_COUNT("Tabs", "tab_count", "set_tab_count", "get_tab_count", "tab_");

ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1"), "set_current_tab", "get_current_tab");
ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_alignment", "get_tab_alignment");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_tabs"), "set_clip_tabs", "get_clip_tabs");
ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_close_display_policy", PROPERTY_HINT_ENUM, "Show Never,Show Active Only,Show Always"), "set_tab_close_display_policy", "get_tab_close_display_policy");
Expand All @@ -1756,8 +1765,6 @@ void TabBar::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_to_selected"), "set_scroll_to_selected", "get_scroll_to_selected");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "select_with_rmb"), "set_select_with_rmb", "get_select_with_rmb");

ADD_ARRAY_COUNT("Tabs", "tab_count", "set_tab_count", "get_tab_count", "tab_");

BIND_ENUM_CONSTANT(ALIGNMENT_LEFT);
BIND_ENUM_CONSTANT(ALIGNMENT_CENTER);
BIND_ENUM_CONSTANT(ALIGNMENT_RIGHT);
Expand Down
13 changes: 12 additions & 1 deletion scene/gui/tab_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ void TabContainer::_notification(int p_what) {
}
} break;

case NOTIFICATION_POST_ENTER_TREE: {
if (setup_current_tab >= 0) {
set_current_tab(setup_current_tab);
setup_current_tab = -1;
}
} break;

case NOTIFICATION_READY:
case NOTIFICATION_RESIZED: {
_update_margins();
Expand Down Expand Up @@ -528,6 +535,10 @@ int TabContainer::get_tab_count() const {
}

void TabContainer::set_current_tab(int p_current) {
if (!is_inside_tree()) {
setup_current_tab = p_current;
return;
}
tab_bar->set_current_tab(p_current);
}

Expand Down Expand Up @@ -912,7 +923,7 @@ void TabContainer::_bind_methods() {
ADD_SIGNAL(MethodInfo("pre_popup_pressed"));

ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_alignment", "get_tab_alignment");
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab");
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1"), "set_current_tab", "get_current_tab");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_tabs"), "set_clip_tabs", "get_clip_tabs");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front");
Expand Down
1 change: 1 addition & 0 deletions scene/gui/tab_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TabContainer : public Container {
bool theme_changing = false;
Vector<Control *> children_removing;
bool drag_to_rearrange_enabled = false;
int setup_current_tab = -1;

struct ThemeCache {
int side_margin = 0;
Expand Down
Loading