TabBar save current tab
This commit is contained in:
parent
09946f79bd
commit
8985a46bdd
3 changed files with 23 additions and 4 deletions
|
@ -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();
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue