mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-25 21:17:01 +00:00
Tab Bar: Moved up TabBarScrollingButtons function call. (#3291)
This commit is contained in:
parent
205874f5b1
commit
99f69eb185
@ -7082,16 +7082,22 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
|
|||||||
for (int section_n = 0; section_n < 3; section_n++)
|
for (int section_n = 0; section_n < 3; section_n++)
|
||||||
tab_bar->WidthAllTabsIdeal += sections[section_n].Width + sections[section_n].Spacing;
|
tab_bar->WidthAllTabsIdeal += sections[section_n].Width + sections[section_n].Spacing;
|
||||||
|
|
||||||
// We want to know here if we'll need the scrolling buttons, to adjust available width with resizable leading/trailing
|
// Horizontal scrolling buttons
|
||||||
bool scrolling_buttons = (tab_bar->WidthAllTabsIdeal > tab_bar->BarRect.GetWidth() && tab_bar->Tabs.Size > 1) && !(tab_bar->Flags & ImGuiTabBarFlags_NoTabListScrollingButtons) && (tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyScroll);
|
// (Note that TabBarScrollButtons() will alter BarRect.Max.x)
|
||||||
float scrolling_buttons_width = scrolling_buttons ? GetTabBarScrollingButtonSize().x * 2.0f : 0.0f;
|
if ((tab_bar->WidthAllTabsIdeal > tab_bar->BarRect.GetWidth() && tab_bar->Tabs.Size > 1) && !(tab_bar->Flags & ImGuiTabBarFlags_NoTabListScrollingButtons) && (tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyScroll))
|
||||||
|
if (ImGuiTabItem* scroll_track_selected_tab = TabBarScrollingButtons(tab_bar))
|
||||||
|
{
|
||||||
|
scroll_track_selected_tab_id = scroll_track_selected_tab->ID;
|
||||||
|
if (!(scroll_track_selected_tab->Flags & ImGuiTabItemFlags_Button))
|
||||||
|
tab_bar->SelectedTabId = scroll_track_selected_tab_id;
|
||||||
|
}
|
||||||
|
|
||||||
// Compute width
|
// Compute width
|
||||||
// FIXME: This is a mess, couldn't TabBarScrollingButtons() just be called earlier?
|
// FIXME: This is a mess
|
||||||
bool central_section_is_visible = (sections[0].WidthWithSpacing() + sections[2].WidthWithSpacing()) < (tab_bar->BarRect.GetWidth() - scrolling_buttons_width);
|
bool central_section_is_visible = (sections[0].WidthWithSpacing() + sections[2].WidthWithSpacing()) < tab_bar->BarRect.GetWidth();
|
||||||
float width_excess = central_section_is_visible
|
float width_excess = central_section_is_visible
|
||||||
? ImMax(sections[1].WidthWithSpacing() - (tab_bar->BarRect.GetWidth() - sections[0].WidthWithSpacing() - sections[2].WidthWithSpacing()), 0.0f)
|
? ImMax(sections[1].WidthWithSpacing() - (tab_bar->BarRect.GetWidth() - sections[0].WidthWithSpacing() - sections[2].WidthWithSpacing()), 0.0f)
|
||||||
: (sections[0].WidthWithSpacing() + sections[2].WidthWithSpacing()) - (tab_bar->BarRect.GetWidth() - scrolling_buttons_width);
|
: (sections[0].WidthWithSpacing() + sections[2].WidthWithSpacing()) - tab_bar->BarRect.GetWidth();
|
||||||
|
|
||||||
if (width_excess > 0.0f && (tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyResizeDown || !central_section_is_visible))
|
if (width_excess > 0.0f && (tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyResizeDown || !central_section_is_visible))
|
||||||
{
|
{
|
||||||
@ -7126,7 +7132,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
|
|||||||
// FIXME: The +1.0f is in TabBarScrollingButtons()
|
// FIXME: The +1.0f is in TabBarScrollingButtons()
|
||||||
ImGuiTabBarSection* section = §ions[section_n];
|
ImGuiTabBarSection* section = §ions[section_n];
|
||||||
if (section_n == 2)
|
if (section_n == 2)
|
||||||
next_tab_offset = ImMin(tab_bar->BarRect.GetWidth() - section->Width - (scrolling_buttons ? scrolling_buttons_width + 1.0f : 0.0f), next_tab_offset);
|
next_tab_offset = ImMin(tab_bar->BarRect.GetWidth() - section->Width, next_tab_offset);
|
||||||
|
|
||||||
for (int tab_n = 0; tab_n < section->TabCount; tab_n++)
|
for (int tab_n = 0; tab_n < section->TabCount; tab_n++)
|
||||||
{
|
{
|
||||||
@ -7138,15 +7144,6 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar)
|
|||||||
next_tab_offset += section->Spacing;
|
next_tab_offset += section->Spacing;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Horizontal scrolling buttons
|
|
||||||
if (scrolling_buttons)
|
|
||||||
if (ImGuiTabItem* scroll_track_selected_tab = TabBarScrollingButtons(tab_bar)) // NB: Will alter BarRect.Max.x
|
|
||||||
{
|
|
||||||
scroll_track_selected_tab_id = scroll_track_selected_tab->ID;
|
|
||||||
if (!(scroll_track_selected_tab->Flags & ImGuiTabItemFlags_Button))
|
|
||||||
tab_bar->SelectedTabId = scroll_track_selected_tab_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)
|
if (found_selected_tab_id == false)
|
||||||
tab_bar->SelectedTabId = 0;
|
tab_bar->SelectedTabId = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user