mirror of
				https://github.com/Drezil/imgui.git
				synced 2025-10-31 13:11:05 +01:00 
			
		
		
		
	Internals: TabBar renaming and shuffling stuff around.
+ sneaking a readme change
This commit is contained in:
		| @@ -115,7 +115,7 @@ Officially maintained bindings (in repository): | |||||||
|  |  | ||||||
| Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): | Third-party bindings (see [Bindings](https://github.com/ocornut/imgui/wiki/Bindings/) page): | ||||||
| - Languages: C, C# and: Beef, ChaiScript, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Kotlin, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... | - Languages: C, C# and: Beef, ChaiScript, D, Go, Haskell, Haxe/hxcpp, Java, JavaScript, Julia, Kotlin, Lua, Odin, Pascal, PureBasic, Python, Ruby, Rust, Swift... | ||||||
| - Frameworks: AGS/Adventure Game Studio, Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/Game Maker Studio2, Godot, GTK3+OpenGL3, Irrlicht Engine, LÖVE+LUA, Magnum, NanoRT, Nim Game Lib, Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, Photoshop, px_render, Qt/QtDirect3D, SFML, Sokol, Unity, Unreal Engine 4, vtk, Win32 GDI, WxWidgets. | - Frameworks: AGS/Adventure Game Studio, Amethyst, bsf, Cinder, Cocos2d-x, Diligent Engine, Flexium, GML/Game Maker Studio2, Godot, GTK3+OpenGL3, Irrlicht Engine, LÖVE+LUA, Magnum, NanoRT, nCine, Nim Game Lib, Ogre, openFrameworks, OSG/OpenSceneGraph, Orx, Photoshop, px_render, Qt/QtDirect3D, SFML, Sokol, Unity, Unreal Engine 4, vtk, Win32 GDI, WxWidgets. | ||||||
| - Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. | - Note that C bindings ([cimgui](https://github.com/cimgui/cimgui)) are auto-generated, you can use its json/lua output to generate bindings for other languages. | ||||||
|  |  | ||||||
| Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. | Also see [Wiki](https://github.com/ocornut/imgui/wiki) for more links and ideas. | ||||||
|   | |||||||
| @@ -10504,8 +10504,8 @@ void ImGui::ShowMetricsWindow(bool* p_open) | |||||||
|                 { |                 { | ||||||
|                     const ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; |                     const ImGuiTabItem* tab = &tab_bar->Tabs[tab_n]; | ||||||
|                     ImGui::PushID(tab); |                     ImGui::PushID(tab); | ||||||
|                     if (ImGui::SmallButton("<")) { TabBarQueueChangeTabOrder(tab_bar, tab, -1); } ImGui::SameLine(0, 2); |                     if (ImGui::SmallButton("<")) { TabBarQueueReorder(tab_bar, tab, -1); } ImGui::SameLine(0, 2); | ||||||
|                     if (ImGui::SmallButton(">")) { TabBarQueueChangeTabOrder(tab_bar, tab, +1); } ImGui::SameLine(); |                     if (ImGui::SmallButton(">")) { TabBarQueueReorder(tab_bar, tab, +1); } ImGui::SameLine(); | ||||||
|                     ImGui::Text("%02d%c Tab 0x%08X '%s'", tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, (tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : ""); |                     ImGui::Text("%02d%c Tab 0x%08X '%s'", tab_n, (tab->ID == tab_bar->SelectedTabId) ? '*' : ' ', tab->ID, (tab->NameOffset != -1) ? tab_bar->GetTabName(tab) : ""); | ||||||
|                     ImGui::PopID(); |                     ImGui::PopID(); | ||||||
|                 } |                 } | ||||||
|   | |||||||
| @@ -1731,8 +1731,8 @@ struct ImGuiTabBar | |||||||
|     int                 PrevFrameVisible; |     int                 PrevFrameVisible; | ||||||
|     ImRect              BarRect; |     ImRect              BarRect; | ||||||
|     float               LastTabContentHeight;   // Record the height of contents submitted below the tab bar |     float               LastTabContentHeight;   // Record the height of contents submitted below the tab bar | ||||||
|     float               OffsetMax;              // Distance from BarRect.Min.x, locked during layout |     float               WidthAllTabs;           // Actual width of all tabs (locked during layout) | ||||||
|     float               OffsetMaxIdeal;         // Ideal offset if all tabs were visible and not clipped |     float               WidthAllTabsIdeal;      // Ideal width if all tabs were visible and not clipped | ||||||
|     float               OffsetNextTab;          // Distance from BarRect.Min.x, incremented with each BeginTabItem() call, not used if ImGuiTabBarFlags_Reorderable if set. |     float               OffsetNextTab;          // Distance from BarRect.Min.x, incremented with each BeginTabItem() call, not used if ImGuiTabBarFlags_Reorderable if set. | ||||||
|     float               ScrollingAnim; |     float               ScrollingAnim; | ||||||
|     float               ScrollingTarget; |     float               ScrollingTarget; | ||||||
| @@ -1931,7 +1931,8 @@ namespace ImGui | |||||||
|     IMGUI_API ImGuiTabItem* TabBarFindTabByID(ImGuiTabBar* tab_bar, ImGuiID tab_id); |     IMGUI_API ImGuiTabItem* TabBarFindTabByID(ImGuiTabBar* tab_bar, ImGuiID tab_id); | ||||||
|     IMGUI_API void          TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id); |     IMGUI_API void          TabBarRemoveTab(ImGuiTabBar* tab_bar, ImGuiID tab_id); | ||||||
|     IMGUI_API void          TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab); |     IMGUI_API void          TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab); | ||||||
|     IMGUI_API void          TabBarQueueChangeTabOrder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int dir); |     IMGUI_API void          TabBarQueueReorder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int dir); | ||||||
|  |     IMGUI_API bool          TabBarProcessReorder(ImGuiTabBar* tab_bar); | ||||||
|     IMGUI_API bool          TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags); |     IMGUI_API bool          TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, ImGuiTabItemFlags flags); | ||||||
|     IMGUI_API ImVec2        TabItemCalcSize(const char* label, bool has_close_button); |     IMGUI_API ImVec2        TabItemCalcSize(const char* label, bool has_close_button); | ||||||
|     IMGUI_API void          TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col); |     IMGUI_API void          TabItemBackground(ImDrawList* draw_list, const ImRect& bb, ImGuiTabItemFlags flags, ImU32 col); | ||||||
|   | |||||||
| @@ -6761,7 +6761,7 @@ bool ImGui::MenuItem(const char* label, const char* shortcut, bool* p_selected, | |||||||
| // - TabBarFindTabById() [Internal] | // - TabBarFindTabById() [Internal] | ||||||
| // - TabBarRemoveTab() [Internal] | // - TabBarRemoveTab() [Internal] | ||||||
| // - TabBarCloseTab() [Internal] | // - TabBarCloseTab() [Internal] | ||||||
| // - TabBarScrollClamp()v | // - TabBarScrollClamp() [Internal] | ||||||
| // - TabBarScrollToTab() [Internal] | // - TabBarScrollToTab() [Internal] | ||||||
| // - TabBarQueueChangeTabOrder() [Internal] | // - TabBarQueueChangeTabOrder() [Internal] | ||||||
| // - TabBarScrollingButtons() [Internal] | // - TabBarScrollingButtons() [Internal] | ||||||
| @@ -6785,7 +6785,7 @@ ImGuiTabBar::ImGuiTabBar() | |||||||
|     SelectedTabId = NextSelectedTabId = VisibleTabId = 0; |     SelectedTabId = NextSelectedTabId = VisibleTabId = 0; | ||||||
|     CurrFrameVisible = PrevFrameVisible = -1; |     CurrFrameVisible = PrevFrameVisible = -1; | ||||||
|     LastTabContentHeight = 0.0f; |     LastTabContentHeight = 0.0f; | ||||||
|     OffsetMax = OffsetMaxIdeal = OffsetNextTab = 0.0f; |     WidthAllTabs = WidthAllTabsIdeal = OffsetNextTab = 0.0f; | ||||||
|     ScrollingAnim = ScrollingTarget = ScrollingTargetDistToVisibility = ScrollingSpeed = 0.0f; |     ScrollingAnim = ScrollingTarget = ScrollingTargetDistToVisibility = ScrollingSpeed = 0.0f; | ||||||
|     Flags = ImGuiTabBarFlags_None; |     Flags = ImGuiTabBarFlags_None; | ||||||
|     ReorderRequestTabId = 0; |     ReorderRequestTabId = 0; | ||||||
| @@ -6951,23 +6951,9 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | |||||||
|     // Process order change request (we could probably process it when requested but it's just saner to do it in a single spot). |     // Process order change request (we could probably process it when requested but it's just saner to do it in a single spot). | ||||||
|     if (tab_bar->ReorderRequestTabId != 0) |     if (tab_bar->ReorderRequestTabId != 0) | ||||||
|     { |     { | ||||||
|         if (ImGuiTabItem* tab1 = TabBarFindTabByID(tab_bar, tab_bar->ReorderRequestTabId)) |         if (TabBarProcessReorder(tab_bar)) | ||||||
|         { |             if (tab_bar->ReorderRequestTabId == tab_bar->SelectedTabId) | ||||||
|             //IM_ASSERT(tab_bar->Flags & ImGuiTabBarFlags_Reorderable); // <- this may happen when using debug tools |                 scroll_track_selected_tab_id = tab_bar->ReorderRequestTabId; | ||||||
|             int tab2_order = tab_bar->GetTabOrder(tab1) + tab_bar->ReorderRequestDir; |  | ||||||
|             if (tab2_order >= 0 && tab2_order < tab_bar->Tabs.Size) |  | ||||||
|             { |  | ||||||
|                 ImGuiTabItem* tab2 = &tab_bar->Tabs[tab2_order]; |  | ||||||
|                 ImGuiTabItem item_tmp = *tab1; |  | ||||||
|                 *tab1 = *tab2; |  | ||||||
|                 *tab2 = item_tmp; |  | ||||||
|                 if (tab2->ID == tab_bar->SelectedTabId) |  | ||||||
|                     scroll_track_selected_tab_id = tab2->ID; |  | ||||||
|                 tab1 = tab2 = NULL; |  | ||||||
|             } |  | ||||||
|             if (tab_bar->Flags & ImGuiTabBarFlags_SaveSettings) |  | ||||||
|                 MarkIniSettingsDirty(); |  | ||||||
|         } |  | ||||||
|         tab_bar->ReorderRequestTabId = 0; |         tab_bar->ReorderRequestTabId = 0; | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -7041,11 +7027,11 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | |||||||
|         offset_x += tab->Width + g.Style.ItemInnerSpacing.x; |         offset_x += tab->Width + g.Style.ItemInnerSpacing.x; | ||||||
|         offset_x_ideal += tab->ContentWidth + g.Style.ItemInnerSpacing.x; |         offset_x_ideal += tab->ContentWidth + g.Style.ItemInnerSpacing.x; | ||||||
|     } |     } | ||||||
|     tab_bar->OffsetMax = ImMax(offset_x - g.Style.ItemInnerSpacing.x, 0.0f); |     tab_bar->WidthAllTabs = ImMax(offset_x - g.Style.ItemInnerSpacing.x, 0.0f); | ||||||
|     tab_bar->OffsetMaxIdeal = ImMax(offset_x_ideal - g.Style.ItemInnerSpacing.x, 0.0f); |     tab_bar->WidthAllTabsIdeal = ImMax(offset_x_ideal - g.Style.ItemInnerSpacing.x, 0.0f); | ||||||
|  |  | ||||||
|     // 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->WidthAllTabs > 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) | ||||||
|         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; | ||||||
| @@ -7087,7 +7073,7 @@ static void ImGui::TabBarLayout(ImGuiTabBar* tab_bar) | |||||||
|     // Actual layout in host window (we don't do it in BeginTabBar() so as not to waste an extra frame) |     // Actual layout in host window (we don't do it in BeginTabBar() so as not to waste an extra frame) | ||||||
|     ImGuiWindow* window = g.CurrentWindow; |     ImGuiWindow* window = g.CurrentWindow; | ||||||
|     window->DC.CursorPos = tab_bar->BarRect.Min; |     window->DC.CursorPos = tab_bar->BarRect.Min; | ||||||
|     ItemSize(ImVec2(tab_bar->OffsetMaxIdeal, tab_bar->BarRect.GetHeight()), tab_bar->FramePadding.y); |     ItemSize(ImVec2(tab_bar->WidthAllTabsIdeal, tab_bar->BarRect.GetHeight()), tab_bar->FramePadding.y); | ||||||
| } | } | ||||||
|  |  | ||||||
| // Dockables uses Name/ID in the global namespace. Non-dockable items use the ID stack. | // Dockables uses Name/ID in the global namespace. Non-dockable items use the ID stack. | ||||||
| @@ -7150,7 +7136,7 @@ void ImGui::TabBarCloseTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) | |||||||
|  |  | ||||||
| static float ImGui::TabBarScrollClamp(ImGuiTabBar* tab_bar, float scrolling) | static float ImGui::TabBarScrollClamp(ImGuiTabBar* tab_bar, float scrolling) | ||||||
| { | { | ||||||
|     scrolling = ImMin(scrolling, tab_bar->OffsetMax - tab_bar->BarRect.GetWidth()); |     scrolling = ImMin(scrolling, tab_bar->WidthAllTabs - tab_bar->BarRect.GetWidth()); | ||||||
|     return ImMax(scrolling, 0.0f); |     return ImMax(scrolling, 0.0f); | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -7174,7 +7160,7 @@ static void ImGui::TabBarScrollToTab(ImGuiTabBar* tab_bar, ImGuiTabItem* tab) | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| void ImGui::TabBarQueueChangeTabOrder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int dir) | void ImGui::TabBarQueueReorder(ImGuiTabBar* tab_bar, const ImGuiTabItem* tab, int dir) | ||||||
| { | { | ||||||
|     IM_ASSERT(dir == -1 || dir == +1); |     IM_ASSERT(dir == -1 || dir == +1); | ||||||
|     IM_ASSERT(tab_bar->ReorderRequestTabId == 0); |     IM_ASSERT(tab_bar->ReorderRequestTabId == 0); | ||||||
| @@ -7182,6 +7168,28 @@ void ImGui::TabBarQueueChangeTabOrder(ImGuiTabBar* tab_bar, const ImGuiTabItem* | |||||||
|     tab_bar->ReorderRequestDir = (ImS8)dir; |     tab_bar->ReorderRequestDir = (ImS8)dir; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | bool ImGui::TabBarProcessReorder(ImGuiTabBar* tab_bar) | ||||||
|  | { | ||||||
|  |     ImGuiTabItem* tab1 = TabBarFindTabByID(tab_bar, tab_bar->ReorderRequestTabId); | ||||||
|  |     if (!tab1) | ||||||
|  |         return false; | ||||||
|  |  | ||||||
|  |     //IM_ASSERT(tab_bar->Flags & ImGuiTabBarFlags_Reorderable); // <- this may happen when using debug tools | ||||||
|  |     int tab2_order = tab_bar->GetTabOrder(tab1) + tab_bar->ReorderRequestDir; | ||||||
|  |     if (tab2_order < 0 || tab2_order >= tab_bar->Tabs.Size) | ||||||
|  |         return false; | ||||||
|  |  | ||||||
|  |     ImGuiTabItem* tab2 = &tab_bar->Tabs[tab2_order]; | ||||||
|  |     ImGuiTabItem item_tmp = *tab1; | ||||||
|  |     *tab1 = *tab2; | ||||||
|  |     *tab2 = item_tmp; | ||||||
|  |     tab1 = tab2 = NULL; | ||||||
|  |  | ||||||
|  |     if (tab_bar->Flags & ImGuiTabBarFlags_SaveSettings) | ||||||
|  |         MarkIniSettingsDirty(); | ||||||
|  |     return true; | ||||||
|  | } | ||||||
|  |  | ||||||
| static ImGuiTabItem* ImGui::TabBarScrollingButtons(ImGuiTabBar* tab_bar) | static ImGuiTabItem* ImGui::TabBarScrollingButtons(ImGuiTabBar* tab_bar) | ||||||
| { | { | ||||||
|     ImGuiContext& g = *GImGui; |     ImGuiContext& g = *GImGui; | ||||||
| @@ -7293,7 +7301,7 @@ bool    ImGui::BeginTabItem(const char* label, bool* p_open, ImGuiTabItemFlags f | |||||||
|     ImGuiTabBar* tab_bar = g.CurrentTabBar; |     ImGuiTabBar* tab_bar = g.CurrentTabBar; | ||||||
|     if (tab_bar == NULL) |     if (tab_bar == NULL) | ||||||
|     { |     { | ||||||
|         IM_ASSERT_USER_ERROR(tab_bar, "BeginTabItem() Needs to be called between BeginTabBar() and EndTabBar()!"); |         IM_ASSERT_USER_ERROR(tab_bar, "Needs to be called between BeginTabBar() and EndTabBar()!"); | ||||||
|         return false; |         return false; | ||||||
|     } |     } | ||||||
|     bool ret = TabItemEx(tab_bar, label, p_open, flags); |     bool ret = TabItemEx(tab_bar, label, p_open, flags); | ||||||
| @@ -7315,7 +7323,7 @@ void    ImGui::EndTabItem() | |||||||
|     ImGuiTabBar* tab_bar = g.CurrentTabBar; |     ImGuiTabBar* tab_bar = g.CurrentTabBar; | ||||||
|     if (tab_bar == NULL) |     if (tab_bar == NULL) | ||||||
|     { |     { | ||||||
|         IM_ASSERT(tab_bar != NULL && "Needs to be called between BeginTabBar() and EndTabBar()!"); |         IM_ASSERT_USER_ERROR(tab_bar != NULL, "Needs to be called between BeginTabBar() and EndTabBar()!"); | ||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|     IM_ASSERT(tab_bar->LastTabItemIdx >= 0); |     IM_ASSERT(tab_bar->LastTabItemIdx >= 0); | ||||||
| @@ -7471,12 +7479,12 @@ bool    ImGui::TabItemEx(ImGuiTabBar* tab_bar, const char* label, bool* p_open, | |||||||
|             if (g.IO.MouseDelta.x < 0.0f && g.IO.MousePos.x < bb.Min.x) |             if (g.IO.MouseDelta.x < 0.0f && g.IO.MousePos.x < bb.Min.x) | ||||||
|             { |             { | ||||||
|                 if (tab_bar->Flags & ImGuiTabBarFlags_Reorderable) |                 if (tab_bar->Flags & ImGuiTabBarFlags_Reorderable) | ||||||
|                     TabBarQueueChangeTabOrder(tab_bar, tab, -1); |                     TabBarQueueReorder(tab_bar, tab, -1); | ||||||
|             } |             } | ||||||
|             else if (g.IO.MouseDelta.x > 0.0f && g.IO.MousePos.x > bb.Max.x) |             else if (g.IO.MouseDelta.x > 0.0f && g.IO.MousePos.x > bb.Max.x) | ||||||
|             { |             { | ||||||
|                 if (tab_bar->Flags & ImGuiTabBarFlags_Reorderable) |                 if (tab_bar->Flags & ImGuiTabBarFlags_Reorderable) | ||||||
|                     TabBarQueueChangeTabOrder(tab_bar, tab, +1); |                     TabBarQueueReorder(tab_bar, tab, +1); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user