Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 5360903
Author: ocornut <omarcornut@gmail.com>
Date:   Fri Feb 9 16:33:42 2024 +0100

    Version 1.90.2

commit 7b5357d
Author: ocornut <omarcornut@gmail.com>
Date:   Fri Feb 9 16:17:59 2024 +0100

    Debug Tools: Metrics: Improved Monitors and Viewports minimap display. Highlight on hover.

    Added ImGuiViewport ID in Master branch.

commit 70aa717
Author: ocornut <omarcornut@gmail.com>
Date:   Fri Feb 9 15:23:43 2024 +0100

    Combo: Fixed not reusing windows optimally when used inside a popup stack.

commit 5cdc4a2
Author: ocornut <omarcornut@gmail.com>
Date:   Fri Feb 9 14:20:12 2024 +0100

    Demo: use ImGui::MemAlloc/MemFree for consistency. (ocornut#7300)

commit 76e09c4
Author: ocornut <omarcornut@gmail.com>
Date:   Thu Feb 8 17:08:01 2024 +0100

    ClosePopupsOverWindow(): amend to remove _ChildWindow test.

    Said test seems unnecessary and incorrect as we test hierarchy now. See test "nav_ctrl_tab_popups" in ImGuiTestSuite.

commit 3a07846
Author: ocornut <omarcornut@gmail.com>
Date:   Thu Feb 8 16:06:55 2024 +0100

    Nav: ImGuiWindowFlags_NoNavInputs is tested during scoring so NavFlattened windows can use it.

commit 7d67623
Author: ocornut <omarcornut@gmail.com>
Date:   Thu Feb 8 15:46:17 2024 +0100

    InputText: Internal: ReloadUserBufXXX functions don't override revert value. (ocornut#2890) fix accidental comment.

commit a5e0e90
Author: ocornut <omarcornut@gmail.com>
Date:   Thu Feb 8 15:44:46 2024 +0100

    Nav: tweak RenderNavHighlight() syntax. ImGuiNavHighlightFlags_TypeThin -> ImGuiNavHighlightFlags_Compact.
  • Loading branch information
simdax committed Feb 12, 2024
1 parent f4bcf1f commit e7f8128
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 57 deletions.
15 changes: 11 additions & 4 deletions docs/CHANGELOG.txt
Expand Up @@ -36,9 +36,11 @@ HOW TO UPDATE?
- Please report any issue!

-----------------------------------------------------------------------
VERSION 1.90.2 WIP (In Progress)
VERSION 1.90.2 (Released 2024-01-09)
-----------------------------------------------------------------------

Decorated log and release notes: https://github.com/ocornut/imgui/releases/tag/v1.90.2

Breaking changes:

- Commented out ImGuiIO::ImeWindowHandle obsoleted in 1.87 in favor of writing
Expand All @@ -55,15 +57,20 @@ Other changes:
regression from 1.90.1 related to code scoping Tab presses to local scope. (#7226) [@bratpilz]
- Nav: Fixed pressing Escape while in a child window with _NavFlattened flag. (#7237)
- Nav: Improve handling of Alt key to toggle menu so that key ownership may be claimed on
indiviudal left/right alt key without intefering with the other.
individual left/right alt key without interfering with the other.
- Nav, Menus: Fixed click on a BeginMenu() followed by right-arrow from making the child menu
reopen and flicker (using ImGuiPopupFlags_NoReopen).
- OpenPopup(): Added ImGuiPopupFlags_NoReopen flag to specifically not close nd reopen a popup
when it is already open. (#1497, #1533)
- Nav: ImGuiWindowFlags_NoNavInputs is tested during scoring so NavFlattened windows can use it.
- Popups: OpenPopup(): added ImGuiPopupFlags_NoReopen flag to specifically not close and reopen
a popup when it is already open. (#1497, #1533)
(Note that this differs from specific handling we already have in place for the case of calling
OpenPopup() repeatedly every frame: we already didn't reopen in that specific situation, otherwise
the effect would be very disastrous in term of confusion, as reopening would steal focus).
- Popups: Slight change to popup closing logic (e.g. after focusing another window) which skipped
over popups that are also child windows.
- Combo: Fixed not reusing windows optimally when used inside a popup stack.
- Debug Tools: Metrics: Fixed debug break in SetShortcutRouting() not handling ImGuiMod_Shortcut redirect.
- Debug Tools: Metrics: Improved Monitors and Viewports minimap display. Highlight on hover.
- Debug Tools: Debug Log: Added "Input Routing" logging.
- Debug Tools: Added "nop" to IM_DEBUG_BREAK macro on GCC to work around GDB bug (#7266) [@Peter0x44]
- Backends: Vulkan: Fixed vkAcquireNextImageKHR() validation errors in VulkanSDK 1.3.275 by
Expand Down
73 changes: 43 additions & 30 deletions imgui.cpp
@@ -1,4 +1,4 @@
// dear imgui, v1.90.2 WIP
// dear imgui, v1.90.2
// (main code and documentation)

// Help:
Expand Down Expand Up @@ -1126,6 +1126,7 @@ static void RenderDimmedBackgroundBehindWindow(ImGuiWindow* window,
static void RenderDimmedBackgrounds();

// Viewports
const ImGuiID IMGUI_VIEWPORT_DEFAULT_ID = 0x11111111; // Using an arbitrary constant instead of e.g. ImHashStr("ViewportDefault", 0); so it's easier to spot in the debugger. The exact value doesn't matter.
static void UpdateViewportsNewFrame();

}
Expand Down Expand Up @@ -3452,22 +3453,22 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl
float rounding = (flags & ImGuiNavHighlightFlags_NoRounding) ? 0.0f : g.Style.FrameRounding;
ImRect display_rect = bb;
display_rect.ClipWith(window->ClipRect);
if (flags & ImGuiNavHighlightFlags_TypeDefault)
const float thickness = 2.0f;
if (flags & ImGuiNavHighlightFlags_Compact)
{
const float THICKNESS = 2.0f;
const float DISTANCE = 3.0f + THICKNESS * 0.5f;
display_rect.Expand(ImVec2(DISTANCE, DISTANCE));
window->DrawList->AddRect(display_rect.Min, display_rect.Max, GetColorU32(ImGuiCol_NavHighlight), rounding, 0, thickness);
}
else
{
const float distance = 3.0f + thickness * 0.5f;
display_rect.Expand(ImVec2(distance, distance));
bool fully_visible = window->ClipRect.Contains(display_rect);
if (!fully_visible)
window->DrawList->PushClipRect(display_rect.Min, display_rect.Max);
window->DrawList->AddRect(display_rect.Min + ImVec2(THICKNESS * 0.5f, THICKNESS * 0.5f), display_rect.Max - ImVec2(THICKNESS * 0.5f, THICKNESS * 0.5f), GetColorU32(ImGuiCol_NavHighlight), rounding, 0, THICKNESS);
window->DrawList->AddRect(display_rect.Min, display_rect.Max, GetColorU32(ImGuiCol_NavHighlight), rounding, 0, thickness);
if (!fully_visible)
window->DrawList->PopClipRect();
}
if (flags & ImGuiNavHighlightFlags_TypeThin)
{
window->DrawList->AddRect(display_rect.Min, display_rect.Max, GetColorU32(ImGuiCol_NavHighlight), rounding, 0, 1.0f);
}
}

void ImGui::RenderMouseCursor(ImVec2 base_pos, float base_scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow)
Expand Down Expand Up @@ -3596,6 +3597,7 @@ void ImGui::Initialize()

// Create default viewport
ImGuiViewportP* viewport = IM_NEW(ImGuiViewportP)();
viewport->ID = IMGUI_VIEWPORT_DEFAULT_ID;
g.Viewports.push_back(viewport);
g.TempBuffer.resize(1024 * 3 + 1, 0);

Expand Down Expand Up @@ -5543,7 +5545,7 @@ void ImGui::EndChild()

// When browsing a window that has no activable items (scroll only) we keep a highlight on the child (pass g.NavId to trick into always displaying)
if (child_window->DC.NavLayersActiveMask == 0 && child_window == g.NavWindow)
RenderNavHighlight(ImRect(bb.Min - ImVec2(2, 2), bb.Max + ImVec2(2, 2)), g.NavId, ImGuiNavHighlightFlags_TypeThin);
RenderNavHighlight(ImRect(bb.Min - ImVec2(2, 2), bb.Max + ImVec2(2, 2)), g.NavId, ImGuiNavHighlightFlags_Compact);
}
else
{
Expand Down Expand Up @@ -6434,7 +6436,7 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
window_stack_data.StackSizesOnBegin.SetToContextState(&g);
g.CurrentWindowStack.push_back(window_stack_data);
if (flags & ImGuiWindowFlags_ChildMenu)
g.BeginMenuCount++;
g.BeginMenuDepth++;

// Update ->RootWindow and others pointers (before any possible call to FocusWindow)
if (first_begin_of_the_frame)
Expand Down Expand Up @@ -7106,7 +7108,7 @@ void ImGui::End()
// Pop from window stack
g.LastItemData = g.CurrentWindowStack.back().ParentLastItemDataBackup;
if (window->Flags & ImGuiWindowFlags_ChildMenu)
g.BeginMenuCount--;
g.BeginMenuDepth--;
if (window->Flags & ImGuiWindowFlags_Popup)
g.BeginPopupStack.pop_back();
g.CurrentWindowStack.back().StackSizesOnBegin.CompareWithContextState(&g);
Expand Down Expand Up @@ -10819,14 +10821,15 @@ void ImGui::ClosePopupsOverWindow(ImGuiWindow* ref_window, bool restore_focus_to
if (!popup.Window)
continue;
IM_ASSERT((popup.Window->Flags & ImGuiWindowFlags_Popup) != 0);
if (popup.Window->Flags & ImGuiWindowFlags_ChildWindow)
continue;

// Trim the stack unless the popup is a direct parent of the reference window (the reference window is often the NavWindow)
// - With this stack of window, clicking/focusing Popup1 will close Popup2 and Popup3:
// Window -> Popup1 -> Popup2 -> Popup3
// - Clicking/Focusing Window2 won't close Popup1:
// Window -> Popup1 -> Window2(Ref)
// - Clicking/focusing Popup1 will close Popup2 and Popup3:
// Window -> Popup1(Ref) -> Popup2 -> Popup3
// - Each popups may contain child windows, which is why we compare ->RootWindow!
// Window -> Popup1 -> Popup1_Child -> Popup2 -> Popup2_Child
// We step through every popup from bottom to top to validate their position relative to reference window.
bool ref_window_is_descendent_of_popup = false;
for (int n = popup_count_to_keep; n < g.OpenPopupStack.Size; n++)
if (ImGuiWindow* popup_window = g.OpenPopupStack[n].Window)
Expand Down Expand Up @@ -10925,7 +10928,7 @@ bool ImGui::BeginPopupEx(ImGuiID id, ImGuiWindowFlags flags)

char name[20];
if (flags & ImGuiWindowFlags_ChildMenu)
ImFormatString(name, IM_ARRAYSIZE(name), "##Menu_%02d", g.BeginMenuCount); // Recycle windows based on depth
ImFormatString(name, IM_ARRAYSIZE(name), "##Menu_%02d", g.BeginMenuDepth); // Recycle windows based on depth
else
ImFormatString(name, IM_ARRAYSIZE(name), "##Popup_%08x", id); // Not recycling, so we can close/open during the same frame

Expand Down Expand Up @@ -11509,7 +11512,7 @@ static void ImGui::NavProcessItem()

// Process Move Request (scoring for navigation)
// FIXME-NAV: Consider policy for double scoring (scoring from NavScoringRect + scoring from a rect wrapped according to current wrapping policy)
if (g.NavMoveScoringItems && (item_flags & ImGuiItemFlags_Disabled) == 0)
if (g.NavMoveScoringItems && (item_flags & ImGuiItemFlags_Disabled) == 0 && (window->Flags & ImGuiWindowFlags_NoNavInputs) == 0)
{
const bool is_tabbing = (g.NavMoveFlags & ImGuiNavMoveFlags_IsTabbing) != 0;
if (is_tabbing)
Expand Down Expand Up @@ -13974,7 +13977,7 @@ static void SetPlatformImeDataFn_DefaultImpl(ImGuiViewport*, ImGuiPlatformImeDat
//-----------------------------------------------------------------------------
// [SECTION] METRICS/DEBUGGER WINDOW
//-----------------------------------------------------------------------------
// - RenderViewportThumbnail() [Internal]
// - DebugRenderViewportThumbnail() [Internal]
// - RenderViewportsThumbnails() [Internal]
// - DebugTextEncoding()
// - MetricsHelpMarker() [Internal]
Expand Down Expand Up @@ -14013,7 +14016,7 @@ void ImGui::DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP*
ImRect thumb_r = thumb_window->Rect();
ImRect title_r = thumb_window->TitleBarRect();
thumb_r = ImRect(ImTrunc(off + thumb_r.Min * scale), ImTrunc(off + thumb_r.Max * scale));
title_r = ImRect(ImTrunc(off + title_r.Min * scale), ImTrunc(off + ImVec2(title_r.Max.x, title_r.Min.y) * scale) + ImVec2(0,5)); // Exaggerate title bar height
title_r = ImRect(ImTrunc(off + title_r.Min * scale), ImTrunc(off + ImVec2(title_r.Max.x, title_r.Min.y + title_r.GetHeight() * 3.0f) * scale)); // Exaggerate title bar height
thumb_r.ClipWithFull(bb);
title_r.ClipWithFull(bb);
const bool window_is_focused = (g.NavWindow && thumb_window->RootWindowForTitleBarHighlight == g.NavWindow->RootWindowForTitleBarHighlight);
Expand All @@ -14023,20 +14026,21 @@ void ImGui::DebugRenderViewportThumbnail(ImDrawList* draw_list, ImGuiViewportP*
window->DrawList->AddText(g.Font, g.FontSize * 1.0f, title_r.Min, GetColorU32(ImGuiCol_Text, alpha_mul), thumb_window->Name, FindRenderedTextEnd(thumb_window->Name));
}
draw_list->AddRect(bb.Min, bb.Max, GetColorU32(ImGuiCol_Border, alpha_mul));
if (viewport->ID == g.DebugMetricsConfig.HighlightViewportID)
window->DrawList->AddRect(bb.Min, bb.Max, IM_COL32(255, 255, 0, 255));
}

static void RenderViewportsThumbnails()
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = g.CurrentWindow;

// We don't display full monitor bounds (we could, but it often looks awkward), instead we display just enough to cover all of our viewports.
float SCALE = 1.0f / 8.0f;
ImRect bb_full(FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX);
for (ImGuiViewportP* viewport : g.Viewports)
bb_full.Add(viewport->GetMainRect());
ImRect bb_full(g.Viewports[0]->Pos, g.Viewports[0]->Pos + g.Viewports[0]->Size);
ImVec2 p = window->DC.CursorPos;
ImVec2 off = p - bb_full.Min * SCALE;

// Draw viewports
for (ImGuiViewportP* viewport : g.Viewports)
{
ImRect viewport_draw_bb(off + (viewport->Pos) * SCALE, off + (viewport->Pos + viewport->Size) * SCALE);
Expand Down Expand Up @@ -14279,7 +14283,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
MetricsHelpMarker("Will call the IM_DEBUG_BREAK() macro to break in debugger.\nWarning: If you don't have a debugger attached, this will probably crash.");
if (Checkbox("Show Item Picker", &g.DebugItemPickerActive) && g.DebugItemPickerActive)
DebugStartItemPicker();
Checkbox("Show \"Debug Break\" buttons in other sections", &g.IO.ConfigDebugIsDebuggerPresent);
Checkbox("Show \"Debug Break\" buttons in other sections (io.ConfigDebugIsDebuggerPresent)", &g.IO.ConfigDebugIsDebuggerPresent);

SeparatorText("Visualize");

Expand Down Expand Up @@ -14415,9 +14419,14 @@ void ImGui::ShowMetricsWindow(bool* p_open)
// Viewports
if (TreeNode("Viewports", "Viewports (%d)", g.Viewports.Size))
{
Indent(GetTreeNodeToLabelSpacing());
RenderViewportsThumbnails();
Unindent(GetTreeNodeToLabelSpacing());
SetNextItemOpen(true, ImGuiCond_Once);
if (TreeNode("Windows Minimap"))
{
RenderViewportsThumbnails();
TreePop();
}
cfg->HighlightViewportID = 0;

for (ImGuiViewportP* viewport : g.Viewports)
DebugNodeViewport(viewport);
TreePop();
Expand Down Expand Up @@ -15119,8 +15128,12 @@ void ImGui::DebugNodeTabBar(ImGuiTabBar* tab_bar, const char* label)

void ImGui::DebugNodeViewport(ImGuiViewportP* viewport)
{
ImGuiContext& g = *GImGui;
SetNextItemOpen(true, ImGuiCond_Once);
if (TreeNode("viewport0", "Viewport #%d", 0))
bool open = TreeNode("viewport0", "Viewport #%d", 0);
if (IsItemHovered())
g.DebugMetricsConfig.HighlightViewportID = viewport->ID;
if (open)
{
ImGuiWindowFlags flags = viewport->Flags;
BulletText("Main Pos: (%.0f,%.0f), Size: (%.0f,%.0f)\nWorkArea Offset Left: %.0f Top: %.0f, Right: %.0f, Bottom: %.0f",
Expand Down
7 changes: 4 additions & 3 deletions imgui.h
@@ -1,4 +1,4 @@
// dear imgui, v1.90.2 WIP
// dear imgui, v1.90.2
// (headers)

// Help:
Expand All @@ -23,8 +23,8 @@

// Library Version
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
#define IMGUI_VERSION "1.90.2 WIP"
#define IMGUI_VERSION_NUM 19018
#define IMGUI_VERSION "1.90.2"
#define IMGUI_VERSION_NUM 19020
#define IMGUI_HAS_TABLE

/*
Expand Down Expand Up @@ -3123,6 +3123,7 @@ enum ImGuiViewportFlags_
// - Windows are generally trying to stay within the Work Area of their host viewport.
struct ImGuiViewport
{
ImGuiID ID; // Unique identifier for the viewport
ImGuiViewportFlags Flags; // See ImGuiViewportFlags_
ImVec2 Pos; // Main Area: Position of the viewport (Dear ImGui coordinates are the same as OS desktop/native coordinates)
ImVec2 Size; // Main Area: Size of the viewport.
Expand Down
10 changes: 5 additions & 5 deletions imgui_demo.cpp
@@ -1,4 +1,4 @@
// dear imgui, v1.90.2 WIP
// dear imgui, v1.90.2
// (demo code)

// Help:
Expand Down Expand Up @@ -6997,19 +6997,19 @@ struct ExampleAppConsole
{
ClearLog();
for (int i = 0; i < History.Size; i++)
free(History[i]);
ImGui::MemFree(History[i]);
}

// Portable helpers
static int Stricmp(const char* s1, const char* s2) { int d; while ((d = toupper(*s2) - toupper(*s1)) == 0 && *s1) { s1++; s2++; } return d; }
static int Strnicmp(const char* s1, const char* s2, int n) { int d = 0; while (n > 0 && (d = toupper(*s2) - toupper(*s1)) == 0 && *s1) { s1++; s2++; n--; } return d; }
static char* Strdup(const char* s) { IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = malloc(len); IM_ASSERT(buf); return (char*)memcpy(buf, (const void*)s, len); }
static char* Strdup(const char* s) { IM_ASSERT(s); size_t len = strlen(s) + 1; void* buf = ImGui::MemAlloc(len); IM_ASSERT(buf); return (char*)memcpy(buf, (const void*)s, len); }
static void Strtrim(char* s) { char* str_end = s + strlen(s); while (str_end > s && str_end[-1] == ' ') str_end--; *str_end = 0; }

void ClearLog()
{
for (int i = 0; i < Items.Size; i++)
free(Items[i]);
ImGui::MemFree(Items[i]);
Items.clear();
}

Expand Down Expand Up @@ -7175,7 +7175,7 @@ struct ExampleAppConsole
for (int i = History.Size - 1; i >= 0; i--)
if (Stricmp(History[i], command_line) == 0)
{
free(History[i]);
ImGui::MemFree(History[i]);
History.erase(History.begin() + i);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion imgui_draw.cpp
@@ -1,4 +1,4 @@
// dear imgui, v1.90.2 WIP
// dear imgui, v1.90.2
// (drawing and font code)

/*
Expand Down

0 comments on commit e7f8128

Please sign in to comment.