From 97b1abd6ddfb38d4b57835152b5b736442e4d15d Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 8 Feb 2022 12:22:46 +0100 Subject: [PATCH 01/15] Internals: rework RenderMouseCursor() signature so we can use it in docking branch more naturally. --- imgui.cpp | 34 ++++++++++++++++++++++++++++++---- imgui.h | 2 +- imgui_draw.cpp | 22 ---------------------- imgui_internal.h | 2 +- 4 files changed, 32 insertions(+), 28 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index efa69604..aca93389 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3193,6 +3193,32 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl } } +void ImGui::RenderMouseCursor(ImVec2 base_pos, float base_scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow) +{ + ImGuiContext& g = *GImGui; + IM_ASSERT(mouse_cursor > ImGuiMouseCursor_None && mouse_cursor < ImGuiMouseCursor_COUNT); + for (int n = 0; n < g.Viewports.Size; n++) + { + ImGuiViewportP* viewport = g.Viewports[n]; + ImDrawList* draw_list = GetForegroundDrawList(viewport); + ImFontAtlas* font_atlas = draw_list->_Data->Font->ContainerAtlas; + ImVec2 offset, size, uv[4]; + if (font_atlas->GetMouseCursorTexData(mouse_cursor, &offset, &size, &uv[0], &uv[2])) + { + const ImVec2 pos = base_pos - offset; + const float scale = base_scale; + ImTextureID tex_id = font_atlas->TexID; + draw_list->PushTextureID(tex_id); + draw_list->AddImage(tex_id, pos + ImVec2(1, 0) * scale, pos + (ImVec2(1, 0) + size) * scale, uv[2], uv[3], col_shadow); + draw_list->AddImage(tex_id, pos + ImVec2(2, 0) * scale, pos + (ImVec2(2, 0) + size) * scale, uv[2], uv[3], col_shadow); + draw_list->AddImage(tex_id, pos, pos + size * scale, uv[2], uv[3], col_border); + draw_list->AddImage(tex_id, pos, pos + size * scale, uv[0], uv[1], col_fill); + draw_list->PopTextureID(); + } + } +} + + //----------------------------------------------------------------------------- // [SECTION] MAIN CODE (most of the code! lots of stuff, needs tidying up!) //----------------------------------------------------------------------------- @@ -4888,6 +4914,10 @@ void ImGui::Render() if (windows_to_render_top_most[n] && IsWindowActiveAndVisible(windows_to_render_top_most[n])) // NavWindowingTarget is always temporarily displayed as the top-most window AddRootWindowToDrawData(windows_to_render_top_most[n]); + // Draw software mouse cursor if requested by io.MouseDrawCursor flag + if (g.IO.MouseDrawCursor && first_render_of_frame && g.MouseCursor != ImGuiMouseCursor_None) + RenderMouseCursor(g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); + // Setup ImDrawData structures for end-user g.IO.MetricsRenderVertices = g.IO.MetricsRenderIndices = 0; for (int n = 0; n < g.Viewports.Size; n++) @@ -4895,10 +4925,6 @@ void ImGui::Render() ImGuiViewportP* viewport = g.Viewports[n]; viewport->DrawDataBuilder.FlattenIntoSingleLayer(); - // Draw software mouse cursor if requested by io.MouseDrawCursor flag - if (g.IO.MouseDrawCursor && first_render_of_frame) - RenderMouseCursor(GetForegroundDrawList(viewport), g.IO.MousePos, g.Style.MouseCursorScale, g.MouseCursor, IM_COL32_WHITE, IM_COL32_BLACK, IM_COL32(0, 0, 0, 48)); - // Add foreground ImDrawList (for each active viewport) if (viewport->DrawLists[1] != NULL) AddDrawListToDrawData(&viewport->DrawDataBuilder.Layers[0], GetForegroundDrawList(viewport)); diff --git a/imgui.h b/imgui.h index 871b75f0..fa591efa 100644 --- a/imgui.h +++ b/imgui.h @@ -65,7 +65,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.87" -#define IMGUI_VERSION_NUM 18700 +#define IMGUI_VERSION_NUM 18701 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE diff --git a/imgui_draw.cpp b/imgui_draw.cpp index a99e6b24..1633ec22 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -3736,7 +3736,6 @@ void ImFont::RenderText(ImDrawList* draw_list, float size, ImVec2 pos, ImU32 col // - RenderArrow() // - RenderBullet() // - RenderCheckMark() -// - RenderMouseCursor() // - RenderArrowPointingAt() // - RenderRectFilledRangeH() // - RenderRectFilledWithHole() @@ -3797,27 +3796,6 @@ void ImGui::RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float draw_list->PathStroke(col, 0, thickness); } -void ImGui::RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow) -{ - if (mouse_cursor == ImGuiMouseCursor_None) - return; - IM_ASSERT(mouse_cursor > ImGuiMouseCursor_None && mouse_cursor < ImGuiMouseCursor_COUNT); - - ImFontAtlas* font_atlas = draw_list->_Data->Font->ContainerAtlas; - ImVec2 offset, size, uv[4]; - if (font_atlas->GetMouseCursorTexData(mouse_cursor, &offset, &size, &uv[0], &uv[2])) - { - pos -= offset; - ImTextureID tex_id = font_atlas->TexID; - draw_list->PushTextureID(tex_id); - draw_list->AddImage(tex_id, pos + ImVec2(1, 0) * scale, pos + (ImVec2(1, 0) + size) * scale, uv[2], uv[3], col_shadow); - draw_list->AddImage(tex_id, pos + ImVec2(2, 0) * scale, pos + (ImVec2(2, 0) + size) * scale, uv[2], uv[3], col_shadow); - draw_list->AddImage(tex_id, pos, pos + size * scale, uv[2], uv[3], col_border); - draw_list->AddImage(tex_id, pos, pos + size * scale, uv[0], uv[1], col_fill); - draw_list->PopTextureID(); - } -} - // Render an arrow. 'pos' is position of the arrow tip. half_sz.x is length from base to tip. half_sz.y is length on each side. void ImGui::RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col) { diff --git a/imgui_internal.h b/imgui_internal.h index baa4a4de..2058da9f 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -2760,12 +2760,12 @@ namespace ImGui IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, ImDrawFlags flags = 0); IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight IMGUI_API const char* FindRenderedTextEnd(const char* text, const char* text_end = NULL); // Find the optional ## from which we stop displaying text. + IMGUI_API void RenderMouseCursor(ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow); // Render helpers (those functions don't access any ImGui state!) IMGUI_API void RenderArrow(ImDrawList* draw_list, ImVec2 pos, ImU32 col, ImGuiDir dir, float scale = 1.0f); IMGUI_API void RenderBullet(ImDrawList* draw_list, ImVec2 pos, ImU32 col); IMGUI_API void RenderCheckMark(ImDrawList* draw_list, ImVec2 pos, ImU32 col, float sz); - IMGUI_API void RenderMouseCursor(ImDrawList* draw_list, ImVec2 pos, float scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow); IMGUI_API void RenderArrowPointingAt(ImDrawList* draw_list, ImVec2 pos, ImVec2 half_sz, ImGuiDir direction, ImU32 col); IMGUI_API void RenderRectFilledRangeH(ImDrawList* draw_list, const ImRect& rect, ImU32 col, float x_start_norm, float x_end_norm, float rounding); IMGUI_API void RenderRectFilledWithHole(ImDrawList* draw_list, ImRect outer, ImRect inner, ImU32 col, float rounding); From 88de9820716b9e2751bc49e6bbac82196b7caf67 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 8 Feb 2022 14:44:06 +0100 Subject: [PATCH 02/15] Version 1.88 WIP --- docs/CHANGELOG.txt | 10 +++++++++- imgui.cpp | 2 +- imgui.h | 6 +++--- imgui_demo.cpp | 2 +- imgui_draw.cpp | 2 +- imgui_internal.h | 2 +- imgui_tables.cpp | 2 +- imgui_widgets.cpp | 2 +- 8 files changed, 18 insertions(+), 10 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 3b7fe232..1f545cd7 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -31,6 +31,15 @@ HOW TO UPDATE? - Please report any issue! +----------------------------------------------------------------------- + VERSION 1.88 WIP (In Progress) +----------------------------------------------------------------------- + +Breaking changes: + +Other Changes: + + ----------------------------------------------------------------------- VERSION 1.87 (Released 2022-02-07) ----------------------------------------------------------------------- @@ -103,7 +112,6 @@ Breaking Changes: better support for IME. Updated backends accordingly. Because the old field is set by existing backends, we are keeping it (marked as obsolete). - Other Changes: - IO: Added event based input queue API, which now trickles events to support low framerates. [@thedmd, @ocornut] diff --git a/imgui.cpp b/imgui.cpp index aca93389..31baf466 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.87 +// dear imgui, 1.88 WIP // (main code and documentation) // Help: diff --git a/imgui.h b/imgui.h index fa591efa..9b8d4ff4 100644 --- a/imgui.h +++ b/imgui.h @@ -1,4 +1,4 @@ -// dear imgui, v1.87 +// dear imgui, v1.88 WIP // (headers) // Help: @@ -64,8 +64,8 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) -#define IMGUI_VERSION "1.87" -#define IMGUI_VERSION_NUM 18701 +#define IMGUI_VERSION "1.88 WIP" +#define IMGUI_VERSION_NUM 18702 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 72d98caa..c8c92f1d 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.87 +// dear imgui, v1.88 WIP // (demo code) // Help: diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 1633ec22..95a2298f 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.87 +// dear imgui, v1.88 WIP // (drawing and font code) /* diff --git a/imgui_internal.h b/imgui_internal.h index 2058da9f..19852942 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1,4 +1,4 @@ -// dear imgui, v1.87 +// dear imgui, v1.88 WIP // (internal structures/api) // You may use this file to debug, understand or extend ImGui features but we don't provide any guarantee of forward compatibility! diff --git a/imgui_tables.cpp b/imgui_tables.cpp index 27f1d538..def61f44 100644 --- a/imgui_tables.cpp +++ b/imgui_tables.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.87 +// dear imgui, v1.88 WIP // (tables and columns code) /* diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 56723cdd..87698bf9 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -1,4 +1,4 @@ -// dear imgui, v1.87 +// dear imgui, v1.88 WIP // (widgets code) /* From aa79d0cd2f72bb0abe979c4dd81a754b6d51a713 Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 8 Feb 2022 14:45:57 +0100 Subject: [PATCH 03/15] Stack Tool: Added option to copy item path to clipboard. (#4631) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 73 ++++++++++++++++++++++++++++++++-------------- imgui_internal.h | 7 +++-- 3 files changed, 58 insertions(+), 24 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 1f545cd7..4aef8a3c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -39,6 +39,8 @@ Breaking changes: Other Changes: +- Stack Tool: Added option to copy item path to clipboard. (#4631) + ----------------------------------------------------------------------- VERSION 1.87 (Released 2022-02-07) diff --git a/imgui.cpp b/imgui.cpp index 31baf466..be040665 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -13026,27 +13026,44 @@ void ImGui::DebugHookIdInfo(ImGuiID id, ImGuiDataType data_type, const void* dat ImGuiStackLevelInfo* info = &tool->Results[tool->StackLevel]; IM_ASSERT(info->ID == id && info->QueryFrameCount > 0); - int data_len; switch (data_type) { case ImGuiDataType_S32: ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "%d", (int)(intptr_t)data_id); break; case ImGuiDataType_String: - data_len = data_id_end ? (int)((const char*)data_id_end - (const char*)data_id) : (int)strlen((const char*)data_id); - ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "\"%.*s\"", data_len, (const char*)data_id); + ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "%.*s", data_id_end ? (int)((const char*)data_id_end - (const char*)data_id) : (int)strlen((const char*)data_id), (const char*)data_id); break; case ImGuiDataType_Pointer: ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "(void*)0x%p", data_id); break; case ImGuiDataType_ID: - if (info->Desc[0] == 0) // PushOverrideID() is often used to avoid hashing twice, which would lead to 2 calls to DebugHookIdInfo(). We prioritize the first one. - ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "0x%08X [override]", id); + if (info->Desc[0] != 0) // PushOverrideID() is often used to avoid hashing twice, which would lead to 2 calls to DebugHookIdInfo(). We prioritize the first one. + return; + ImFormatString(info->Desc, IM_ARRAYSIZE(info->Desc), "0x%08X [override]", id); break; default: IM_ASSERT(0); } info->QuerySuccess = true; + info->DataType = data_type; +} + +static int StackToolFormatLevelInfo(ImGuiStackTool* tool, int n, bool format_for_ui, char* buf, size_t buf_size) +{ + ImGuiStackLevelInfo* info = &tool->Results[n]; + ImGuiWindow* window = (info->Desc[0] == 0 && n == 0) ? ImGui::FindWindowByID(info->ID) : NULL; + if (window) // Source: window name (because the root ID don't call GetID() and so doesn't get hooked) + return ImFormatString(buf, buf_size, format_for_ui ? "\"%s\" [window]" : "%s", window->Name); + if (info->QuerySuccess) // Source: GetID() hooks (prioritize over ItemInfo() because we frequently use patterns like: PushID(str), Button("") where they both have same id) + return ImFormatString(buf, buf_size, (format_for_ui && info->DataType == ImGuiDataType_String) ? "\"%s\"" : "%s", info->Desc); + if (tool->StackLevel < tool->Results.Size) // Only start using fallback below when all queries are done, so during queries we don't flickering ??? markers. + return (*buf = 0); +#ifdef IMGUI_ENABLE_TEST_ENGINE + if (const char* label = ImGuiTestEngine_FindItemDebugLabel(GImGui, info->ID)) // Source: ImGuiTestEngine's ItemInfo() + return ImFormatString(buf, buf_size, format_for_ui ? "??? \"%s\"" : "%s", label); +#endif + return ImFormatString(buf, buf_size, "???"); } // Stack Tool: Display UI @@ -13062,6 +13079,7 @@ void ImGui::ShowStackToolWindow(bool* p_open) } // Display hovered/active status + ImGuiStackTool* tool = &g.DebugStackTool; const ImGuiID hovered_id = g.HoveredIdPreviousFrame; const ImGuiID active_id = g.ActiveId; #ifdef IMGUI_ENABLE_TEST_ENGINE @@ -13072,8 +13090,33 @@ void ImGui::ShowStackToolWindow(bool* p_open) SameLine(); MetricsHelpMarker("Hover an item with the mouse to display elements of the ID Stack leading to the item's final ID.\nEach level of the stack correspond to a PushID() call.\nAll levels of the stack are hashed together to make the final ID of a widget (ID displayed at the bottom level of the stack).\nRead FAQ entry about the ID stack for details."); + // CTRL+C to copy path + const float time_since_copy = (float)g.Time - tool->CopyToClipboardLastTime; + Checkbox("Ctrl+C: copy path to clipboard", &tool->CopyToClipboardOnCtrlC); + SameLine(); + TextColored((time_since_copy >= 0.0f && time_since_copy < 0.75f && ImFmod(time_since_copy, 0.25f) < 0.25f * 0.5f) ? ImVec4(1.f, 1.f, 0.3f, 1.f) : ImVec4(), "*COPIED*"); + if (tool->CopyToClipboardOnCtrlC && IsKeyDown(ImGuiKey_ModCtrl) && IsKeyPressed(ImGuiKey_C)) + { + tool->CopyToClipboardLastTime = (float)g.Time; + char* p = g.TempBuffer; + char* p_end = p + IM_ARRAYSIZE(g.TempBuffer); + for (int stack_n = 0; stack_n < tool->Results.Size && p + 3 < p_end; stack_n++) + { + *p++ = '/'; + char level_desc[256]; + StackToolFormatLevelInfo(tool, stack_n, false, level_desc, IM_ARRAYSIZE(level_desc)); + for (int n = 0; level_desc[n] && p + 2 < p_end; n++) + { + if (level_desc[n] == '/') + *p++ = '\\'; + *p++ = level_desc[n]; + } + } + *p = '\0'; + SetClipboardText(g.TempBuffer); + } + // Display decorated stack - ImGuiStackTool* tool = &g.DebugStackTool; tool->LastActiveFrame = g.FrameCount; if (tool->Results.Size > 0 && BeginTable("##table", 3, ImGuiTableFlags_Borders)) { @@ -13087,23 +13130,9 @@ void ImGui::ShowStackToolWindow(bool* p_open) ImGuiStackLevelInfo* info = &tool->Results[n]; TableNextColumn(); Text("0x%08X", (n > 0) ? tool->Results[n - 1].ID : 0); - TableNextColumn(); - ImGuiWindow* window = (info->Desc[0] == 0 && n == 0) ? FindWindowByID(info->ID) : NULL; - if (window) // Source: window name (because the root ID don't call GetID() and so doesn't get hooked) - Text("\"%s\" [window]", window->Name); - else if (info->QuerySuccess) // Source: GetID() hooks (prioritize over ItemInfo() because we frequently use patterns like: PushID(str), Button("") where they both have same id) - TextUnformatted(info->Desc); - else if (tool->StackLevel >= tool->Results.Size) // Only start using fallback below when all queries are done, so during queries we don't flickering ??? markers. - { -#ifdef IMGUI_ENABLE_TEST_ENGINE - if (const char* label = ImGuiTestEngine_FindItemDebugLabel(&g, info->ID)) // Source: ImGuiTestEngine's ItemInfo() - Text("??? \"%s\"", label); - else -#endif - TextUnformatted("???"); - } - + StackToolFormatLevelInfo(tool, n, true, g.TempBuffer, IM_ARRAYSIZE(g.TempBuffer)); + TextUnformatted(g.TempBuffer); TableNextColumn(); Text("0x%08X", info->ID); if (n == tool->Results.Size - 1) diff --git a/imgui_internal.h b/imgui_internal.h index 19852942..12bc7dfc 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -1510,7 +1510,8 @@ struct ImGuiStackLevelInfo ImGuiID ID; ImS8 QueryFrameCount; // >= 1: Query in progress bool QuerySuccess; // Obtained result from DebugHookIdInfo() - char Desc[58]; // Arbitrarily sized buffer to hold a result (FIXME: could replace Results[] with a chunk stream?) + ImGuiDataType DataType : 8; + char Desc[57]; // Arbitrarily sized buffer to hold a result (FIXME: could replace Results[] with a chunk stream?) FIXME: Now that we added CTRL+C this should be fixed. ImGuiStackLevelInfo() { memset(this, 0, sizeof(*this)); } }; @@ -1522,8 +1523,10 @@ struct ImGuiStackTool int StackLevel; // -1: query stack and resize Results, >= 0: individual stack level ImGuiID QueryId; // ID to query details for ImVector Results; + bool CopyToClipboardOnCtrlC; + float CopyToClipboardLastTime; - ImGuiStackTool() { memset(this, 0, sizeof(*this)); } + ImGuiStackTool() { memset(this, 0, sizeof(*this)); CopyToClipboardLastTime = -FLT_MAX; } }; //----------------------------------------------------------------------------- From 4691fa0ed5fab7ce25733e1b8d3d62ffc6511940 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 8 Feb 2022 13:33:26 +0100 Subject: [PATCH 04/15] ImDrawList: PthArcTo: Add small tolerance when comparing angles (#4993) --- docs/CHANGELOG.txt | 1 + imgui.h | 2 +- imgui_draw.cpp | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 4aef8a3c..e81d6057 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -40,6 +40,7 @@ Breaking changes: Other Changes: - Stack Tool: Added option to copy item path to clipboard. (#4631) +- Drawlist: Fixed PathArcTo() emitting terminating vertices too close to arc vertices. (#4993) [@thedmd] ----------------------------------------------------------------------- diff --git a/imgui.h b/imgui.h index 9b8d4ff4..8f7378b8 100644 --- a/imgui.h +++ b/imgui.h @@ -65,7 +65,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.88 WIP" -#define IMGUI_VERSION_NUM 18702 +#define IMGUI_VERSION_NUM 18703 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 95a2298f..23938706 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -1206,8 +1206,8 @@ void ImDrawList::PathArcTo(const ImVec2& center, float radius, float a_min, floa const float a_min_segment_angle = a_min_sample * IM_PI * 2.0f / IM_DRAWLIST_ARCFAST_SAMPLE_MAX; const float a_max_segment_angle = a_max_sample * IM_PI * 2.0f / IM_DRAWLIST_ARCFAST_SAMPLE_MAX; - const bool a_emit_start = (a_min_segment_angle - a_min) != 0.0f; - const bool a_emit_end = (a_max - a_max_segment_angle) != 0.0f; + const bool a_emit_start = ImAbs(a_min_segment_angle - a_min) >= 1e-5f; + const bool a_emit_end = ImAbs(a_max - a_max_segment_angle) >= 1e-5f; _Path.reserve(_Path.Size + (a_mid_samples + 1 + (a_emit_start ? 1 : 0) + (a_emit_end ? 1 : 0))); if (a_emit_start) From 955aacfbc58040c875d927a3c34edd2a3d7554d9 Mon Sep 17 00:00:00 2001 From: Borislav Stanimirov Date: Wed, 9 Feb 2022 10:47:11 +0200 Subject: [PATCH 05/15] GCC: Disable deprecated-enum-enum-conversion for gcc as well (#4997) --- imgui_widgets.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 87698bf9..19a34257 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -82,6 +82,7 @@ Index of this file: #pragma GCC diagnostic ignored "-Wpragmas" // warning: unknown option after '#pragma GCC diagnostic' kind #pragma GCC diagnostic ignored "-Wformat-nonliteral" // warning: format not a string literal, format string not checked #pragma GCC diagnostic ignored "-Wclass-memaccess" // [__GNUC__ >= 8] warning: 'memset/memcpy' clearing/writing an object of type 'xxxx' with no trivial copy-assignment; use assignment or value-initialization instead +#pragma GCC diagnostic ignored "-Wdeprecated-enum-enum-conversion" // warning: bitwise operation between different enumeration types ('XXXFlags_' and 'XXXFlagsPrivate_') is deprecated #endif //------------------------------------------------------------------------- From 71f98dd05615cd5a06a02cb8a7e37b47e9bbd874 Mon Sep 17 00:00:00 2001 From: Jeff Mears Date: Mon, 7 Feb 2022 17:09:43 -0800 Subject: [PATCH 06/15] Declare ImVec2 and ImVec4 constructors as constexpr (#4995) --- docs/CHANGELOG.txt | 1 + imgui.h | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index e81d6057..37d29c17 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -40,6 +40,7 @@ Breaking changes: Other Changes: - Stack Tool: Added option to copy item path to clipboard. (#4631) +- Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan] - Drawlist: Fixed PathArcTo() emitting terminating vertices too close to arc vertices. (#4993) [@thedmd] diff --git a/imgui.h b/imgui.h index 8f7378b8..2204a86d 100644 --- a/imgui.h +++ b/imgui.h @@ -249,8 +249,8 @@ IM_MSVC_RUNTIME_CHECKS_OFF struct ImVec2 { float x, y; - ImVec2() { x = y = 0.0f; } - ImVec2(float _x, float _y) { x = _x; y = _y; } + constexpr ImVec2() : x(0.0f), y(0.0f) { } + constexpr ImVec2(float _x, float _y) : x(_x), y(_y) { } float operator[] (size_t idx) const { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. float& operator[] (size_t idx) { IM_ASSERT(idx <= 1); return (&x)[idx]; } // We very rarely use this [] operator, the assert overhead is fine. #ifdef IM_VEC2_CLASS_EXTRA @@ -261,9 +261,9 @@ struct ImVec2 // ImVec4: 4D vector used to store clipping rectangles, colors etc. [Compile-time configurable type] struct ImVec4 { - float x, y, z, w; - ImVec4() { x = y = z = w = 0.0f; } - ImVec4(float _x, float _y, float _z, float _w) { x = _x; y = _y; z = _z; w = _w; } + float x, y, z, w; + constexpr ImVec4() : x(0.0f), y(0.0f), z(0.0f), w(0.0f) { } + constexpr ImVec4(float _x, float _y, float _z, float _w) : x(_x), y(_y), z(_z), w(_w) { } #ifdef IM_VEC4_CLASS_EXTRA IM_VEC4_CLASS_EXTRA // Define additional constructors and implicit cast operators in imconfig.h to convert back and forth between your math types and ImVec4. #endif From 5854da10e664312e51acec618267d06b1294ac0b Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 11 Feb 2022 12:24:32 +0100 Subject: [PATCH 07/15] Declare other structures as constexpr (#4995) + rename ImGuiInputEventType_Char to ImGuiInputEventType_Text for consistency with event structure. --- imconfig.h | 8 ++++---- imgui.cpp | 4 ++-- imgui_internal.h | 20 ++++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/imconfig.h b/imconfig.h index 774b8f0e..c854832e 100644 --- a/imconfig.h +++ b/imconfig.h @@ -81,12 +81,12 @@ //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. // This will be inlined as part of ImVec2 and ImVec4 class declarations. /* -#define IM_VEC2_CLASS_EXTRA \ - ImVec2(const MyVec2& f) { x = f.x; y = f.y; } \ +#define IM_VEC2_CLASS_EXTRA \ + constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ operator MyVec2() const { return MyVec2(x,y); } -#define IM_VEC4_CLASS_EXTRA \ - ImVec4(const MyVec4& f) { x = f.x; y = f.y; z = f.z; w = f.w; } \ +#define IM_VEC4_CLASS_EXTRA \ + constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ operator MyVec4() const { return MyVec4(x,y,z,w); } */ diff --git a/imgui.cpp b/imgui.cpp index be040665..01d1f7cb 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1180,7 +1180,7 @@ void ImGuiIO::AddInputCharacter(unsigned int c) return; ImGuiInputEvent e; - e.Type = ImGuiInputEventType_Char; + e.Type = ImGuiInputEventType_Text; e.Source = ImGuiInputSource_Keyboard; e.Text.Char = c; g.InputEventsQueue.push_back(e); @@ -7882,7 +7882,7 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs) } } } - else if (e->Type == ImGuiInputEventType_Char) + else if (e->Type == ImGuiInputEventType_Text) { // Trickling Rule: Stop processing queued events if keys/mouse have been interacted with if (trickle_fast_inputs && (key_changed || mouse_button_changed != 0 || mouse_moved || mouse_wheeled)) diff --git a/imgui_internal.h b/imgui_internal.h index 12bc7dfc..891e406e 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -469,17 +469,17 @@ IM_MSVC_RUNTIME_CHECKS_OFF struct ImVec1 { float x; - ImVec1() { x = 0.0f; } - ImVec1(float _x) { x = _x; } + constexpr ImVec1() : x(0.0f) { } + constexpr ImVec1(float _x) : x(_x) { } }; // Helper: ImVec2ih (2D vector, half-size integer, for long-term packed storage) struct ImVec2ih { short x, y; - ImVec2ih() { x = y = 0; } - ImVec2ih(short _x, short _y) { x = _x; y = _y; } - explicit ImVec2ih(const ImVec2& rhs) { x = (short)rhs.x; y = (short)rhs.y; } + constexpr ImVec2ih() : x(0), y(0) {} + constexpr ImVec2ih(short _x, short _y) : x(_x), y(_y) {} + constexpr explicit ImVec2ih(const ImVec2& rhs) : x((short)rhs.x), y((short)rhs.y) {} }; // Helper: ImRect (2D axis aligned bounding-box) @@ -489,10 +489,10 @@ struct IMGUI_API ImRect ImVec2 Min; // Upper-left ImVec2 Max; // Lower-right - ImRect() : Min(0.0f, 0.0f), Max(0.0f, 0.0f) {} - ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} - ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} - ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} + constexpr ImRect() : Min(0.0f, 0.0f), Max(0.0f, 0.0f) {} + constexpr ImRect(const ImVec2& min, const ImVec2& max) : Min(min), Max(max) {} + constexpr ImRect(const ImVec4& v) : Min(v.x, v.y), Max(v.z, v.w) {} + constexpr ImRect(float x1, float y1, float x2, float y2) : Min(x1, y1), Max(x2, y2) {} ImVec2 GetCenter() const { return ImVec2((Min.x + Max.x) * 0.5f, (Min.y + Max.y) * 0.5f); } ImVec2 GetSize() const { return ImVec2(Max.x - Min.x, Max.y - Min.y); } @@ -1171,7 +1171,7 @@ enum ImGuiInputEventType ImGuiInputEventType_MouseWheel, ImGuiInputEventType_MouseButton, ImGuiInputEventType_Key, - ImGuiInputEventType_Char, + ImGuiInputEventType_Text, ImGuiInputEventType_Focus, ImGuiInputEventType_COUNT }; From b6b8f6634e19e22ca6af20e5f155e9de02b2b4b6 Mon Sep 17 00:00:00 2001 From: thedmd Date: Tue, 15 Feb 2022 11:14:43 +0100 Subject: [PATCH 08/15] ImVector: Fixed erase() with empty range. (#5009) --- docs/CHANGELOG.txt | 1 + imgui.h | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 37d29c17..ce2ff4dc 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,6 +41,7 @@ Other Changes: - Stack Tool: Added option to copy item path to clipboard. (#4631) - Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan] +- ImVector: Fixed erase() with empty range. (#5009) [@thedmd] - Drawlist: Fixed PathArcTo() emitting terminating vertices too close to arc vertices. (#4993) [@thedmd] diff --git a/imgui.h b/imgui.h index 2204a86d..281c843f 100644 --- a/imgui.h +++ b/imgui.h @@ -65,7 +65,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.88 WIP" -#define IMGUI_VERSION_NUM 18703 +#define IMGUI_VERSION_NUM 18704 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE From 8d3906365db5b4c18758e3fd5cb05fb5356350af Mon Sep 17 00:00:00 2001 From: ocornut Date: Tue, 15 Feb 2022 17:06:50 +0100 Subject: [PATCH 09/15] CI: Fixes for OSX + explicitely request C++11. --- .github/workflows/build.yml | 28 +++++++++++------------ examples/example_glfw_metal/Makefile | 2 +- examples/example_glfw_opengl2/Makefile | 2 +- examples/example_glfw_opengl3/Makefile | 2 +- examples/example_glut_opengl2/Makefile | 2 +- examples/example_null/Makefile | 4 ++-- examples/example_sdl_metal/Makefile | 2 +- examples/example_sdl_opengl2/Makefile | 2 +- examples/example_sdl_opengl3/Makefile | 2 +- examples/example_sdl_sdlrenderer/Makefile | 2 +- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a667bd58..9611d37e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -246,7 +246,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -Wextra -Werror -Wno-zero-as-null-pointer-constant -Wno-double-promotion -Wno-variadic-macros -Wno-empty-body -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -Wextra -Werror -Wno-zero-as-null-pointer-constant -Wno-double-promotion -Wno-variadic-macros -Wno-empty-body -o example_single_file example_single_file.cpp - name: Build example_null (freetype) run: | @@ -262,7 +262,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (with ImWchar32) run: | @@ -274,7 +274,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (with large ImDrawIdx + pointer ImTextureID) run: | @@ -287,7 +287,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (with IMGUI_DISABLE_OBSOLETE_FUNCTIONS) run: | @@ -299,7 +299,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (with IMGUI_DISABLE_OBSOLETE_KEYIO) run: | @@ -311,7 +311,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (with IMGUI_DISABLE_DEMO_WINDOWS and IMGUI_DISABLE_METRICS_WINDOW) run: | @@ -324,7 +324,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (with IMGUI_DISABLE_FILE_FUNCTIONS) run: | @@ -336,7 +336,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (with IMGUI_USE_BGRA_PACKED_COLOR) run: | @@ -348,7 +348,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (with IM_VEC2_CLASS_EXTRA and IM_VEC4_CLASS_EXTRA) run: | @@ -368,7 +368,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - g++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + g++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (without c++ runtime, Clang) run: | @@ -380,7 +380,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - clang++ -I. -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp + clang++ -I. -std=c++11 -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 @@ -397,7 +397,7 @@ jobs: run: make -C examples/example_sdl_opengl3 - name: Build with IMGUI_IMPL_VULKAN_NO_PROTOTYPES - run: g++ -c -I. -DIMGUI_IMPL_VULKAN_NO_PROTOTYPES=1 backends/imgui_impl_vulkan.cpp + run: g++ -c -I. -std=c++11 -DIMGUI_IMPL_VULKAN_NO_PROTOTYPES=1 backends/imgui_impl_vulkan.cpp MacOS: runs-on: macos-latest @@ -420,7 +420,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - clang++ -I. -Wall -Wformat -o example_single_file example_single_file.cpp + clang++ -I. -std=c++11 -Wall -Wformat -o example_single_file example_single_file.cpp - name: Build example_null (without c++ runtime) run: | @@ -431,7 +431,7 @@ jobs: #include "examples/example_null/main.cpp" EOF - clang++ -I. -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp + clang++ -I. -std=c++11 -Wall -Wformat -nodefaultlibs -fno-rtti -fno-exceptions -fno-threadsafe-statics -lc -lm -o example_single_file example_single_file.cpp - name: Build example_glfw_opengl2 run: make -C examples/example_glfw_opengl2 diff --git a/examples/example_glfw_metal/Makefile b/examples/example_glfw_metal/Makefile index a174bc8f..82d5ac96 100644 --- a/examples/example_glfw_metal/Makefile +++ b/examples/example_glfw_metal/Makefile @@ -17,7 +17,7 @@ LIBS = -framework Metal -framework MetalKit -framework Cocoa -framework IOKit -f LIBS += -L/usr/local/lib -L/opt/homebrew/lib LIBS += -lglfw -CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I/usr/local/include -I/opt/homebrew/include +CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I/usr/local/include -I/opt/homebrew/include CXXFLAGS += -Wall -Wformat CFLAGS = $(CXXFLAGS) diff --git a/examples/example_glfw_opengl2/Makefile b/examples/example_glfw_opengl2/Makefile index 5c19a27f..1f15c15c 100644 --- a/examples/example_glfw_opengl2/Makefile +++ b/examples/example_glfw_opengl2/Makefile @@ -22,7 +22,7 @@ SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glfw.cpp $(IMGUI_DIR)/backends/imgui OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) -CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends +CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends CXXFLAGS += -g -Wall -Wformat LIBS = diff --git a/examples/example_glfw_opengl3/Makefile b/examples/example_glfw_opengl3/Makefile index 672a7059..252ce571 100644 --- a/examples/example_glfw_opengl3/Makefile +++ b/examples/example_glfw_opengl3/Makefile @@ -23,7 +23,7 @@ OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) LINUX_GL_LIBS = -lGL -CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends +CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends CXXFLAGS += -g -Wall -Wformat LIBS = diff --git a/examples/example_glut_opengl2/Makefile b/examples/example_glut_opengl2/Makefile index a980f56f..7af289dc 100644 --- a/examples/example_glut_opengl2/Makefile +++ b/examples/example_glut_opengl2/Makefile @@ -17,7 +17,7 @@ SOURCES += $(IMGUI_DIR)/backends/imgui_impl_glut.cpp $(IMGUI_DIR)/backends/imgui OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) -CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends +CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends CXXFLAGS += -g -Wall -Wformat LIBS = diff --git a/examples/example_null/Makefile b/examples/example_null/Makefile index 9208e8a0..9ceb3534 100644 --- a/examples/example_null/Makefile +++ b/examples/example_null/Makefile @@ -17,7 +17,7 @@ SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) -CXXFLAGS += -I$(IMGUI_DIR) +CXXFLAGS += -std=c++11 -I$(IMGUI_DIR) CXXFLAGS += -g -Wall -Wformat LIBS = @@ -52,7 +52,7 @@ endif ifeq ($(UNAME_S), Darwin) #APPLE ECHO_MESSAGE = "Mac OS X" ifeq ($(WITH_EXTRA_WARNINGS), 1) - CXXFLAGS += -Weverything -Wno-reserved-id-macro -Wno-c++98-compat-pedantic -Wno-padded -Wno-c++11-long-long -Wno-poison-system-directories + CXXFLAGS += -Weverything -Wno-reserved-id-macro -Wno-c++98-compat-pedantic -Wno-padded -Wno-poison-system-directories endif CFLAGS = $(CXXFLAGS) endif diff --git a/examples/example_sdl_metal/Makefile b/examples/example_sdl_metal/Makefile index 042bb04c..2167a98f 100644 --- a/examples/example_sdl_metal/Makefile +++ b/examples/example_sdl_metal/Makefile @@ -17,7 +17,7 @@ LIBS = -framework Metal -framework MetalKit -framework Cocoa -framework IOKit -f LIBS += `sdl2-config --libs` LIBS += -L/usr/local/lib -CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I/usr/local/include +CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends -I/usr/local/include CXXFLAGS += `sdl2-config --cflags` CXXFLAGS += -Wall -Wformat CFLAGS = $(CXXFLAGS) diff --git a/examples/example_sdl_opengl2/Makefile b/examples/example_sdl_opengl2/Makefile index 92e0554b..24790f18 100644 --- a/examples/example_sdl_opengl2/Makefile +++ b/examples/example_sdl_opengl2/Makefile @@ -22,7 +22,7 @@ SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl.cpp $(IMGUI_DIR)/backends/imgui_ OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) -CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends +CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends CXXFLAGS += -g -Wall -Wformat LIBS = diff --git a/examples/example_sdl_opengl3/Makefile b/examples/example_sdl_opengl3/Makefile index 1b8ab422..ae22ce20 100644 --- a/examples/example_sdl_opengl3/Makefile +++ b/examples/example_sdl_opengl3/Makefile @@ -23,7 +23,7 @@ OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) LINUX_GL_LIBS = -lGL -CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends +CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends CXXFLAGS += -g -Wall -Wformat LIBS = diff --git a/examples/example_sdl_sdlrenderer/Makefile b/examples/example_sdl_sdlrenderer/Makefile index 5667789a..aa3b2d2e 100644 --- a/examples/example_sdl_sdlrenderer/Makefile +++ b/examples/example_sdl_sdlrenderer/Makefile @@ -22,7 +22,7 @@ SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl.cpp $(IMGUI_DIR)/backends/imgui_ OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) UNAME_S := $(shell uname -s) -CXXFLAGS = -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends +CXXFLAGS = -std=c++11 -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends CXXFLAGS += -g -Wall -Wformat LIBS = From 7ff41a78f956cf3388db9e0c8edfa1f0257e5c1f Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Tue, 15 Feb 2022 22:16:55 +0300 Subject: [PATCH 10/15] Fonts: binary_to_compressed_c.cpp gained -nostatic option (#5021) This allow to use added variables in other source files via extern declaration. --- docs/CHANGELOG.txt | 1 + misc/fonts/binary_to_compressed_c.cpp | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index ce2ff4dc..8b1fadd3 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,6 +41,7 @@ Other Changes: - Stack Tool: Added option to copy item path to clipboard. (#4631) - Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan] +- Misc: binary_to_compressed_c tool: Added -nostatic option. (#5021) [@podsvirov] - ImVector: Fixed erase() with empty range. (#5009) [@thedmd] - Drawlist: Fixed PathArcTo() emitting terminating vertices too close to arc vertices. (#4993) [@thedmd] diff --git a/misc/fonts/binary_to_compressed_c.cpp b/misc/fonts/binary_to_compressed_c.cpp index 441c8f67..284f039a 100644 --- a/misc/fonts/binary_to_compressed_c.cpp +++ b/misc/fonts/binary_to_compressed_c.cpp @@ -15,7 +15,7 @@ // You can also find a precompiled Windows binary in the binary/demo package available from https://github.com/ocornut/imgui // Usage: -// binary_to_compressed_c.exe [-base85] [-nocompress] +// binary_to_compressed_c.exe [-base85] [-nocompress] [-nostatic] // Usage example: // # binary_to_compressed_c.exe myfont.ttf MyFont > myfont.cpp // # binary_to_compressed_c.exe -base85 myfont.ttf MyFont > myfont.cpp @@ -31,23 +31,25 @@ typedef unsigned int stb_uint; typedef unsigned char stb_uchar; stb_uint stb_compress(stb_uchar* out, stb_uchar* in, stb_uint len); -static bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression); +static bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression, bool use_static); int main(int argc, char** argv) { if (argc < 3) { - printf("Syntax: %s [-base85] [-nocompress] \n", argv[0]); + printf("Syntax: %s [-base85] [-nocompress] [-nostatic] \n", argv[0]); return 0; } int argn = 1; bool use_base85_encoding = false; bool use_compression = true; - if (argv[argn][0] == '-') + bool use_static = true; + while (argn < (argc - 2) && argv[argn][0] == '-') { if (strcmp(argv[argn], "-base85") == 0) { use_base85_encoding = true; argn++; } else if (strcmp(argv[argn], "-nocompress") == 0) { use_compression = false; argn++; } + else if (strcmp(argv[argn], "-nostatic") == 0) { use_static = false; argn++; } else { fprintf(stderr, "Unknown argument: '%s'\n", argv[argn]); @@ -55,7 +57,7 @@ int main(int argc, char** argv) } } - bool ret = binary_to_compressed_c(argv[argn], argv[argn + 1], use_base85_encoding, use_compression); + bool ret = binary_to_compressed_c(argv[argn], argv[argn + 1], use_base85_encoding, use_compression, use_static); if (!ret) fprintf(stderr, "Error opening or reading file: '%s'\n", argv[argn]); return ret ? 0 : 1; @@ -67,7 +69,7 @@ char Encode85Byte(unsigned int x) return (x >= '\\') ? x + 1 : x; } -bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression) +bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_base85_encoding, bool use_compression, bool use_static) { // Read file FILE* f = fopen(filename, "rb"); @@ -90,10 +92,11 @@ bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_b FILE* out = stdout; fprintf(out, "// File: '%s' (%d bytes)\n", filename, (int)data_sz); fprintf(out, "// Exported using binary_to_compressed_c.cpp\n"); + const char* static_str = use_static ? "static " : ""; const char* compressed_str = use_compression ? "compressed_" : ""; if (use_base85_encoding) { - fprintf(out, "static const char %s_%sdata_base85[%d+1] =\n \"", symbol, compressed_str, (int)((compressed_sz + 3) / 4)*5); + fprintf(out, "%sconst char %s_%sdata_base85[%d+1] =\n \"", static_str, symbol, compressed_str, (int)((compressed_sz + 3) / 4)*5); char prev_c = 0; for (int src_i = 0; src_i < compressed_sz; src_i += 4) { @@ -112,8 +115,8 @@ bool binary_to_compressed_c(const char* filename, const char* symbol, bool use_b } else { - fprintf(out, "static const unsigned int %s_%ssize = %d;\n", symbol, compressed_str, (int)compressed_sz); - fprintf(out, "static const unsigned int %s_%sdata[%d/4] =\n{", symbol, compressed_str, (int)((compressed_sz + 3) / 4)*4); + fprintf(out, "%sconst unsigned int %s_%ssize = %d;\n", static_str, symbol, compressed_str, (int)compressed_sz); + fprintf(out, "%sconst unsigned int %s_%sdata[%d/4] =\n{", static_str, symbol, compressed_str, (int)((compressed_sz + 3) / 4)*4); int column = 0; for (int i = 0; i < compressed_sz; i += 4) { From 2dfa71fad57b8379c7732221975f99cde52884cb Mon Sep 17 00:00:00 2001 From: ocornut Date: Wed, 16 Feb 2022 19:32:46 +0100 Subject: [PATCH 11/15] Inputs: Fixed IsMouseClicked() repeat mode rate being half of keyboard repeat rate. Using KeyModAlt. Removed KeyModsPrev. --- docs/CHANGELOG.txt | 1 + imgui.cpp | 24 ++++++++---------------- imgui.h | 3 +-- imgui_internal.h | 10 +++++----- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 8b1fadd3..05c3c4c8 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -39,6 +39,7 @@ Breaking changes: Other Changes: +- Inputs: Fixed IsMouseClicked() repeat mode rate being half of keyboard repeat rate. - Stack Tool: Added option to copy item path to clipboard. (#4631) - Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan] - Misc: binary_to_compressed_c tool: Added -nostatic option. (#5021) [@podsvirov] diff --git a/imgui.cpp b/imgui.cpp index 01d1f7cb..f7c8b613 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -1250,7 +1250,7 @@ void ImGuiIO::ClearInputKeys() KeysData[n].DownDurationPrev = -1.0f; } KeyCtrl = KeyShift = KeyAlt = KeySuper = false; - KeyMods = KeyModsPrev = ImGuiKeyModFlags_None; + KeyMods = ImGuiKeyModFlags_None; for (int n = 0; n < IM_ARRAYSIZE(NavInputsDownDuration); n++) NavInputsDownDuration[n] = NavInputsDownDurationPrev[n] = -1.0f; } @@ -3938,9 +3938,6 @@ static void ImGui::UpdateKeyboardInputs() ImGuiContext& g = *GImGui; ImGuiIO& io = g.IO; - // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools - io.KeyMods = GetMergedKeyModFlags(); - // Import legacy keys or verify they are not used #ifndef IMGUI_DISABLE_OBSOLETE_KEYIO if (io.BackendUsingLegacyKeyArrays == 0) @@ -3982,6 +3979,9 @@ static void ImGui::UpdateKeyboardInputs() } #endif + // Synchronize io.KeyMods with individual modifiers io.KeyXXX bools + io.KeyMods = GetMergedKeyModFlags(); + // Clear gamepad data if disabled if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0) for (int i = ImGuiKey_Gamepad_BEGIN; i < ImGuiKey_Gamepad_END; i++) @@ -4864,7 +4864,6 @@ void ImGui::EndFrame() // Clear Input data for next frame g.IO.MouseWheel = g.IO.MouseWheelH = 0.0f; g.IO.InputQueueCharacters.resize(0); - g.IO.KeyModsPrev = g.IO.KeyMods; // doing it here is better than in NewFrame() as we'll tolerate backend writing to KeyMods. If we want to firmly disallow it we should detect it. memset(g.IO.NavInputs, 0, sizeof(g.IO.NavInputs)); CallContextHooks(&g, ImGuiContextHookType_EndFramePost); @@ -7657,14 +7656,8 @@ bool ImGui::IsMouseClicked(ImGuiMouseButton button, bool repeat) const float t = g.IO.MouseDownDuration[button]; if (t == 0.0f) return true; - if (repeat && t > g.IO.KeyRepeatDelay) - { - // FIXME: 2019/05/03: Our old repeat code was wrong here and led to doubling the repeat rate, which made it an ok rate for repeat on mouse hold. - int amount = CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate * 0.50f); - if (amount > 0) - return true; - } + return CalcTypematicRepeatAmount(t - g.IO.DeltaTime, t, g.IO.KeyRepeatDelay, g.IO.KeyRepeatRate) > 0; return false; } @@ -10796,7 +10789,7 @@ static void ImGui::NavUpdateWindowing() // - Testing that only Alt is tested prevents Alt+Shift or AltGR from toggling menu layer. // - AltGR is normally Alt+Ctrl but we can't reliably detect it (not all backends/systems/layout emit it as Alt+Ctrl). But even on keyboards without AltGR we don't want Alt+Ctrl to open menu anyway. const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0; - if (nav_keyboard_active && io.KeyMods == ImGuiKeyModFlags_Alt && (io.KeyModsPrev & ImGuiKeyModFlags_Alt) == 0) + if (nav_keyboard_active && IsKeyPressed(ImGuiKey_ModAlt)) { g.NavWindowingToggleLayer = true; g.NavInputSource = ImGuiInputSource_Keyboard; @@ -10809,13 +10802,12 @@ static void ImGui::NavUpdateWindowing() g.NavWindowingToggleLayer = false; // Apply layer toggle on release - // Important: we don't assume that Alt was previously held in order to handle loss of focus when backend calls io.AddFocusEvent(false) // Important: as before version <18314 we lacked an explicit IO event for focus gain/loss, we also compare mouse validity to detect old backends clearing mouse pos on focus loss. - if (!(io.KeyMods & ImGuiKeyModFlags_Alt) && (io.KeyModsPrev & ImGuiKeyModFlags_Alt) && g.NavWindowingToggleLayer) + if (IsKeyReleased(ImGuiKey_ModAlt) && g.NavWindowingToggleLayer) if (g.ActiveId == 0 || g.ActiveIdAllowOverlap) if (IsMousePosValid(&io.MousePos) == IsMousePosValid(&io.MousePosPrev)) apply_toggle_layer = true; - if (!io.KeyAlt) + if (!IsKeyDown(ImGuiKey_ModAlt)) g.NavWindowingToggleLayer = false; } diff --git a/imgui.h b/imgui.h index 281c843f..b71ce891 100644 --- a/imgui.h +++ b/imgui.h @@ -65,7 +65,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.88 WIP" -#define IMGUI_VERSION_NUM 18704 +#define IMGUI_VERSION_NUM 18705 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE @@ -2029,7 +2029,6 @@ struct ImGuiIO // Other state maintained from data above + IO function calls ImGuiKeyModFlags KeyMods; // Key mods flags (same as io.KeyCtrl/KeyShift/KeyAlt/KeySuper but merged into flags), updated by NewFrame() - ImGuiKeyModFlags KeyModsPrev; // Key mods flags (from previous frame) ImGuiKeyData KeysData[ImGuiKey_KeysData_SIZE]; // Key state for all known keys. Use IsKeyXXX() functions to access this. bool WantCaptureMouseUnlessPopupClose; // Alternative to WantCaptureMouse: (WantCaptureMouse == true && WantCaptureMouseUnlessPopupClose == false) when a click over void is expected to close a popup. ImVec2 MousePosPrev; // Previous mouse position (note that MouseDelta is not necessary == MousePos-MousePosPrev, in case either position is invalid) diff --git a/imgui_internal.h b/imgui_internal.h index 891e406e..99cecc8d 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -547,11 +547,11 @@ struct ImBitArray ImBitArray() { ClearAllBits(); } void ClearAllBits() { memset(Storage, 0, sizeof(Storage)); } void SetAllBits() { memset(Storage, 255, sizeof(Storage)); } - bool TestBit(int n) const { IM_ASSERT(n + OFFSET < BITCOUNT); return ImBitArrayTestBit(Storage, n + OFFSET); } - void SetBit(int n) { IM_ASSERT(n + OFFSET < BITCOUNT); ImBitArraySetBit(Storage, n + OFFSET); } - void ClearBit(int n) { IM_ASSERT(n + OFFSET < BITCOUNT); ImBitArrayClearBit(Storage, n + OFFSET); } - void SetBitRange(int n, int n2) { ImBitArraySetBitRange(Storage, n + OFFSET, n2 + OFFSET); } // Works on range [n..n2) - bool operator[](int n) const { IM_ASSERT(n + OFFSET < BITCOUNT); return ImBitArrayTestBit(Storage, n + OFFSET); } + bool TestBit(int n) const { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); return ImBitArrayTestBit(Storage, n); } + void SetBit(int n) { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); ImBitArraySetBit(Storage, n); } + void ClearBit(int n) { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); ImBitArrayClearBit(Storage, n); } + void SetBitRange(int n, int n2) { n += OFFSET; n2 += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT && n2 > n && n2 <= BITCOUNT); ImBitArraySetBitRange(Storage, n, n2); } // Works on range [n..n2) + bool operator[](int n) const { n += OFFSET; IM_ASSERT(n >= 0 && n < BITCOUNT); return ImBitArrayTestBit(Storage, n); } }; // Helper: ImBitVector From 5c8f8d031166765d2f1e2ac2de27df6d3691c05a Mon Sep 17 00:00:00 2001 From: thedmd Date: Wed, 16 Feb 2022 19:50:36 +0100 Subject: [PATCH 12/15] ImVector: Fixed erase() with empty range. (#5009) amend/fix b6b8f66 Actual change was missing in b6b8f66 --- imgui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index b71ce891..771f3547 100644 --- a/imgui.h +++ b/imgui.h @@ -1815,7 +1815,7 @@ struct ImVector inline void pop_back() { IM_ASSERT(Size > 0); Size--; } inline void push_front(const T& v) { if (Size == 0) push_back(v); else insert(Data, v); } inline T* erase(const T* it) { IM_ASSERT(it >= Data && it < Data + Size); const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + 1, ((size_t)Size - (size_t)off - 1) * sizeof(T)); Size--; return Data + off; } - inline T* erase(const T* it, const T* it_last){ IM_ASSERT(it >= Data && it < Data + Size && it_last > it && it_last <= Data + Size); const ptrdiff_t count = it_last - it; const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + count, ((size_t)Size - (size_t)off - (size_t)count) * sizeof(T)); Size -= (int)count; return Data + off; } + inline T* erase(const T* it, const T* it_last){ IM_ASSERT(it >= Data && it < Data + Size && it_last >= it && it_last <= Data + Size); const ptrdiff_t count = it_last - it; const ptrdiff_t off = it - Data; memmove(Data + off, Data + off + count, ((size_t)Size - (size_t)off - (size_t)count) * sizeof(T)); Size -= (int)count; return Data + off; } inline T* erase_unsorted(const T* it) { IM_ASSERT(it >= Data && it < Data + Size); const ptrdiff_t off = it - Data; if (it < Data + Size - 1) memcpy(Data + off, Data + Size - 1, sizeof(T)); Size--; return Data + off; } inline T* insert(const T* it, const T& v) { IM_ASSERT(it >= Data && it <= Data + Size); const ptrdiff_t off = it - Data; if (Size == Capacity) reserve(_grow_capacity(Size + 1)); if (off < (int)Size) memmove(Data + off + 1, Data + off, ((size_t)Size - (size_t)off) * sizeof(T)); memcpy(&Data[off], &v, sizeof(v)); Size++; return Data + off; } inline bool contains(const T& v) const { const T* data = Data; const T* data_end = Data + Size; while (data < data_end) if (*data++ == v) return true; return false; } From d9e60d29e1cab8c0b5370f92ce73b992ac77b3f1 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 17 Feb 2022 11:09:06 +0100 Subject: [PATCH 13/15] Clipper: Fixed a regresssion when not calling End() + calling End() twice as well. (#4822) --- docs/CHANGELOG.txt | 2 ++ imgui.cpp | 14 +++++++------- imgui.h | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 05c3c4c8..47d3c67c 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -39,6 +39,8 @@ Breaking changes: Other Changes: +- Clipper: Fixed a regression in 1.86 when not calling clipper.End() and late destructing the + clipper instance. High-level languages (Lua,Rust etc.) would typically be affected. (#4822) - Inputs: Fixed IsMouseClicked() repeat mode rate being half of keyboard repeat rate. - Stack Tool: Added option to copy item path to clipboard. (#4631) - Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan] diff --git a/imgui.cpp b/imgui.cpp index f7c8b613..d7f09ddf 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -2565,15 +2565,14 @@ void ImGuiListClipper::Begin(int items_count, float items_height) void ImGuiListClipper::End() { - // In theory here we should assert that we are already at the right position, but it seems saner to just seek at the end and not assert/crash the user. ImGuiContext& g = *GImGui; - if (ItemsCount >= 0 && ItemsCount < INT_MAX && DisplayStart >= 0) - ImGuiListClipper_SeekCursorForItem(this, ItemsCount); - ItemsCount = -1; - - // Restore temporary buffer and fix back pointers which may be invalidated when nesting if (ImGuiListClipperData* data = (ImGuiListClipperData*)TempData) { + // In theory here we should assert that we are already at the right position, but it seems saner to just seek at the end and not assert/crash the user. + if (ItemsCount >= 0 && ItemsCount < INT_MAX && DisplayStart >= 0) + ImGuiListClipper_SeekCursorForItem(this, ItemsCount); + + // Restore temporary buffer and fix back pointers which may be invalidated when nesting IM_ASSERT(data->ListClipper == this); data->StepNo = data->Ranges.Size; if (--g.ClipperTempDataStacked > 0) @@ -2583,6 +2582,7 @@ void ImGuiListClipper::End() } TempData = NULL; } + ItemsCount = -1; } void ImGuiListClipper::ForceDisplayRangeByIndices(int item_min, int item_max) @@ -2715,8 +2715,8 @@ bool ImGuiListClipper::Step() // Advance the cursor to the end of the list and then returns 'false' to end the loop. if (ItemsCount < INT_MAX) ImGuiListClipper_SeekCursorForItem(this, ItemsCount); - ItemsCount = -1; + End(); return false; } diff --git a/imgui.h b/imgui.h index 771f3547..e38dfd64 100644 --- a/imgui.h +++ b/imgui.h @@ -65,7 +65,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.88 WIP" -#define IMGUI_VERSION_NUM 18705 +#define IMGUI_VERSION_NUM 18706 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE From 421e73e6db0d5a74a2276c6f66d74bcfc078d584 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 17 Feb 2022 15:36:00 +0100 Subject: [PATCH 14/15] Fix an assert in metrics. --- imgui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imgui.cpp b/imgui.cpp index d7f09ddf..e09be5b1 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -12418,7 +12418,7 @@ void ImGui::ShowMetricsWindow(bool* p_open) Text("ActiveIdWindow: '%s'", g.ActiveIdWindow ? g.ActiveIdWindow->Name : "NULL"); int active_id_using_key_input_count = 0; - for (int n = 0; n < ImGuiKey_NamedKey_COUNT; n++) + for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++) active_id_using_key_input_count += g.ActiveIdUsingKeyInputMask[n] ? 1 : 0; Text("ActiveIdUsing: Wheel: %d, NavDirMask: %X, NavInputMask: %X, KeyInputMask: %d key(s)", g.ActiveIdUsingMouseWheel, g.ActiveIdUsingNavDirMask, g.ActiveIdUsingNavInputMask, active_id_using_key_input_count); Text("HoveredId: 0x%08X (%.2f sec), AllowOverlap: %d", g.HoveredIdPreviousFrame, g.HoveredIdTimer, g.HoveredIdAllowOverlap); // Not displaying g.HoveredId as it is update mid-frame From 29d462ebce0275345a6ce4621d8fff0ded57c9e5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 17 Feb 2022 18:39:03 +0100 Subject: [PATCH 15/15] Set HoveredID even when g.NavDisableMouseHover is set by gamepad/keyboard navigation. This will facilitate the use of future InputOwner API based on HoveredID/ActiveID. Note that this widen the small gap between polling g.HoveredID and using IsItemHovered() the later does various filtering. Added IsItemHovered(ImGuiHoveredFlags_NoNavOverride) to disable that specific state redirect/filter. Side-effect: fix EndGroup() use of combining HoveredId values when gamepad/keyboard nav is active. Unlikely to have user-visible side effect since IsItemHovered() would have filtered out anyway. Side-effect: fix IsAnyItemHovered() when gamepad/keyboard is active (but this wasn't the primary intent of this change). Side-effect: fix using SetItemUsingMouseWheel() while hovering an item and gamepad/keyboard is active. (#2891) --- docs/CHANGELOG.txt | 3 +++ imgui.cpp | 7 ++++--- imgui.h | 3 ++- imgui_widgets.cpp | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 47d3c67c..b2c6baaa 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -41,8 +41,11 @@ Other Changes: - Clipper: Fixed a regression in 1.86 when not calling clipper.End() and late destructing the clipper instance. High-level languages (Lua,Rust etc.) would typically be affected. (#4822) +- IsItemHovered(): added ImGuiHoveredFlags_NoNavOverride to disable the behavior where the + return value is overriden by focus when gamepad/keyboard navigation is active. - Inputs: Fixed IsMouseClicked() repeat mode rate being half of keyboard repeat rate. - Stack Tool: Added option to copy item path to clipboard. (#4631) +- Misc: Fixed IsAnyItemHovered() returning false when using navigation. - Misc: Added constexpr to ImVec2/ImVec4 inline constructors. (#4995) [@Myriachan] - Misc: binary_to_compressed_c tool: Added -nostatic option. (#5021) [@podsvirov] - ImVector: Fixed erase() with empty range. (#5009) [@thedmd] diff --git a/imgui.cpp b/imgui.cpp index e09be5b1..8cbe97b2 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3474,7 +3474,7 @@ bool ImGui::IsItemHovered(ImGuiHoveredFlags flags) { ImGuiContext& g = *GImGui; ImGuiWindow* window = g.CurrentWindow; - if (g.NavDisableMouseHover && !g.NavDisableHighlight) + if (g.NavDisableMouseHover && !g.NavDisableHighlight && !(flags & ImGuiHoveredFlags_NoNavOverride)) { if ((g.LastItemData.InFlags & ImGuiItemFlags_Disabled) && !(flags & ImGuiHoveredFlags_AllowWhenDisabled)) return false; @@ -3535,8 +3535,6 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) return false; if (!IsMouseHoveringRect(bb.Min, bb.Max)) return false; - if (g.NavDisableMouseHover) - return false; if (!IsWindowContentHoverable(window, ImGuiHoveredFlags_None)) { g.HoveredIdDisabled = true; @@ -3572,6 +3570,9 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id) IM_DEBUG_BREAK(); } + if (g.NavDisableMouseHover) + return false; + return true; } diff --git a/imgui.h b/imgui.h index e38dfd64..1e8f5b7c 100644 --- a/imgui.h +++ b/imgui.h @@ -65,7 +65,7 @@ Index of this file: // Version // (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens) #define IMGUI_VERSION "1.88 WIP" -#define IMGUI_VERSION_NUM 18706 +#define IMGUI_VERSION_NUM 18707 #define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx)) #define IMGUI_HAS_TABLE @@ -1280,6 +1280,7 @@ enum ImGuiHoveredFlags_ ImGuiHoveredFlags_AllowWhenBlockedByActiveItem = 1 << 7, // Return true even if an active item is blocking access to this item/window. Useful for Drag and Drop patterns. ImGuiHoveredFlags_AllowWhenOverlapped = 1 << 8, // IsItemHovered() only: Return true even if the position is obstructed or overlapped by another window ImGuiHoveredFlags_AllowWhenDisabled = 1 << 9, // IsItemHovered() only: Return true even if the item is disabled + ImGuiHoveredFlags_NoNavOverride = 1 << 10, // Disable using gamepad/keyboard navigation state when active, always query mouse. ImGuiHoveredFlags_RectOnly = ImGuiHoveredFlags_AllowWhenBlockedByPopup | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem | ImGuiHoveredFlags_AllowWhenOverlapped, ImGuiHoveredFlags_RootAndChildWindows = ImGuiHoveredFlags_RootWindow | ImGuiHoveredFlags_ChildWindows }; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 19a34257..21415a74 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -6925,7 +6925,7 @@ bool ImGui::BeginMenuEx(const char* label, const char* icon, bool enabled) if (!enabled) EndDisabled(); - const bool hovered = (g.HoveredId == id) && enabled; + const bool hovered = (g.HoveredId == id) && enabled && !g.NavDisableMouseHover; if (menuset_is_open) g.NavWindow = backed_nav_window;