mirror of
https://github.com/Drezil/imgui.git
synced 2025-01-19 03:16:35 +00:00
TabBar: Recover if SelectedTabId doesn't exist anymore.
This commit is contained in:
parent
3e47978a80
commit
599d5f185c
@ -9525,7 +9525,6 @@ void ImGui::EndDragDropTarget()
|
|||||||
// TODO:
|
// TODO:
|
||||||
// A~ document root node resizing behavior incorrect
|
// A~ document root node resizing behavior incorrect
|
||||||
// A~ document root node retrieval of ID ?
|
// 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- 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
|
// 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)
|
// A~ Unreal style document system (requires low-level controls of dockspace serialization fork/copy/delete)
|
||||||
|
@ -5966,6 +5966,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
|
|||||||
// Compute ideal widths
|
// Compute ideal widths
|
||||||
float width_total_contents = 0.0f;
|
float width_total_contents = 0.0f;
|
||||||
ImGuiTabItem* most_recently_selected_tab = NULL;
|
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++)
|
for (int tab_n = 0; tab_n < tab_bar->Tabs.Size; tab_n++)
|
||||||
{
|
{
|
||||||
ImGuiTabItem* tab = &tab_bar->Tabs[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)
|
if (most_recently_selected_tab == NULL || most_recently_selected_tab->LastFrameSelected < tab->LastFrameSelected)
|
||||||
most_recently_selected_tab = tab;
|
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)
|
// 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,
|
// 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!
|
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;
|
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)
|
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;
|
scroll_track_selected_tab_id = tab_bar->SelectedTabId = most_recently_selected_tab->ID;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user