mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 03:58:47 +02:00
Tab Bar: Allow calling SetTabItemClosed() after a tab has been submitted (will process next frame).
+ larger combo height on TabBarTabListPopupButton()
This commit is contained in:
@ -6709,15 +6709,17 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
|
||||
ImGuiContext& g = *GImGui;
|
||||
tab_bar->WantLayout = false;
|
||||
|
||||
// Garbage collect
|
||||
// Garbage collect by compacting list
|
||||
int tab_dst_n = 0;
|
||||
for (int tab_src_n = 0; tab_src_n < tab_bar->Tabs.Size; tab_src_n++)
|
||||
{
|
||||
ImGuiTabItem* tab = &tab_bar->Tabs[tab_src_n];
|
||||
if (tab->LastFrameVisible < tab_bar->PrevFrameVisible)
|
||||
if (tab->LastFrameVisible < tab_bar->PrevFrameVisible || tab->WantClose)
|
||||
{
|
||||
if (tab->ID == tab_bar->SelectedTabId)
|
||||
tab_bar->SelectedTabId = 0;
|
||||
// Remove tab
|
||||
if (tab_bar->VisibleTabId == tab->ID) { tab_bar->VisibleTabId = 0; }
|
||||
if (tab_bar->SelectedTabId == tab->ID) { tab_bar->SelectedTabId = 0; }
|
||||
if (tab_bar->NextSelectedTabId == tab->ID) { tab_bar->NextSelectedTabId = 0; }
|
||||
continue;
|
||||
}
|
||||
if (tab_dst_n != tab_src_n)
|
||||
@ -7039,7 +7041,7 @@ static ImGuiTabItem* ImGui::TabBarTabListPopupButton(ImGuiTabBar* tab_bar)
|
||||
arrow_col.w *= 0.5f;
|
||||
PushStyleColor(ImGuiCol_Text, arrow_col);
|
||||
PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
|
||||
bool open = BeginCombo("##v", NULL, ImGuiComboFlags_NoPreview);
|
||||
bool open = BeginCombo("##v", NULL, ImGuiComboFlags_NoPreview | ImGuiComboFlags_HeightLargest);
|
||||
PopStyleColor(2);
|
||||
|
||||
ImGuiTabItem* tab_to_select = NULL;
|
||||
@ -7167,7 +7169,7 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
|
||||
tab->Flags = flags;
|
||||
|
||||
// Append name with zero-terminator
|
||||
tab->NameOffset = tab_bar->TabsNames.size();
|
||||
tab->NameOffset = (ImS16)tab_bar->TabsNames.size();
|
||||
tab_bar->TabsNames.append(label, label + strlen(label) + 1);
|
||||
|
||||
// If we are not reorderable, always reset offset based on submission order.
|
||||
@ -7316,9 +7318,8 @@ bool ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open,
|
||||
}
|
||||
|
||||
// [Public] This is call is 100% optional but it allows to remove some one-frame glitches when a tab has been unexpectedly removed.
|
||||
// To use it to need to call the function SetTabItemClosed() after BeginTabBar() and before any call to BeginTabItem().
|
||||
// To use it to need to call the function SetTabItemClosed() between BeginTabBar() and EndTabBar().
|
||||
// Tabs closed by the close button will automatically be flagged to avoid this issue.
|
||||
// FIXME: We should aim to support calling SetTabItemClosed() after the tab submission (for next frame)
|
||||
void ImGui::SetTabItemClosed(const char* label)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -7326,9 +7327,9 @@ void ImGui::SetTabItemClosed(const char* label)
|
||||
if (is_within_manual_tab_bar)
|
||||
{
|
||||
ImGuiTabBar* tab_bar = g.CurrentTabBar;
|
||||
IM_ASSERT(tab_bar->WantLayout); // Needs to be called AFTER BeginTabBar() and BEFORE the first call to BeginTabItem()
|
||||
ImGuiID tab_id = TabBarCalcTabID(tab_bar, label);
|
||||
TabBarRemoveTab(tab_bar, tab_id);
|
||||
if (ImGuiTabItem* tab = TabBarFindTabByID(tab_bar, tab_id))
|
||||
tab->WantClose = true; // Will be processed by next call to TabBarLayout()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user