From 599d5f185cfbcfee316ce7ac90c9481a8d0d6da8 Mon Sep 17 00:00:00 2001 From: omar Date: Fri, 21 Sep 2018 11:02:03 +0200 Subject: [PATCH] TabBar: Recover if SelectedTabId doesn't exist anymore. --- imgui.cpp | 1 - imgui_widgets.cpp | 7 ++++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index eefb6c51..d83f2fe9 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -9525,7 +9525,6 @@ void ImGui::EndDragDropTarget() // TODO: // A~ document root node resizing behavior incorrect // A~ document root node retrieval of ID ? -// A- fix when SelectedTab doesn't exist (easy to repro/fix with .ini mod, but would be nice to also find real repro) // B- full rebuild loses viewport of floating dock nodes // B- dock node inside its own viewports creates 1 temporary viewport per window on startup before ditching them // A~ Unreal style document system (requires low-level controls of dockspace serialization fork/copy/delete) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 3a1415c5..aa630591 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -5966,6 +5966,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) // Compute ideal widths float width_total_contents = 0.0f; ImGuiTabItem* most_recently_selected_tab = NULL; + bool found_selected_tab_id = false; for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++) { ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; @@ -5973,6 +5974,8 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) if (most_recently_selected_tab == NULL || most_recently_selected_tab->LastFrameSelected < tab->LastFrameSelected) most_recently_selected_tab = tab; + if (tab->ID == tab_bar->SelectedTabId) + found_selected_tab_id = true; // Refresh tab width immediately if we can (for manual tab bar, WidthContent will lag by one frame which is mostly noticeable when changing style.FramePadding.x) // Additionally, when using TabBarAddTab() to manipulate tab bar order we occasionally insert new tabs that don't have a width yet, @@ -6043,7 +6046,9 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) if (ImGuiTabItem* tab_to_select = TabBarScrollingButtons(tab_bar)) // NB: Will alter BarRect.Max.x! scroll_track_selected_tab_id = tab_bar->SelectedTabId = tab_to_select->ID; - // If we have lost the selected tab, select the next most recently active one. + // If we have lost the selected tab, select the next most recently active one + if (found_selected_tab_id == false) + tab_bar->SelectedTabId = 0; if (tab_bar->SelectedTabId == 0 && tab_bar->NextSelectedTabId == 0 && most_recently_selected_tab != NULL) scroll_track_selected_tab_id = tab_bar->SelectedTabId = most_recently_selected_tab->ID;