mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 05:01:05 +01:00 
			
		
		
		
	Tabs: Moved Tab List Popup to left-side to match docking button. Highlight selected tab. (#261, #351)
This commit is contained in:
		| @@ -5969,6 +5969,12 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | |||||||
|         tab_bar->ReorderRequestTabId = 0; |         tab_bar->ReorderRequestTabId = 0; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // Tab List Popup (will alter tab_bar->BarRect and therefore the available width!) | ||||||
|  |     const bool tab_list_popup_button = (tab_bar->Flags & ImGuiTabBarFlags_TabListPopupButton) != 0; | ||||||
|  |     if (tab_list_popup_button) | ||||||
|  |         if (ImGuiTabItem* tab_to_select = TabBarTabListPopupButton(tab_bar)) // NB: Will alter BarRect.Max.x! | ||||||
|  |             scroll_track_selected_tab_id = tab_bar->SelectedTabId = tab_to_select->ID; | ||||||
|  |  | ||||||
|     ImVector<ImGuiTabBarSortItem>& width_sort_buffer = g.TabSortByWidthBuffer; |     ImVector<ImGuiTabBarSortItem>& width_sort_buffer = g.TabSortByWidthBuffer; | ||||||
|     width_sort_buffer.resize(tab_bar->Tabs.Size); |     width_sort_buffer.resize(tab_bar->Tabs.Size); | ||||||
|  |  | ||||||
| @@ -6044,12 +6050,6 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | |||||||
|     tab_bar->OffsetMax = ImMax(offset_x - g.Style.ItemInnerSpacing.x, 0.0f); |     tab_bar->OffsetMax = ImMax(offset_x - g.Style.ItemInnerSpacing.x, 0.0f); | ||||||
|     tab_bar->OffsetNextTab = 0.0f; |     tab_bar->OffsetNextTab = 0.0f; | ||||||
|  |  | ||||||
|     // Tab List Popup |  | ||||||
|     const bool tab_list_popup_button = (tab_bar->Flags & ImGuiTabBarFlags_TabListPopupButton) != 0; |  | ||||||
|     if (tab_list_popup_button) |  | ||||||
|         if (ImGuiTabItem* tab_to_select = TabBarTabListPopupButton(tab_bar)) // NB: Will alter BarRect.Max.x! |  | ||||||
|             scroll_track_selected_tab_id = tab_bar->SelectedTabId = tab_to_select->ID; |  | ||||||
|  |  | ||||||
|     // Horizontal scrolling buttons |     // Horizontal scrolling buttons | ||||||
|     const bool scrolling_buttons = (tab_bar->OffsetMax > tab_bar->BarRect.GetWidth() && tab_bar->Tabs.Size > 1) && !(tab_bar->Flags & ImGuiTabBarFlags_NoTabListScrollingButtons) && (tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyScroll); |     const bool scrolling_buttons = (tab_bar->OffsetMax > tab_bar->BarRect.GetWidth() && tab_bar->Tabs.Size > 1) && !(tab_bar->Flags & ImGuiTabBarFlags_NoTabListScrollingButtons) && (tab_bar->Flags & ImGuiTabBarFlags_FittingPolicyScroll); | ||||||
|     if (scrolling_buttons) |     if (scrolling_buttons) | ||||||
| @@ -6225,18 +6225,17 @@ static ImGuiTabItem* ImGui::TabBarTabListPopupButton(ImGuiTabBar* tab_bar) | |||||||
|     ImGuiContext& g = *GImGui; |     ImGuiContext& g = *GImGui; | ||||||
|     ImGuiWindow* window = g.CurrentWindow; |     ImGuiWindow* window = g.CurrentWindow; | ||||||
|  |  | ||||||
|     const float tab_list_popup_button_width = g.FontSize + g.Style.FramePadding.y * 2.0f; |     // We use g.Style.FramePadding.y to match the square ArrowButton size | ||||||
|  |     const float tab_list_popup_button_width = g.FontSize + g.Style.FramePadding.y; | ||||||
|     const ImVec2 backup_cursor_pos = window->DC.CursorPos; |     const ImVec2 backup_cursor_pos = window->DC.CursorPos; | ||||||
|     tab_bar->BarRect.Max.x -= tab_list_popup_button_width; |     window->DC.CursorPos = ImVec2(tab_bar->BarRect.Min.x - g.Style.FramePadding.y, tab_bar->BarRect.Min.y); | ||||||
|     if (window->HasCloseButton) |     tab_bar->BarRect.Min.x += tab_list_popup_button_width; | ||||||
|         tab_bar->BarRect.Max.x += g.Style.ItemInnerSpacing.x; |  | ||||||
|     window->DC.CursorPos = ImVec2(tab_bar->BarRect.Max.x, tab_bar->BarRect.Min.y); |  | ||||||
|  |  | ||||||
|     ImVec4 arrow_col = g.Style.Colors[ImGuiCol_Text]; |     ImVec4 arrow_col = g.Style.Colors[ImGuiCol_Text]; | ||||||
|     arrow_col.w *= 0.5f; |     arrow_col.w *= 0.5f; | ||||||
|     PushStyleColor(ImGuiCol_Text, arrow_col); |     PushStyleColor(ImGuiCol_Text, arrow_col); | ||||||
|     PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); |     PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); | ||||||
|     bool open = BeginCombo("##v", NULL, ImGuiComboFlags_NoPreview | ImGuiComboFlags_PopupAlignLeft); |     bool open = BeginCombo("##v", NULL, ImGuiComboFlags_NoPreview); | ||||||
|     PopStyleColor(2); |     PopStyleColor(2); | ||||||
|  |  | ||||||
|     ImGuiTabItem* tab_to_select = NULL; |     ImGuiTabItem* tab_to_select = NULL; | ||||||
| @@ -6246,7 +6245,7 @@ static ImGuiTabItem* ImGui::TabBarTabListPopupButton(ImGuiTabBar* tab_bar) | |||||||
|         { |         { | ||||||
|             ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; |             ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; | ||||||
|             const char* tab_name = tab_bar->GetTabName(tab); |             const char* tab_name = tab_bar->GetTabName(tab); | ||||||
|             if (MenuItem(tab_name)) |             if (Selectable(tab_name, tab_bar->SelectedTabId == tab->ID)) | ||||||
|                 tab_to_select = tab; |                 tab_to_select = tab; | ||||||
|         } |         } | ||||||
|         EndCombo(); |         EndCombo(); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user