Skip to content

Commit baae057

Browse files
committed
Internals: Merge in minor noise from wip Tables branch to simplify further merging.
1 parent 5185329 commit baae057

File tree

3 files changed

+52
-21
lines changed

3 files changed

+52
-21
lines changed

imgui.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3934,6 +3934,11 @@ void ImGui::Shutdown(ImGuiContext* context)
39343934
g.DrawDataBuilder.ClearFreeMemory();
39353935
g.BackgroundDrawList.ClearFreeMemory();
39363936
g.ForegroundDrawList.ClearFreeMemory();
3937+
3938+
g.TabBars.Clear();
3939+
g.CurrentTabBarStack.clear();
3940+
g.ShrinkWidthBuffer.clear();
3941+
39373942
g.PrivateClipboard.clear();
39383943
g.InputTextState.ClearFreeMemory();
39393944

@@ -6744,7 +6749,8 @@ void ImGui::SetNextWindowBgAlpha(float alpha)
67446749
// FIXME: This is in window space (not screen space!). We should try to obsolete all those functions.
67456750
ImVec2 ImGui::GetContentRegionMax()
67466751
{
6747-
ImGuiWindow* window = GImGui->CurrentWindow;
6752+
ImGuiContext& g = *GImGui;
6753+
ImGuiWindow* window = g.CurrentWindow;
67486754
ImVec2 mx = window->ContentsRegionRect.Max - window->Pos;
67496755
if (window->DC.CurrentColumns)
67506756
mx.x = window->WorkRect.Max.x - window->Pos.x;
@@ -6754,7 +6760,8 @@ ImVec2 ImGui::GetContentRegionMax()
67546760
// [Internal] Absolute coordinate. Saner. This is not exposed until we finishing refactoring work rect features.
67556761
ImVec2 ImGui::GetContentRegionMaxAbs()
67566762
{
6757-
ImGuiWindow* window = GImGui->CurrentWindow;
6763+
ImGuiContext& g = *GImGui;
6764+
ImGuiWindow* window = g.CurrentWindow;
67586765
ImVec2 mx = window->ContentsRegionRect.Max;
67596766
if (window->DC.CurrentColumns)
67606767
mx.x = window->WorkRect.Max.x;
@@ -9650,14 +9657,16 @@ void ImGui::ShowMetricsWindow(bool* p_open)
96509657
return;
96519658
}
96529659

9660+
// State
96539661
enum { WRT_OuterRect, WRT_OuterRectClipped, WRT_InnerRect, WRT_InnerClipRect, WRT_WorkRect, WRT_Contents, WRT_ContentsRegionRect, WRT_Count }; // Windows Rect Type
96549662
const char* wrt_rects_names[WRT_Count] = { "OuterRect", "OuterRectClipped", "InnerRect", "InnerClipRect", "WorkRect", "Contents", "ContentsRegionRect" };
9655-
9656-
static bool show_windows_begin_order = false;
96579663
static bool show_windows_rects = false;
96589664
static int show_windows_rect_type = WRT_WorkRect;
9665+
static bool show_windows_begin_order = false;
96599666
static bool show_drawcmd_clip_rects = true;
96609667

9668+
// Basic info
9669+
ImGuiContext& g = *GImGui;
96619670
ImGuiIO& io = ImGui::GetIO();
96629671
ImGui::Text("Dear ImGui %s", ImGui::GetVersion());
96639672
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / io.Framerate, io.Framerate);
@@ -9666,6 +9675,12 @@ void ImGui::ShowMetricsWindow(bool* p_open)
96669675
ImGui::Text("%d active allocations", io.MetricsActiveAllocations);
96679676
ImGui::Separator();
96689677

9678+
// Helper functions to display common structures:
9679+
// - NodeDrawList
9680+
// - NodeColumns
9681+
// - NodeWindow
9682+
// - NodeWindows
9683+
// - NodeTabBar
96699684
struct Funcs
96709685
{
96719686
static ImRect GetWindowRect(ImGuiWindow* window, int rect_type)
@@ -9830,8 +9845,6 @@ void ImGui::ShowMetricsWindow(bool* p_open)
98309845
}
98319846
};
98329847

9833-
// Access private state, we are going to display the draw lists from last frame
9834-
ImGuiContext& g = *GImGui;
98359848
Funcs::NodeWindows(g.Windows, "Windows");
98369849
if (ImGui::TreeNode("DrawList", "Active DrawLists (%d)", g.DrawDataBuilder.Layers[0].Size))
98379850
{
@@ -9857,6 +9870,20 @@ void ImGui::ShowMetricsWindow(bool* p_open)
98579870
ImGui::TreePop();
98589871
}
98599872

9873+
#if 0
9874+
if (ImGui::TreeNode("Docking"))
9875+
{
9876+
ImGui::TreePop();
9877+
}
9878+
#endif
9879+
9880+
#if 0
9881+
if (ImGui::TreeNode("Tables", "Tables (%d)", g.Tables.Data.Size))
9882+
{
9883+
ImGui::TreePop();
9884+
}
9885+
#endif
9886+
98609887
if (ImGui::TreeNode("Internal state"))
98619888
{
98629889
const char* input_source_names[] = { "None", "Mouse", "Nav", "NavKeyboard", "NavGamepad" }; IM_ASSERT(IM_ARRAYSIZE(input_source_names) == ImGuiInputSource_COUNT);
@@ -9903,6 +9930,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
99039930
ImGui::TreePop();
99049931
}
99059932

9933+
// Tool: Display windows Rectangles and Begin Order
99069934
if (show_windows_rects || show_windows_begin_order)
99079935
{
99089936
for (int n = 0; n < g.Windows.Size; n++)

imgui_internal.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,8 @@ enum ImGuiSelectableFlagsPrivate_
358358
ImGuiSelectableFlags_PressedOnClick = 1 << 21,
359359
ImGuiSelectableFlags_PressedOnRelease = 1 << 22,
360360
ImGuiSelectableFlags_DrawFillAvailWidth = 1 << 23, // FIXME: We may be able to remove this (added in 6251d379 for menus)
361-
ImGuiSelectableFlags_AllowItemOverlap = 1 << 24
361+
ImGuiSelectableFlags_AllowItemOverlap = 1 << 24,
362+
ImGuiSelectableFlags_DrawHoveredWhenHeld= 1 << 25 // Always show active when held, even is not hovered. This concept could probably be renamed/formalized somehow.
362363
};
363364

364365
// Extend ImGuiTreeNodeFlags_
@@ -827,13 +828,13 @@ struct ImGuiShrinkWidthItem
827828
float Width;
828829
};
829830

830-
struct ImGuiTabBarRef
831+
struct ImGuiPtrOrIndex
831832
{
832-
ImGuiTabBar* Ptr; // Either field can be set, not both. Dock node tab bars are loose while BeginTabBar() ones are in a pool.
833-
int IndexInMainPool;
833+
void* Ptr; // Either field can be set, not both. e.g. Dock node tab bars are loose while BeginTabBar() ones are in a pool.
834+
int Index; // Usually index in a main pool.
834835

835-
ImGuiTabBarRef(ImGuiTabBar* ptr) { Ptr = ptr; IndexInMainPool = -1; }
836-
ImGuiTabBarRef(int index_in_main_pool) { Ptr = NULL; IndexInMainPool = index_in_main_pool; }
836+
ImGuiPtrOrIndex(void* ptr) { Ptr = ptr; Index = -1; }
837+
ImGuiPtrOrIndex(int index) { Ptr = NULL; Index = index; }
837838
};
838839

839840
//-----------------------------------------------------------------------------
@@ -986,9 +987,9 @@ struct ImGuiContext
986987
unsigned char DragDropPayloadBufLocal[8]; // Local buffer for small payloads
987988

988989
// Tab bars
989-
ImPool<ImGuiTabBar> TabBars;
990990
ImGuiTabBar* CurrentTabBar;
991-
ImVector<ImGuiTabBarRef> CurrentTabBarStack;
991+
ImPool<ImGuiTabBar> TabBars;
992+
ImVector<ImGuiPtrOrIndex> CurrentTabBarStack;
992993
ImVector<ImGuiShrinkWidthItem> ShrinkWidthBuffer;
993994

994995
// Widget state
@@ -1425,7 +1426,7 @@ struct ImGuiTabBar
14251426
float ScrollingSpeed;
14261427
ImGuiTabBarFlags Flags;
14271428
ImGuiID ReorderRequestTabId;
1428-
int ReorderRequestDir;
1429+
ImS8 ReorderRequestDir;
14291430
bool WantLayout;
14301431
bool VisibleTabWasSubmitted;
14311432
short LastTabItemIdx; // For BeginTabItem()/EndTabItem()

imgui_widgets.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5490,6 +5490,8 @@ bool ImGui::Selectable(const char* label, bool selected, ImGuiSelectableFlags fl
54905490
window->DC.LastItemStatusFlags |= ImGuiItemStatusFlags_ToggledSelection;
54915491

54925492
// Render
5493+
if (held && (flags & ImGuiSelectableFlags_DrawHoveredWhenHeld))
5494+
hovered = true;
54935495
if (hovered || selected)
54945496
{
54955497
const ImU32 col = GetColorU32((held && hovered) ? ImGuiCol_HeaderActive : hovered ? ImGuiCol_HeaderHovered : ImGuiCol_Header);
@@ -6271,18 +6273,18 @@ static int IMGUI_CDECL TabItemComparerByVisibleOffset(const void* lhs, const voi
62716273
return (int)(a->Offset - b->Offset);
62726274
}
62736275

6274-
static ImGuiTabBar* GetTabBarFromTabBarRef(const ImGuiTabBarRef& ref)
6276+
static ImGuiTabBar* GetTabBarFromTabBarRef(const ImGuiPtrOrIndex& ref)
62756277
{
62766278
ImGuiContext& g = *GImGui;
6277-
return ref.Ptr ? ref.Ptr : g.TabBars.GetByIndex(ref.IndexInMainPool);
6279+
return ref.Ptr ? (ImGuiTabBar*)ref.Ptr : g.TabBars.GetByIndex(ref.Index);
62786280
}
62796281

6280-
static ImGuiTabBarRef GetTabBarRefFromTabBar(ImGuiTabBar* tab_bar)
6282+
static ImGuiPtrOrIndex GetTabBarRefFromTabBar(ImGuiTabBar* tab_bar)
62816283
{
62826284
ImGuiContext& g = *GImGui;
62836285
if (g.TabBars.Contains(tab_bar))
6284-
return ImGuiTabBarRef(g.TabBars.GetIndex(tab_bar));
6285-
return ImGuiTabBarRef(tab_bar);
6286+
return ImGuiPtrOrIndex(g.TabBars.GetIndex(tab_bar));
6287+
return ImGuiPtrOrIndex(tab_bar);
62866288
}
62876289

62886290
bool ImGui::BeginTabBar(const char* str_id, ImGuiTabBarFlags flags)
@@ -6637,7 +6639,7 @@ void ImGui::TabBarQueueChangeTabOrder(ImGuiTabBar* tab_bar, const ImGuiTabItem*
66376639
IM_ASSERT(dir == -1 || dir == +1);
66386640
IM_ASSERT(tab_bar->ReorderRequestTabId == 0);
66396641
tab_bar->ReorderRequestTabId = tab->ID;
6640-
tab_bar->ReorderRequestDir = dir;
6642+
tab_bar->ReorderRequestDir = (ImS8)dir;
66416643
}
66426644

66436645
static ImGuiTabItem* ImGui::TabBarScrollingButtons(ImGuiTabBar* tab_bar)

0 commit comments

Comments
 (0)