Merge pull request #88477 from jsjtxietian/tab-down

Tweak property order in the inspector for TabBar
This commit is contained in:
Rémi Verschelde 2024-02-19 00:08:44 +01:00
commit 3b649d208f
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 16 additions and 3 deletions

View File

@ -635,6 +635,13 @@ void TabBar::set_tab_count(int p_count) {
}
}
if (!initialized) {
if (queued_current != current) {
current = queued_current;
}
initialized = true;
}
queue_redraw();
update_minimum_size();
notify_property_list_changed();
@ -649,6 +656,10 @@ void TabBar::set_current_tab(int p_current) {
// An index of -1 is only valid if deselecting is enabled or there are no valid tabs.
ERR_FAIL_COND_MSG(!_can_deselect(), "Cannot deselect tabs, deselection is not enabled.");
} else {
if (!initialized && p_current >= get_tab_count()) {
queued_current = p_current;
return;
}
ERR_FAIL_INDEX(p_current, get_tab_count());
}
@ -1825,9 +1836,6 @@ void TabBar::_bind_methods() {
ADD_SIGNAL(MethodInfo("tab_hovered", PropertyInfo(Variant::INT, "tab")));
ADD_SIGNAL(MethodInfo("active_tab_rearranged", PropertyInfo(Variant::INT, "idx_to")));
// "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");
@ -1840,6 +1848,8 @@ void TabBar::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "select_with_rmb"), "set_select_with_rmb", "get_select_with_rmb");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_enabled"), "set_deselect_enabled", "get_deselect_enabled");
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);

View File

@ -108,6 +108,9 @@ private:
bool scroll_to_selected = true;
int tabs_rearrange_group = -1;
bool initialized = false;
int queued_current = -1;
const float DEFAULT_GAMEPAD_EVENT_DELAY_MS = 0.5;
const float GAMEPAD_EVENT_REPEAT_RATE_MS = 1.0 / 20;
float gamepad_event_delay_ms = DEFAULT_GAMEPAD_EVENT_DELAY_MS;