mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-13 16:29:54 +02:00
Make classes not depend on the implicit GImGui context (#5856, #6199): ImGuiWindow, ImGuiInputTextCallbackData, ImGuiListClipper, ImGuiStackSizes
This commit is a preparation toward adding ImGui apis with explicit context and making ImGui applications being able to use multiple context at the same time whatever their concurrency model. This commit modifies ImGuiInputTextCallback, ImGuiListClipper and ImGuiStackSize so those classes do not to depend on GImGui context anymore. About ImGuiInputTextCallback: - ImGuiInputTextCallback depends on ImGuiContext because it has a `InsertChars` method adding character to `g.InputTextState` - To make ImGuiInputTextCallback aware of which context to use, the appropriate context is given as argument of ImGuiInputTextCallback constructor. About ImGuiListClipper: - ImGuiListClipper apply to a context through its `Begin`, `End`, and `Step` method. - To make ImGuiListClipper aware of which context to use, the appropriate context is given as argument of ImGuiListClipper constructor. - Since the behavior is different than previously the class has been renamed ImGuiListClipperEx - In order to preserve backward compatibility, a subclass of ImGuiListClipperEx named ImGuiListClipper has been defined and forward the implicit context to ImGuiListClipperEx parent. About ImGuiTextFilter: - ImGuiTextFilter depends on the implicit context because the Draw(..) method call ImGui::InputText(...) - Instead from that commit the Draw(...) method takes an explicit context as first argument - Since the behavior is different than previously the class has been renamed ImGuiTextFilterEx - In order to preserve backward compatibility, a subclass of ImGuiTextFilterEx named ImGuiTextFilter has been defined. This subclass has a draw method override which and forward the implicit context to the parent class Draw(...) About ImGuiStackSizes: - ImGuiStackSizes was depending on ImGuiContext because of its `SetToCurrentState` and `CompareWithCurrentState` method - ImGuiStackSizes is an helper object use for comparing state of context. It does not necessarily need to compare the same context. For that reason, as opposed to previous classes it takes the context it wants to compare to as argument of its method. - For this occasion `SetToCurrentState` and `CompareWithCurrentState` have been renamed `SetToContextState` and `CompareWithContextState` to match the new method signature. ImGuiListClipper ImGuiInputTextCallbackData
This commit is contained in:
@ -1182,8 +1182,8 @@ struct IMGUI_API ImGuiStackSizes
|
||||
short SizeOfDisabledStack;
|
||||
|
||||
ImGuiStackSizes() { memset(this, 0, sizeof(*this)); }
|
||||
void SetToCurrentState();
|
||||
void CompareWithCurrentState();
|
||||
void SetToContextState(ImGuiContext* ctx);
|
||||
void CompareWithContextState(ImGuiContext* ctx);
|
||||
};
|
||||
|
||||
// Data saved for each window pushed into the stack
|
||||
@ -2237,6 +2237,7 @@ struct IMGUI_API ImGuiWindowTempData
|
||||
// Storage for one window
|
||||
struct IMGUI_API ImGuiWindow
|
||||
{
|
||||
ImGuiContext* Ctx; // Parent UI context (needs to be set explicitly by parent).
|
||||
char* Name; // Window name, owned by the window.
|
||||
ImGuiID ID; // == ImHashStr(Name)
|
||||
ImGuiWindowFlags Flags; // See enum ImGuiWindowFlags_
|
||||
@ -2347,10 +2348,10 @@ public:
|
||||
|
||||
// We don't use g.FontSize because the window may be != g.CurrentWindow.
|
||||
ImRect Rect() const { return ImRect(Pos.x, Pos.y, Pos.x + Size.x, Pos.y + Size.y); }
|
||||
float CalcFontSize() const { ImGuiContext& g = *GImGui; float scale = g.FontBaseSize * FontWindowScale; if (ParentWindow) scale *= ParentWindow->FontWindowScale; return scale; }
|
||||
float TitleBarHeight() const { ImGuiContext& g = *GImGui; return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + g.Style.FramePadding.y * 2.0f; }
|
||||
float CalcFontSize() const { ImGuiContext& g = *Ctx; float scale = g.FontBaseSize * FontWindowScale; if (ParentWindow) scale *= ParentWindow->FontWindowScale; return scale; }
|
||||
float TitleBarHeight() const { ImGuiContext& g = *Ctx; return (Flags & ImGuiWindowFlags_NoTitleBar) ? 0.0f : CalcFontSize() + g.Style.FramePadding.y * 2.0f; }
|
||||
ImRect TitleBarRect() const { return ImRect(Pos, ImVec2(Pos.x + SizeFull.x, Pos.y + TitleBarHeight())); }
|
||||
float MenuBarHeight() const { ImGuiContext& g = *GImGui; return (Flags & ImGuiWindowFlags_MenuBar) ? DC.MenuBarOffset.y + CalcFontSize() + g.Style.FramePadding.y * 2.0f : 0.0f; }
|
||||
float MenuBarHeight() const { ImGuiContext& g = *Ctx; return (Flags & ImGuiWindowFlags_MenuBar) ? DC.MenuBarOffset.y + CalcFontSize() + g.Style.FramePadding.y * 2.0f : 0.0f; }
|
||||
ImRect MenuBarRect() const { float y1 = Pos.y + TitleBarHeight(); return ImRect(Pos.x, y1, Pos.x + SizeFull.x, y1 + MenuBarHeight()); }
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user