|
|
@@ -372,6 +372,7 @@ CODE
|
|
|
When you are not sure about a old symbol or function name, try using the Search/Find function of your IDE to look for comments or references in all imgui files.
|
|
|
You can read releases logs https://github.com/ocornut/imgui/releases for more details.
|
|
|
|
|
|
+ - 2020/06/23 (1.77) - removed BeginPopupContextWindow(const char*, int mouse_button, bool also_over_items) in favor of BeginPopupContextWindow(const char*, ImGuiPopupFlags flags) with ImGuiPopupFlags_NoOverItems.
|
|
|
- 2020/06/15 (1.77) - renamed OpenPopupOnItemClick() to OpenPopupContextItem(). Kept inline redirection function (will obsolete).
|
|
|
- 2020/06/15 (1.77) - removed CalcItemRectClosestPoint() entry point which was made obsolete and asserting in December 2017.
|
|
|
- 2020/04/23 (1.77) - removed unnecessary ID (first arg) of ImFontAtlas::AddCustomRectRegular().
|
|
|
@@ -600,7 +601,10 @@ CODE
|
|
|
FREQUENTLY ASKED QUESTIONS (FAQ)
|
|
|
================================
|
|
|
|
|
|
- Read all answers online: https://www.dearimgui.org/faq, or in docs/FAQ.md (with a Markdown viewer)
|
|
|
+ Read all answers online:
|
|
|
+ https://www.dearimgui.org/faq or https://github.com/ocornut/imgui/blob/master/docs/FAQ.md (same url)
|
|
|
+ Read all answers locally (with a text editor or ideally a Markdown viewer):
|
|
|
+ docs/FAQ.md
|
|
|
Some answers are copied down here to facilitate searching in code.
|
|
|
|
|
|
Q&A: Basics
|
|
|
@@ -639,130 +643,15 @@ CODE
|
|
|
Q: I integrated Dear ImGui in my engine and little squares are showing instead of text..
|
|
|
Q: I integrated Dear ImGui in my engine and some elements are clipping or disappearing when I move windows around..
|
|
|
Q: I integrated Dear ImGui in my engine and some elements are displaying outside their expected windows boundaries..
|
|
|
->> See https://www.dearimgui.org/faq
|
|
|
+ >> See https://www.dearimgui.org/faq
|
|
|
|
|
|
Q&A: Usage
|
|
|
----------
|
|
|
|
|
|
- Q: Why are multiple widgets reacting when I interact with a single one?
|
|
|
- Q: How can I have multiple widgets with the same label or with an empty label?
|
|
|
- A: A primer on labels and the ID Stack...
|
|
|
-
|
|
|
- Dear ImGui internally need to uniquely identify UI elements.
|
|
|
- Elements that are typically not clickable (such as calls to the Text functions) don't need an ID.
|
|
|
- Interactive widgets (such as calls to Button buttons) need a unique ID.
|
|
|
- Unique ID are used internally to track active widgets and occasionally associate state to widgets.
|
|
|
- Unique ID are implicitly built from the hash of multiple elements that identify the "path" to the UI element.
|
|
|
-
|
|
|
- - Unique ID are often derived from a string label:
|
|
|
-
|
|
|
- Button("OK"); // Label = "OK", ID = hash of (..., "OK")
|
|
|
- Button("Cancel"); // Label = "Cancel", ID = hash of (..., "Cancel")
|
|
|
-
|
|
|
- - ID are uniquely scoped within windows, tree nodes, etc. which all pushes to the ID stack. Having
|
|
|
- two buttons labeled "OK" in different windows or different tree locations is fine.
|
|
|
- We used "..." above to signify whatever was already pushed to the ID stack previously:
|
|
|
-
|
|
|
- Begin("MyWindow");
|
|
|
- Button("OK"); // Label = "OK", ID = hash of ("MyWindow", "OK")
|
|
|
- End();
|
|
|
- Begin("MyOtherWindow");
|
|
|
- Button("OK"); // Label = "OK", ID = hash of ("MyOtherWindow", "OK")
|
|
|
- End();
|
|
|
-
|
|
|
- - If you have a same ID twice in the same location, you'll have a conflict:
|
|
|
-
|
|
|
- Button("OK");
|
|
|
- Button("OK"); // ID collision! Interacting with either button will trigger the first one.
|
|
|
-
|
|
|
- Fear not! this is easy to solve and there are many ways to solve it!
|
|
|
-
|
|
|
- - Solving ID conflict in a simple/local context:
|
|
|
- When passing a label you can optionally specify extra ID information within string itself.
|
|
|
- Use "##" to pass a complement to the ID that won't be visible to the end-user.
|
|
|
- This helps solving the simple collision cases when you know e.g. at compilation time which items
|
|
|
- are going to be created:
|
|
|
-
|
|
|
- Begin("MyWindow");
|
|
|
- Button("Play"); // Label = "Play", ID = hash of ("MyWindow", "Play")
|
|
|
- Button("Play##foo1"); // Label = "Play", ID = hash of ("MyWindow", "Play##foo1") // Different from above
|
|
|
- Button("Play##foo2"); // Label = "Play", ID = hash of ("MyWindow", "Play##foo2") // Different from above
|
|
|
- End();
|
|
|
-
|
|
|
- - If you want to completely hide the label, but still need an ID:
|
|
|
-
|
|
|
- Checkbox("##On", &b); // Label = "", ID = hash of (..., "##On") // No visible label, just a checkbox!
|
|
|
-
|
|
|
- - Occasionally/rarely you might want change a label while preserving a constant ID. This allows
|
|
|
- you to animate labels. For example you may want to include varying information in a window title bar,
|
|
|
- but windows are uniquely identified by their ID. Use "###" to pass a label that isn't part of ID:
|
|
|
-
|
|
|
- Button("Hello###ID"); // Label = "Hello", ID = hash of (..., "###ID")
|
|
|
- Button("World###ID"); // Label = "World", ID = hash of (..., "###ID") // Same as above, even though the label looks different
|
|
|
-
|
|
|
- sprintf(buf, "My game (%f FPS)###MyGame", fps);
|
|
|
- Begin(buf); // Variable title, ID = hash of "MyGame"
|
|
|
-
|
|
|
- - Solving ID conflict in a more general manner:
|
|
|
- Use PushID() / PopID() to create scopes and manipulate the ID stack, as to avoid ID conflicts
|
|
|
- within the same window. This is the most convenient way of distinguishing ID when iterating and
|
|
|
- creating many UI elements programmatically.
|
|
|
- You can push a pointer, a string or an integer value into the ID stack.
|
|
|
- Remember that ID are formed from the concatenation of _everything_ pushed into the ID stack.
|
|
|
- At each level of the stack we store the seed used for items at this level of the ID stack.
|
|
|
-
|
|
|
- Begin("Window");
|
|
|
- for (int i = 0; i < 100; i++)
|
|
|
- {
|
|
|
- PushID(i); // Push i to the id tack
|
|
|
- Button("Click"); // Label = "Click", ID = hash of ("Window", i, "Click")
|
|
|
- PopID();
|
|
|
- }
|
|
|
- for (int i = 0; i < 100; i++)
|
|
|
- {
|
|
|
- MyObject* obj = Objects[i];
|
|
|
- PushID(obj);
|
|
|
- Button("Click"); // Label = "Click", ID = hash of ("Window", obj pointer, "Click")
|
|
|
- PopID();
|
|
|
- }
|
|
|
- for (int i = 0; i < 100; i++)
|
|
|
- {
|
|
|
- MyObject* obj = Objects[i];
|
|
|
- PushID(obj->Name);
|
|
|
- Button("Click"); // Label = "Click", ID = hash of ("Window", obj->Name, "Click")
|
|
|
- PopID();
|
|
|
- }
|
|
|
- End();
|
|
|
-
|
|
|
- - You can stack multiple prefixes into the ID stack:
|
|
|
-
|
|
|
- Button("Click"); // Label = "Click", ID = hash of (..., "Click")
|
|
|
- PushID("node");
|
|
|
- Button("Click"); // Label = "Click", ID = hash of (..., "node", "Click")
|
|
|
- PushID(my_ptr);
|
|
|
- Button("Click"); // Label = "Click", ID = hash of (..., "node", my_ptr, "Click")
|
|
|
- PopID();
|
|
|
- PopID();
|
|
|
-
|
|
|
- - Tree nodes implicitly creates a scope for you by calling PushID().
|
|
|
-
|
|
|
- Button("Click"); // Label = "Click", ID = hash of (..., "Click")
|
|
|
- if (TreeNode("node")) // <-- this function call will do a PushID() for you (unless instructed not to, with a special flag)
|
|
|
- {
|
|
|
- Button("Click"); // Label = "Click", ID = hash of (..., "node", "Click")
|
|
|
- TreePop();
|
|
|
- }
|
|
|
-
|
|
|
- - When working with trees, ID are used to preserve the open/close state of each tree node.
|
|
|
- Depending on your use cases you may want to use strings, indices or pointers as ID.
|
|
|
- e.g. when following a single pointer that may change over time, using a static string as ID
|
|
|
- will preserve your node open/closed state when the targeted object change.
|
|
|
- e.g. when displaying a list of objects, using indices or pointers as ID will preserve the
|
|
|
- node open/closed state differently. See what makes more sense in your situation!
|
|
|
-
|
|
|
+ Q: How can I have widgets with an empty label?
|
|
|
+ Q: How can I have multiple widgets with the same label?
|
|
|
+ Q: Why are multiple widgets reacting when I interact with one?
|
|
|
Q: How can I display an image? What is ImTextureID, how does it works?
|
|
|
- >> See https://www.dearimgui.org/faq and https://github.com/ocornut/imgui/wiki/Image-Loading-and-Displaying-Examples
|
|
|
-
|
|
|
Q: How can I use my own math types instead of ImVec2/ImVec4?
|
|
|
Q: How can I interact with standard C++ types (such as std::string and std::vector)?
|
|
|
Q: How can I display custom shapes? (using low-level ImDrawList API)
|
|
|
@@ -965,7 +854,7 @@ static void UpdateMouseInputs();
|
|
|
static void UpdateMouseWheel();
|
|
|
static void UpdateTabFocus();
|
|
|
static void UpdateDebugToolItemPicker();
|
|
|
-static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4]);
|
|
|
+static bool UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect);
|
|
|
static void RenderWindowOuterBorders(ImGuiWindow* window);
|
|
|
static void RenderWindowDecorations(ImGuiWindow* window, const ImRect& title_bar_rect, bool title_bar_is_highlight, int resize_grip_count, const ImU32 resize_grip_col[4], float resize_grip_draw_size);
|
|
|
static void RenderWindowTitleBarContents(ImGuiWindow* window, const ImRect& title_bar_rect, const char* name, bool* p_open);
|
|
|
@@ -3257,11 +3146,21 @@ float ImGui::CalcWrapWidthForPos(const ImVec2& pos, float wrap_pos_x)
|
|
|
if (wrap_pos_x < 0.0f)
|
|
|
return 0.0f;
|
|
|
|
|
|
- ImGuiWindow* window = GImGui->CurrentWindow;
|
|
|
+ ImGuiContext& g = *GImGui;
|
|
|
+ ImGuiWindow* window = g.CurrentWindow;
|
|
|
if (wrap_pos_x == 0.0f)
|
|
|
+ {
|
|
|
+ // We could decide to setup a default wrapping max point for auto-resizing windows,
|
|
|
+ // or have auto-wrap (with unspecified wrapping pos) behave as a ContentSize extending function?
|
|
|
+ //if (window->Hidden && (window->Flags & ImGuiWindowFlags_AlwaysAutoResize))
|
|
|
+ // wrap_pos_x = ImMax(window->WorkRect.Min.x + g.FontSize * 10.0f, window->WorkRect.Max.x);
|
|
|
+ //else
|
|
|
wrap_pos_x = window->WorkRect.Max.x;
|
|
|
+ }
|
|
|
else if (wrap_pos_x > 0.0f)
|
|
|
+ {
|
|
|
wrap_pos_x += window->Pos.x - window->Scroll.x; // wrap_pos_x is provided is window local space
|
|
|
+ }
|
|
|
|
|
|
return ImMax(wrap_pos_x - pos.x, 1.0f);
|
|
|
}
|
|
|
@@ -3460,7 +3359,7 @@ void ImGui::UpdateMouseMovingWindowEndFrame()
|
|
|
// Handle the edge case of a popup being closed while clicking in its empty space.
|
|
|
// If we try to focus it, FocusWindow() > ClosePopupsOverWindow() will accidentally close any parent popups because they are not linked together any more.
|
|
|
ImGuiWindow* root_window = g.HoveredRootWindow;
|
|
|
- const bool is_closed_popup = root_window && (root_window->Flags & ImGuiWindowFlags_Popup) && !IsPopupOpenAtAnyLevel(root_window->PopupId);
|
|
|
+ const bool is_closed_popup = root_window && (root_window->Flags & ImGuiWindowFlags_Popup) && !IsPopupOpen(root_window->PopupId, ImGuiPopupFlags_AnyPopupLevel);
|
|
|
|
|
|
if (root_window != NULL && !is_closed_popup)
|
|
|
{
|
|
|
@@ -5122,7 +5021,7 @@ ImGuiID ImGui::GetWindowResizeID(ImGuiWindow* window, int n)
|
|
|
|
|
|
// Handle resize for: Resize Grips, Borders, Gamepad
|
|
|
// Return true when using auto-fit (double click on resize grip)
|
|
|
-static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4])
|
|
|
+static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& size_auto_fit, int* border_held, int resize_grip_count, ImU32 resize_grip_col[4], const ImRect& visibility_rect)
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
ImGuiWindowFlags flags = window->Flags;
|
|
|
@@ -5174,6 +5073,9 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
|
|
|
// Resize from any of the four corners
|
|
|
// We don't use an incremental MouseDelta but rather compute an absolute target size based on mouse position
|
|
|
ImVec2 corner_target = g.IO.MousePos - g.ActiveIdClickOffset + ImLerp(grip.InnerDir * grip_hover_outer_size, grip.InnerDir * -grip_hover_inner_size, grip.CornerPosN); // Corner of the window corresponding to our corner grip
|
|
|
+ ImVec2 clamp_min = ImVec2(grip.CornerPosN.x == 1.0f ? visibility_rect.Min.x : -FLT_MAX, grip.CornerPosN.y == 1.0f ? visibility_rect.Min.y : -FLT_MAX);
|
|
|
+ ImVec2 clamp_max = ImVec2(grip.CornerPosN.x == 0.0f ? visibility_rect.Max.x : +FLT_MAX, grip.CornerPosN.y == 0.0f ? visibility_rect.Max.y : +FLT_MAX);
|
|
|
+ corner_target = ImClamp(corner_target, clamp_min, clamp_max);
|
|
|
CalcResizePosSizeFromAnyCorner(window, corner_target, grip.CornerPosN, &pos_target, &size_target);
|
|
|
}
|
|
|
if (resize_grip_n == 0 || held || hovered)
|
|
|
@@ -5199,6 +5101,9 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
|
|
|
if (border_n == 1) { border_posn = ImVec2(1, 0); border_target.x = (g.IO.MousePos.x - g.ActiveIdClickOffset.x + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); } // Right
|
|
|
if (border_n == 2) { border_posn = ImVec2(0, 1); border_target.y = (g.IO.MousePos.y - g.ActiveIdClickOffset.y + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); } // Bottom
|
|
|
if (border_n == 3) { border_posn = ImVec2(0, 0); border_target.x = (g.IO.MousePos.x - g.ActiveIdClickOffset.x + WINDOWS_RESIZE_FROM_EDGES_HALF_THICKNESS); } // Left
|
|
|
+ ImVec2 clamp_min = ImVec2(border_n == 1 ? visibility_rect.Min.x : -FLT_MAX, border_n == 2 ? visibility_rect.Min.y : -FLT_MAX);
|
|
|
+ ImVec2 clamp_max = ImVec2(border_n == 3 ? visibility_rect.Max.x : +FLT_MAX, border_n == 0 ? visibility_rect.Max.y : +FLT_MAX);
|
|
|
+ border_target = ImClamp(border_target, clamp_min, clamp_max);
|
|
|
CalcResizePosSizeFromAnyCorner(window, border_target, border_posn, &pos_target, &size_target);
|
|
|
}
|
|
|
}
|
|
|
@@ -5220,6 +5125,7 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
|
|
|
{
|
|
|
const float NAV_RESIZE_SPEED = 600.0f;
|
|
|
nav_resize_delta *= ImFloor(NAV_RESIZE_SPEED * g.IO.DeltaTime * ImMin(g.IO.DisplayFramebufferScale.x, g.IO.DisplayFramebufferScale.y));
|
|
|
+ nav_resize_delta = ImMax(nav_resize_delta, visibility_rect.Min - window->Pos - window->Size);
|
|
|
g.NavWindowingToggleLayer = false;
|
|
|
g.NavDisableMouseHover = true;
|
|
|
resize_grip_col[0] = GetColorU32(ImGuiCol_ResizeGripActive);
|
|
|
@@ -5244,13 +5150,13 @@ static bool ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& s
|
|
|
return ret_auto_fit;
|
|
|
}
|
|
|
|
|
|
-static inline void ClampWindowRect(ImGuiWindow* window, const ImRect& viewport_rect, const ImVec2& padding)
|
|
|
+static inline void ClampWindowRect(ImGuiWindow* window, const ImRect& visibility_rect)
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
ImVec2 size_for_clamping = window->Size;
|
|
|
if (g.IO.ConfigWindowsMoveFromTitleBarOnly && !(window->Flags & ImGuiWindowFlags_NoTitleBar))
|
|
|
size_for_clamping.y = window->TitleBarHeight();
|
|
|
- window->Pos = ImClamp(window->Pos, viewport_rect.Min + padding - size_for_clamping, viewport_rect.Max - padding);
|
|
|
+ window->Pos = ImClamp(window->Pos, visibility_rect.Min - size_for_clamping, visibility_rect.Max);
|
|
|
}
|
|
|
|
|
|
static void ImGui::RenderWindowOuterBorders(ImGuiWindow* window)
|
|
|
@@ -5740,7 +5646,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|
|
if (window_just_activated_by_user)
|
|
|
{
|
|
|
window->AutoPosLastDirection = ImGuiDir_None;
|
|
|
- if ((flags & ImGuiWindowFlags_Popup) != 0 && !window_pos_set_by_api)
|
|
|
+ if ((flags & ImGuiWindowFlags_Popup) != 0 && !(flags & ImGuiWindowFlags_Modal) && !window_pos_set_by_api) // FIXME: BeginPopup() could use SetNextWindowPos()
|
|
|
window->Pos = g.BeginPopupStack.back().OpenPopupPos;
|
|
|
}
|
|
|
|
|
|
@@ -5764,17 +5670,17 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|
|
else if ((flags & ImGuiWindowFlags_Tooltip) != 0 && !window_pos_set_by_api && !window_is_child_tooltip)
|
|
|
window->Pos = FindBestWindowPosForPopup(window);
|
|
|
|
|
|
+ // Calculate the range of allowed position for that window (to be movable and visible past safe area padding)
|
|
|
+ // When clamping to stay visible, we will enforce that window->Pos stays inside of visibility_rect.
|
|
|
+ ImRect viewport_rect(GetViewportRect());
|
|
|
+ ImVec2 visibility_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding);
|
|
|
+ ImRect visibility_rect(viewport_rect.Min + visibility_padding, viewport_rect.Max - visibility_padding);
|
|
|
+
|
|
|
// Clamp position/size so window stays visible within its viewport or monitor
|
|
|
// Ignore zero-sized display explicitly to avoid losing positions if a window manager reports zero-sized window when initializing or minimizing.
|
|
|
- ImRect viewport_rect(GetViewportRect());
|
|
|
if (!window_pos_set_by_api && !(flags & ImGuiWindowFlags_ChildWindow) && window->AutoFitFramesX <= 0 && window->AutoFitFramesY <= 0)
|
|
|
- {
|
|
|
- ImVec2 clamp_padding = ImMax(style.DisplayWindowPadding, style.DisplaySafeAreaPadding);
|
|
|
- if (viewport_rect.GetWidth() > 0 && viewport_rect.GetHeight() > 0.0f)
|
|
|
- {
|
|
|
- ClampWindowRect(window, viewport_rect, clamp_padding);
|
|
|
- }
|
|
|
- }
|
|
|
+ if (viewport_rect.GetWidth() > 0.0f && viewport_rect.GetHeight() > 0.0f)
|
|
|
+ ClampWindowRect(window, visibility_rect);
|
|
|
window->Pos = ImFloor(window->Pos);
|
|
|
|
|
|
// Lock window rounding for the frame (so that altering them doesn't cause inconsistencies)
|
|
|
@@ -5801,7 +5707,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
|
|
|
const int resize_grip_count = g.IO.ConfigWindowsResizeFromEdges ? 2 : 1; // Allow resize from lower-left if we have the mouse cursor feedback for it.
|
|
|
const float resize_grip_draw_size = IM_FLOOR(ImMax(g.FontSize * 1.35f, window->WindowRounding + 1.0f + g.FontSize * 0.2f));
|
|
|
if (!window->Collapsed)
|
|
|
- if (UpdateWindowManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0]))
|
|
|
+ if (UpdateWindowManualResize(window, size_auto_fit, &border_held, resize_grip_count, &resize_grip_col[0], visibility_rect))
|
|
|
use_current_size_for_scrollbar_x = use_current_size_for_scrollbar_y = true;
|
|
|
window->ResizeBorderHeld = (signed char)border_held;
|
|
|
|
|
|
@@ -7611,35 +7517,45 @@ void ImGui::SetTooltip(const char* fmt, ...)
|
|
|
// [SECTION] POPUPS
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
-// Return true if the popup is open at the current BeginPopup() level of the popup stack
|
|
|
-bool ImGui::IsPopupOpen(ImGuiID id)
|
|
|
+// Supported flags: ImGuiPopupFlags_AnyPopupId, ImGuiPopupFlags_AnyPopupLevel
|
|
|
+bool ImGui::IsPopupOpen(ImGuiID id, ImGuiPopupFlags popup_flags)
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
- return g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].PopupId == id;
|
|
|
-}
|
|
|
-
|
|
|
-// Return true if the popup is open at the current BeginPopup() level of the popup stack
|
|
|
-bool ImGui::IsPopupOpen(const char* str_id)
|
|
|
-{
|
|
|
- ImGuiContext& g = *GImGui;
|
|
|
- return g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].PopupId == g.CurrentWindow->GetID(str_id);
|
|
|
-}
|
|
|
-
|
|
|
-bool ImGui::IsPopupOpenAtAnyLevel(ImGuiID id)
|
|
|
-{
|
|
|
- ImGuiContext& g = *GImGui;
|
|
|
- for (int n = 0; n < g.OpenPopupStack.Size; n++)
|
|
|
- if (g.OpenPopupStack[n].PopupId == id)
|
|
|
- return true;
|
|
|
- return false;
|
|
|
+ if (popup_flags & ImGuiPopupFlags_AnyPopupId)
|
|
|
+ {
|
|
|
+ // Return true if any popup is open at the current BeginPopup() level of the popup stack
|
|
|
+ // This may be used to e.g. test for another popups already opened to handle popups priorities at the same level.
|
|
|
+ IM_ASSERT(id == 0);
|
|
|
+ if (popup_flags & ImGuiPopupFlags_AnyPopupLevel)
|
|
|
+ return g.OpenPopupStack.Size > 0;
|
|
|
+ else
|
|
|
+ return g.OpenPopupStack.Size > g.BeginPopupStack.Size;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ if (popup_flags & ImGuiPopupFlags_AnyPopupLevel)
|
|
|
+ {
|
|
|
+ // Return true if the popup is open anywhere in the popup stack
|
|
|
+ for (int n = 0; n < g.OpenPopupStack.Size; n++)
|
|
|
+ if (g.OpenPopupStack[n].PopupId == id)
|
|
|
+ return true;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Return true if the popup is open at the current BeginPopup() level of the popup stack (this is the most-common query)
|
|
|
+ return g.OpenPopupStack.Size > g.BeginPopupStack.Size && g.OpenPopupStack[g.BeginPopupStack.Size].PopupId == id;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-// Return true if any popup is open at the current BeginPopup() level of the popup stack
|
|
|
-// This may be used to e.g. test for another popups already opened in the same frame to handle popups priorities at the same level.
|
|
|
-bool ImGui::IsAnyPopupOpen()
|
|
|
+bool ImGui::IsPopupOpen(const char* str_id, ImGuiPopupFlags popup_flags)
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
- return g.OpenPopupStack.Size > g.BeginPopupStack.Size;
|
|
|
+ ImGuiID id = (popup_flags & ImGuiPopupFlags_AnyPopupId) ? 0 : g.CurrentWindow->GetID(str_id);
|
|
|
+ if ((popup_flags & ImGuiPopupFlags_AnyPopupLevel) && id != 0)
|
|
|
+ IM_ASSERT(0 && "Cannot use IsPopupOpen() with a string id and ImGuiPopupFlags_AnyPopupLevel."); // But non-string version is legal and used internally
|
|
|
+ return IsPopupOpen(id, popup_flags);
|
|
|
}
|
|
|
|
|
|
ImGuiWindow* ImGui::GetTopMostPopupModal()
|
|
|
@@ -7652,21 +7568,26 @@ ImGuiWindow* ImGui::GetTopMostPopupModal()
|
|
|
return NULL;
|
|
|
}
|
|
|
|
|
|
-void ImGui::OpenPopup(const char* str_id)
|
|
|
+void ImGui::OpenPopup(const char* str_id, ImGuiPopupFlags popup_flags)
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
- OpenPopupEx(g.CurrentWindow->GetID(str_id));
|
|
|
+ OpenPopupEx(g.CurrentWindow->GetID(str_id), popup_flags);
|
|
|
}
|
|
|
|
|
|
// Mark popup as open (toggle toward open state).
|
|
|
// Popups are closed when user click outside, or activate a pressable item, or CloseCurrentPopup() is called within a BeginPopup()/EndPopup() block.
|
|
|
// Popup identifiers are relative to the current ID-stack (so OpenPopup and BeginPopup needs to be at the same level).
|
|
|
// One open popup per level of the popup hierarchy (NB: when assigning we reset the Window member of ImGuiPopupRef to NULL)
|
|
|
-void ImGui::OpenPopupEx(ImGuiID id)
|
|
|
+void ImGui::OpenPopupEx(ImGuiID id, ImGuiPopupFlags popup_flags)
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
ImGuiWindow* parent_window = g.CurrentWindow;
|
|
|
- int current_stack_size = g.BeginPopupStack.Size;
|
|
|
+ const int current_stack_size = g.BeginPopupStack.Size;
|
|
|
+
|
|
|
+ if (popup_flags & ImGuiPopupFlags_NoOpenOverExistingPopup)
|
|
|
+ if (IsPopupOpen(0u, ImGuiPopupFlags_AnyPopupId))
|
|
|
+ return;
|
|
|
+
|
|
|
ImGuiPopupData popup_ref; // Tagged as new ref as Window will be set back to NULL if we write this into OpenPopupStack.
|
|
|
popup_ref.PopupId = id;
|
|
|
popup_ref.Window = NULL;
|
|
|
@@ -7799,10 +7720,11 @@ void ImGui::CloseCurrentPopup()
|
|
|
window->DC.NavHideHighlightOneFrame = true;
|
|
|
}
|
|
|
|
|
|
+// Attention! BeginPopup() adds default flags which BeginPopupEx()!
|
|
|
bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags flags)
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
- if (!IsPopupOpen(id))
|
|
|
+ if (!IsPopupOpen(id, ImGuiPopupFlags_None))
|
|
|
{
|
|
|
g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
|
|
|
return false;
|
|
|
@@ -7841,18 +7763,19 @@ bool ImGui::BeginPopupModal(const char* name, bool* p_open, ImGuiWindowFlags fla
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
ImGuiWindow* window = g.CurrentWindow;
|
|
|
const ImGuiID id = window->GetID(name);
|
|
|
- if (!IsPopupOpen(id))
|
|
|
+ if (!IsPopupOpen(id, ImGuiPopupFlags_None))
|
|
|
{
|
|
|
g.NextWindowData.ClearFlags(); // We behave like Begin() and need to consume those values
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- // Center modal windows by default
|
|
|
+ // Center modal windows by default for increased visibility
|
|
|
+ // (this won't really last as settings will kick in, and is mostly for backward compatibility. user may do the same themselves)
|
|
|
// FIXME: Should test for (PosCond & window->SetWindowPosAllowFlags) with the upcoming window.
|
|
|
if ((g.NextWindowData.Flags & ImGuiNextWindowDataFlags_HasPos) == 0)
|
|
|
- SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));
|
|
|
+ SetNextWindowPos(g.IO.DisplaySize * 0.5f, ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
|
|
|
|
|
|
- flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoSavedSettings;
|
|
|
+ flags |= ImGuiWindowFlags_Popup | ImGuiWindowFlags_Modal | ImGuiWindowFlags_NoCollapse;
|
|
|
const bool is_open = Begin(name, p_open, flags);
|
|
|
if (!is_open || (p_open && !*p_open)) // NB: is_open can be 'false' when the popup is completely clipped (e.g. zero size display)
|
|
|
{
|
|
|
@@ -7883,14 +7806,15 @@ void ImGui::EndPopup()
|
|
|
g.WithinEndChild = false;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::OpenPopupContextItem(const char* str_id, ImGuiMouseButton mouse_button)
|
|
|
+bool ImGui::OpenPopupContextItem(const char* str_id, ImGuiPopupFlags popup_flags)
|
|
|
{
|
|
|
ImGuiWindow* window = GImGui->CurrentWindow;
|
|
|
+ int mouse_button = (popup_flags & ImGuiPopupFlags_MouseButtonMask_);
|
|
|
if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
|
|
|
{
|
|
|
ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict!
|
|
|
IM_ASSERT(id != 0); // You cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item)
|
|
|
- OpenPopupEx(id);
|
|
|
+ OpenPopupEx(id, popup_flags);
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
@@ -7901,39 +7825,42 @@ bool ImGui::OpenPopupContextItem(const char* str_id, ImGuiMouseButton mouse_butt
|
|
|
// - You may want to handle this on user side if you have specific needs (e.g. tweaking IsItemHovered() parameters).
|
|
|
// - This is essentially the same as calling OpenPopupContextItem() + BeginPopup() but written to avoid
|
|
|
// computing the ID twice because BeginPopupContextXXX functions are called very frequently.
|
|
|
-bool ImGui::BeginPopupContextItem(const char* str_id, ImGuiMouseButton mouse_button)
|
|
|
+bool ImGui::BeginPopupContextItem(const char* str_id, ImGuiPopupFlags popup_flags)
|
|
|
{
|
|
|
ImGuiWindow* window = GImGui->CurrentWindow;
|
|
|
if (window->SkipItems)
|
|
|
return false;
|
|
|
ImGuiID id = str_id ? window->GetID(str_id) : window->DC.LastItemId; // If user hasn't passed an ID, we can use the LastItemID. Using LastItemID as a Popup ID won't conflict!
|
|
|
IM_ASSERT(id != 0); // You cannot pass a NULL str_id if the last item has no identifier (e.g. a Text() item)
|
|
|
+ int mouse_button = (popup_flags & ImGuiPopupFlags_MouseButtonMask_);
|
|
|
if (IsMouseReleased(mouse_button) && IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
|
|
|
- OpenPopupEx(id);
|
|
|
+ OpenPopupEx(id, popup_flags);
|
|
|
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::BeginPopupContextWindow(const char* str_id, ImGuiMouseButton mouse_button, bool also_over_items)
|
|
|
+bool ImGui::BeginPopupContextWindow(const char* str_id, ImGuiPopupFlags popup_flags)
|
|
|
{
|
|
|
ImGuiWindow* window = GImGui->CurrentWindow;
|
|
|
if (!str_id)
|
|
|
str_id = "window_context";
|
|
|
ImGuiID id = window->GetID(str_id);
|
|
|
+ int mouse_button = (popup_flags & ImGuiPopupFlags_MouseButtonMask_);
|
|
|
if (IsMouseReleased(mouse_button) && IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup))
|
|
|
- if (also_over_items || !IsAnyItemHovered())
|
|
|
- OpenPopupEx(id);
|
|
|
+ if (!(popup_flags & ImGuiPopupFlags_NoOpenOverItems) || !IsAnyItemHovered())
|
|
|
+ OpenPopupEx(id, popup_flags);
|
|
|
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::BeginPopupContextVoid(const char* str_id, ImGuiMouseButton mouse_button)
|
|
|
+bool ImGui::BeginPopupContextVoid(const char* str_id, ImGuiPopupFlags popup_flags)
|
|
|
{
|
|
|
ImGuiWindow* window = GImGui->CurrentWindow;
|
|
|
if (!str_id)
|
|
|
str_id = "void_context";
|
|
|
ImGuiID id = window->GetID(str_id);
|
|
|
+ int mouse_button = (popup_flags & ImGuiPopupFlags_MouseButtonMask_);
|
|
|
if (IsMouseReleased(mouse_button) && !IsWindowHovered(ImGuiHoveredFlags_AnyWindow))
|
|
|
if (GetTopMostPopupModal() == NULL)
|
|
|
- OpenPopupEx(id);
|
|
|
+ OpenPopupEx(id, popup_flags);
|
|
|
return BeginPopupEx(id, ImGuiWindowFlags_AlwaysAutoResize|ImGuiWindowFlags_NoTitleBar|ImGuiWindowFlags_NoSavedSettings);
|
|
|
}
|
|
|
|