mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 07:53:26 +00:00
Merge pull request #108255 from thygrrr/tab-container-deselect-enable-fix
Fix: TabBar/TabContainer can't start with all tabs deselected
This commit is contained in:
commit
4d1f26e1fd
2 changed files with 24 additions and 6 deletions
|
@ -1266,7 +1266,7 @@ void TabBar::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) {
|
|||
queue_redraw();
|
||||
update_minimum_size();
|
||||
|
||||
if (tabs.size() == 1) {
|
||||
if (!deselect_enabled && tabs.size() == 1) {
|
||||
if (is_inside_tree()) {
|
||||
set_current_tab(0);
|
||||
} else {
|
||||
|
|
|
@ -51,7 +51,8 @@ TEST_CASE("[SceneTree][TabBar] tab operations") {
|
|||
CHECK(tab_bar->get_previous_tab() == -1);
|
||||
}
|
||||
|
||||
SUBCASE("[TabBar] add tabs") {
|
||||
SUBCASE("[TabBar] add tabs disallowing deselection") {
|
||||
tab_bar->set_deselect_enabled(false);
|
||||
tab_bar->add_tab("tab0");
|
||||
CHECK(tab_bar->get_tab_count() == 1);
|
||||
CHECK(tab_bar->get_current_tab() == 0);
|
||||
|
@ -92,6 +93,23 @@ TEST_CASE("[SceneTree][TabBar] tab operations") {
|
|||
CHECK_FALSE(tab_bar->is_tab_hidden(2));
|
||||
}
|
||||
|
||||
SUBCASE("[TabBar] add tabs allowing deselection") {
|
||||
tab_bar->set_deselect_enabled(true);
|
||||
tab_bar->add_tab("tab0");
|
||||
CHECK(tab_bar->get_tab_count() == 1);
|
||||
CHECK(tab_bar->get_current_tab() == -1);
|
||||
CHECK(tab_bar->get_previous_tab() == -1);
|
||||
SIGNAL_CHECK_FALSE("tab_selected");
|
||||
SIGNAL_CHECK_FALSE("tab_changed");
|
||||
|
||||
tab_bar->add_tab("tab1");
|
||||
CHECK(tab_bar->get_tab_count() == 2);
|
||||
CHECK(tab_bar->get_current_tab() == -1);
|
||||
CHECK(tab_bar->get_previous_tab() == -1);
|
||||
SIGNAL_CHECK_FALSE("tab_selected");
|
||||
SIGNAL_CHECK_FALSE("tab_changed");
|
||||
}
|
||||
|
||||
SUBCASE("[TabBar] set tab count") {
|
||||
// Adds multiple tabs at once.
|
||||
tab_bar->set_tab_count(3);
|
||||
|
@ -320,7 +338,7 @@ TEST_CASE("[SceneTree][TabBar] tab operations") {
|
|||
SIGNAL_CHECK("tab_selected", { { -1 } });
|
||||
SIGNAL_CHECK("tab_changed", { { -1 } });
|
||||
|
||||
// Adding a tab will still set the current tab to 0.
|
||||
// Adding first tab will NOT change the current tab. (stays deselected)
|
||||
tab_bar->clear_tabs();
|
||||
CHECK(tab_bar->get_current_tab() == -1);
|
||||
CHECK(tab_bar->get_previous_tab() == -1);
|
||||
|
@ -329,10 +347,10 @@ TEST_CASE("[SceneTree][TabBar] tab operations") {
|
|||
tab_bar->add_tab("tab1");
|
||||
tab_bar->add_tab("tab2");
|
||||
CHECK(tab_bar->get_tab_count() == 3);
|
||||
CHECK(tab_bar->get_current_tab() == 0);
|
||||
CHECK(tab_bar->get_current_tab() == -1);
|
||||
CHECK(tab_bar->get_previous_tab() == -1);
|
||||
SIGNAL_CHECK("tab_selected", { { 0 } });
|
||||
SIGNAL_CHECK("tab_changed", { { 0 } });
|
||||
SIGNAL_CHECK_FALSE("tab_selected");
|
||||
SIGNAL_CHECK_FALSE("tab_changed");
|
||||
|
||||
tab_bar->set_current_tab(-1);
|
||||
SIGNAL_DISCARD("tab_selected");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue