Skip to content

Commit ae86889

Browse files
committed
Merge branch 'master' into docking
2 parents 1ab1e3c + f7ba645 commit ae86889

11 files changed

+115
-60
lines changed

.github/workflows/static-analysis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@ jobs:
4242
fi
4343
cd examples/example_null
4444
pvs-studio-analyzer trace -- make WITH_EXTRA_WARNINGS=1
45-
pvs-studio-analyzer analyze -e ../../imstb_rectpack.h -e ../../imstb_textedit.h -e ../../imstb_truetype.h -l ../../pvs-studio.lic -o pvs-studio.log
45+
pvs-studio-analyzer analyze --disableLicenseExpirationCheck -e ../../imstb_rectpack.h -e ../../imstb_textedit.h -e ../../imstb_truetype.h -l ../../pvs-studio.lic -o pvs-studio.log
4646
plog-converter -a 'GA:1,2;OP:1' -d V1071 -t errorfile -w pvs-studio.log

backends/imgui_impl_wgpu.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
// CHANGELOG
2020
// (minor and older changes stripped away, please see git history for details)
21+
// 2024-09-16: Added support for optional IMGUI_IMPL_WEBGPU_BACKEND_DAWN / IMGUI_IMPL_WEBGPU_BACKEND_WGPU define to handle ever-changing native implementations. (#7977)
2122
// 2024-01-22: Added configurable PipelineMultisampleState struct. (#7240)
2223
// 2024-01-22: (Breaking) ImGui_ImplWGPU_Init() now takes a ImGui_ImplWGPU_InitInfo structure instead of variety of parameters, allowing for easier further changes.
2324
// 2024-01-22: Fixed pipeline layout leak. (#7245)
@@ -37,6 +38,18 @@
3738
// 2021-02-18: Change blending equation to preserve alpha in output buffer.
3839
// 2021-01-28: Initial version.
3940

41+
// When targeting native platforms (i.e. NOT emscripten), one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN
42+
// or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided. See imgui_impl_wgpu.h for more details.
43+
#ifndef __EMSCRIPTEN__
44+
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) == defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
45+
#error exactly one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be defined!
46+
#endif
47+
#else
48+
#if defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN) || defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
49+
#error neither IMGUI_IMPL_WEBGPU_BACKEND_DAWN nor IMGUI_IMPL_WEBGPU_BACKEND_WGPU may be defined if targeting emscripten!
50+
#endif
51+
#endif
52+
4053
#include "imgui.h"
4154
#ifndef IMGUI_DISABLE
4255
#include "imgui_impl_wgpu.h"
@@ -247,7 +260,11 @@ static WGPUProgrammableStageDescriptor ImGui_ImplWGPU_CreateShaderModule(const c
247260
ImGui_ImplWGPU_Data* bd = ImGui_ImplWGPU_GetBackendData();
248261

249262
WGPUShaderModuleWGSLDescriptor wgsl_desc = {};
263+
#ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
264+
wgsl_desc.chain.sType = WGPUSType_ShaderSourceWGSL;
265+
#else
250266
wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor;
267+
#endif
251268
wgsl_desc.code = wgsl_source;
252269

253270
WGPUShaderModuleDescriptor desc = {};
@@ -662,7 +679,11 @@ bool ImGui_ImplWGPU_CreateDeviceObjects()
662679
// Create depth-stencil State
663680
WGPUDepthStencilState depth_stencil_state = {};
664681
depth_stencil_state.format = bd->depthStencilFormat;
682+
#ifdef IMGUI_IMPL_WEBGPU_BACKEND_DAWN
683+
depth_stencil_state.depthWriteEnabled = WGPUOptionalBool_False;
684+
#else
665685
depth_stencil_state.depthWriteEnabled = false;
686+
#endif
666687
depth_stencil_state.depthCompare = WGPUCompareFunction_Always;
667688
depth_stencil_state.stencilFront.compare = WGPUCompareFunction_Always;
668689
depth_stencil_state.stencilFront.failOp = WGPUStencilOperation_Keep;
@@ -732,7 +753,15 @@ bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info)
732753
// Setup backend capabilities flags
733754
ImGui_ImplWGPU_Data* bd = IM_NEW(ImGui_ImplWGPU_Data)();
734755
io.BackendRendererUserData = (void*)bd;
756+
#if defined(__EMSCRIPTEN__)
757+
io.BackendRendererName = "imgui_impl_webgpu_emscripten";
758+
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_DAWN)
759+
io.BackendRendererName = "imgui_impl_webgpu_dawn";
760+
#elif defined(IMGUI_IMPL_WEBGPU_BACKEND_WGPU)
761+
io.BackendRendererName = "imgui_impl_webgpu_wgpu";
762+
#else
735763
io.BackendRendererName = "imgui_impl_webgpu";
764+
#endif
736765
io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
737766

738767
bd->initInfo = *init_info;

backends/imgui_impl_wgpu.h

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
// This needs to be used along with a Platform Binding (e.g. GLFW)
33
// (Please note that WebGPU is currently experimental, will not run on non-beta browsers, and may break.)
44

5+
// Important note to dawn and/or wgpu users: when targeting native platforms (i.e. NOT emscripten),
6+
// one of IMGUI_IMPL_WEBGPU_BACKEND_DAWN or IMGUI_IMPL_WEBGPU_BACKEND_WGPU must be provided.
7+
// Add #define to your imconfig.h file, or as a compilation flag in your build system.
8+
// This requirement will be removed once WebGPU stabilizes and backends converge on a unified interface.
9+
//#define IMGUI_IMPL_WEBGPU_BACKEND_DAWN
10+
//#define IMGUI_IMPL_WEBGPU_BACKEND_WGPU
11+
512
// Implemented features:
613
// [X] Renderer: User texture binding. Use 'WGPUTextureView' as ImTextureID. Read the FAQ about ImTextureID!
714
// [X] Renderer: Large meshes support (64k+ vertices) with 16-bit indices.

docs/CHANGELOG.txt

+12-1
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,27 @@ Other changes:
6565
- Nav: pressing any keyboard key while holding Alt disable toggling nav layer on Alt release. (#4439)
6666
- MultiSelect+Tables: fixed an issue where box-select would skip items while drag-scrolling
6767
in a table with outer borders. (#7970, #7821).
68+
- Inputs: SetNextItemShortcut() with ImGuiInputFlags_Tooltip doesn't show tooltip when item is active.
6869
- InputText: internal refactoring to simplify and optimize the code. The ImWchar buffer has been
6970
removed. Simplifications allowed to implement new optimizations for handling very large text buffers
7071
(e.g. in our testing, handling of a 1 MB text buffer is now 3 times faster in VS2022 Debug build).
71-
This is the first step toward more refactorig. (#7925) [@alektron, @ocornut]
72+
This is the first step toward more refactoring. (#7925) [@alektron, @ocornut]
7273
- InputText: added CJK double-width punctuation to list of separators considered for CTRL+Arrow.
74+
- Tables: fixed auto-width columns when using synced-instances of same table. The previous fix
75+
done in v1.90.5 was incomplete. (#7218)
76+
- Tables: fixed assertion related to inconsistent outer clipping when sizes are not rounded. (#7957) [@eclbtownsend]
77+
- Tables: fixed assertion with tables with borders when clipped by parent. (#6765, #3752, #7428)
78+
- Windows: fixed an issue where double-click to collapse could be triggered even while another
79+
item is active, if the item didn't use the left mouse button. (#7841)
80+
- Misc: Made it accepted to call SetMouseCursor() with any out-of-bound value, as a way to allow
81+
hacking in custom cursors if desirable.
7382
- Fonts: fixed ellipsis "..." rendering width miscalculation bug introduced in 1.91.0. (#7976) [@DDeimos]
7483
- TextLinkOpenURL(): modified tooltip to display a verb "Open 'xxxx'". (#7885, #7660)
7584
- Backends: SDL2: use SDL_Vulkan_GetDrawableSize() when available. (#7967, #3190) [@scribam]
7685
- Backends: GLFW+Emscripten: use OSX behaviors automatically when using contrib glfw port. (#7965, #7915)
7786
[@ypujante]
87+
- Backends: WebGPU: Added support for optional IMGUI_IMPL_WEBGPU_BACKEND_DAWN / IMGUI_IMPL_WEBGPU_BACKEND_WGPU
88+
defines to handle ever-changing native implementations. (#7977, #7969, #6602, #6188, #7523) [@acgaudette]
7889

7990
Docking+Viewports Branch:
8091

examples/example_glfw_wgpu/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ add_executable(example_glfw_wgpu
7979
${IMGUI_DIR}/imgui_tables.cpp
8080
${IMGUI_DIR}/imgui_widgets.cpp
8181
)
82+
IF(NOT EMSCRIPTEN)
83+
target_compile_definitions(example_glfw_wgpu PUBLIC
84+
"IMGUI_IMPL_WEBGPU_BACKEND_DAWN"
85+
)
86+
endif()
8287
target_include_directories(example_glfw_wgpu PUBLIC
8388
${IMGUI_DIR}
8489
${IMGUI_DIR}/backends

imgui.cpp

+11-6
Original file line numberDiff line numberDiff line change
@@ -3770,7 +3770,8 @@ void ImGui::RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFl
37703770
void ImGui::RenderMouseCursor(ImVec2 base_pos, float base_scale, ImGuiMouseCursor mouse_cursor, ImU32 col_fill, ImU32 col_border, ImU32 col_shadow)
37713771
{
37723772
ImGuiContext& g = *GImGui;
3773-
IM_ASSERT(mouse_cursor > ImGuiMouseCursor_None && mouse_cursor < ImGuiMouseCursor_COUNT);
3773+
if (mouse_cursor <= ImGuiMouseCursor_None || mouse_cursor >= ImGuiMouseCursor_COUNT) // We intentionally accept out of bound values.
3774+
mouse_cursor = ImGuiMouseCursor_Arrow;
37743775
ImFontAtlas* font_atlas = g.DrawListSharedData.Font->ContainerAtlas;
37753776
for (ImGuiViewportP* viewport : g.Viewports)
37763777
{
@@ -4438,7 +4439,7 @@ bool ImGui::ItemHoverable(const ImRect& bb, ImGuiID id, ImGuiItemFlags item_flag
44384439

44394440
// Display shortcut (only works with mouse)
44404441
// (ImGuiItemStatusFlags_HasShortcut in LastItemData denotes we want a tooltip)
4441-
if (id == g.LastItemData.ID && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasShortcut))
4442+
if (id == g.LastItemData.ID && (g.LastItemData.StatusFlags & ImGuiItemStatusFlags_HasShortcut) && g.ActiveId != id)
44424443
if (IsItemHovered(ImGuiHoveredFlags_ForTooltip | ImGuiHoveredFlags_DelayNormal))
44434444
SetTooltip("%s", GetKeyChordName(g.LastItemData.Shortcut));
44444445
}
@@ -6497,7 +6498,7 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
64976498
ButtonBehavior(resize_rect, resize_grip_id, &hovered, &held, ImGuiButtonFlags_FlattenChildren | ImGuiButtonFlags_NoNavFocus);
64986499
//GetForegroundDrawList(window)->AddRect(resize_rect.Min, resize_rect.Max, IM_COL32(255, 255, 0, 255));
64996500
if (hovered || held)
6500-
g.MouseCursor = (resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE;
6501+
SetMouseCursor((resize_grip_n & 1) ? ImGuiMouseCursor_ResizeNESW : ImGuiMouseCursor_ResizeNWSE);
65016502

65026503
if (held && g.IO.MouseDoubleClicked[0])
65036504
{
@@ -6543,7 +6544,7 @@ static int ImGui::UpdateWindowManualResize(ImGuiWindow* window, const ImVec2& si
65436544
if (hovered && g.HoveredIdTimer <= WINDOWS_RESIZE_FROM_EDGES_FEEDBACK_TIMER)
65446545
hovered = false;
65456546
if (hovered || held)
6546-
g.MouseCursor = (axis == ImGuiAxis_X) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS;
6547+
SetMouseCursor((axis == ImGuiAxis_X) ? ImGuiMouseCursor_ResizeEW : ImGuiMouseCursor_ResizeNS);
65476548
if (held && g.IO.MouseDoubleClicked[0])
65486549
{
65496550
// Double-clicking bottom or right border auto-fit on this axis
@@ -7374,9 +7375,10 @@ bool ImGui::Begin(const char* name, bool* p_open, ImGuiWindowFlags flags)
73747375
// At this point we don't have a clipping rectangle setup yet, so we can use the title bar area for hit detection and drawing
73757376
if (!(flags & ImGuiWindowFlags_NoTitleBar) && !(flags & ImGuiWindowFlags_NoCollapse) && !window->DockIsActive)
73767377
{
7377-
// We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed), so verify that we don't have items over the title bar.
7378+
// We don't use a regular button+id to test for double-click on title bar (mostly due to legacy reason, could be fixed),
7379+
// so verify that we don't have items over the title bar.
73787380
ImRect title_bar_rect = window->TitleBarRect();
7379-
if (g.HoveredWindow == window && g.HoveredId == 0 && g.HoveredIdPreviousFrame == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max))
7381+
if (g.HoveredWindow == window && g.HoveredId == 0 && g.HoveredIdPreviousFrame == 0 && g.ActiveId == 0 && IsMouseHoveringRect(title_bar_rect.Min, title_bar_rect.Max))
73807382
if (g.IO.MouseClickedCount[0] == 2 && GetKeyOwner(ImGuiKey_MouseLeft) == ImGuiKeyOwner_NoOwner)
73817383
window->WantCollapseToggle = true;
73827384
if (window->WantCollapseToggle)
@@ -9915,6 +9917,9 @@ ImGuiMouseCursor ImGui::GetMouseCursor()
99159917
return g.MouseCursor;
99169918
}
99179919

9920+
// We intentionally accept values of ImGuiMouseCursor that are outside our bounds, in case users needs to hack-in a custom cursor value.
9921+
// Custom cursors may be handled by custom backends. If you are using a standard backend and want to hack in a custom cursor, you may
9922+
// handle it before the backend _NewFrame() call and temporarily set ImGuiConfigFlags_NoMouseCursorChange during the backend _NewFrame() call.
99189923
void ImGui::SetMouseCursor(ImGuiMouseCursor cursor_type)
99199924
{
99209925
ImGuiContext& g = *GImGui;

imgui.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
// Library Version
3030
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals, e.g. '#if IMGUI_VERSION_NUM >= 12345')
3131
#define IMGUI_VERSION "1.91.2 WIP"
32-
#define IMGUI_VERSION_NUM 19114
32+
#define IMGUI_VERSION_NUM 19115
3333
#define IMGUI_HAS_TABLE
3434
#define IMGUI_HAS_VIEWPORT // Viewport WIP branch
3535
#define IMGUI_HAS_DOCK // Docking WIP branch

imgui_demo.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -7565,7 +7565,8 @@ static void ShowDemoWindowInputs()
75657565
IM_ASSERT(IM_ARRAYSIZE(mouse_cursors_names) == ImGuiMouseCursor_COUNT);
75667566

75677567
ImGuiMouseCursor current = ImGui::GetMouseCursor();
7568-
ImGui::Text("Current mouse cursor = %d: %s", current, mouse_cursors_names[current]);
7568+
const char* cursor_name = (current >= ImGuiMouseCursor_Arrow) && (current < ImGuiMouseCursor_COUNT) ? mouse_cursors_names[current] : "N/A";
7569+
ImGui::Text("Current mouse cursor = %d: %s", current, cursor_name);
75697570
ImGui::BeginDisabled(true);
75707571
ImGui::CheckboxFlags("io.BackendFlags: HasMouseCursors", &io.BackendFlags, ImGuiBackendFlags_HasMouseCursors);
75717572
ImGui::EndDisabled();

imgui_draw.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2505,13 +2505,14 @@ ImFont* ImFontAtlas::AddFont(const ImFontConfig* font_cfg)
25052505
{
25062506
IM_ASSERT(!Locked && "Cannot modify a locked ImFontAtlas between NewFrame() and EndFrame/Render()!");
25072507
IM_ASSERT(font_cfg->FontData != NULL && font_cfg->FontDataSize > 0);
2508-
IM_ASSERT(font_cfg->SizePixels > 0.0f);
2508+
IM_ASSERT(font_cfg->SizePixels > 0.0f && "Is ImFontConfig struct correctly initialized?");
2509+
IM_ASSERT(font_cfg->OversampleH > 0 && font_cfg->OversampleV > 0 && "Is ImFontConfig struct correctly initialized?");
25092510

25102511
// Create new font
25112512
if (!font_cfg->MergeMode)
25122513
Fonts.push_back(IM_NEW(ImFont));
25132514
else
2514-
IM_ASSERT(!Fonts.empty() && "Cannot use MergeMode for the first font"); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font.
2515+
IM_ASSERT(Fonts.Size > 0 && "Cannot use MergeMode for the first font"); // When using MergeMode make sure that a font has already been added before. You can use ImGui::GetIO().Fonts->AddFontDefault() to add the default imgui font.
25152516

25162517
ConfigData.push_back(*font_cfg);
25172518
ImFontConfig& new_font_cfg = ConfigData.back();

imgui_tables.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ bool ImGui::BeginTableEx(const char* name, ImGuiID id, int columns_count, ImG
328328
// - always performing the GetOrAddByKey() O(log N) query in g.Tables.Map[].
329329
const bool use_child_window = (flags & (ImGuiTableFlags_ScrollX | ImGuiTableFlags_ScrollY)) != 0;
330330
const ImVec2 avail_size = GetContentRegionAvail();
331-
const ImVec2 actual_outer_size = CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f);
331+
const ImVec2 actual_outer_size = ImTrunc(CalcItemSize(outer_size, ImMax(avail_size.x, 1.0f), use_child_window ? ImMax(avail_size.y, 1.0f) : 0.0f));
332332
const ImRect outer_rect(outer_window->DC.CursorPos, outer_window->DC.CursorPos + actual_outer_size);
333333
const bool outer_window_is_measuring_size = (outer_window->AutoFitFramesX > 0) || (outer_window->AutoFitFramesY > 0); // Doesn't apply to AlwaysAutoResize windows!
334334
if (use_child_window && IsClippedEx(outer_rect, 0) && !outer_window_is_measuring_size)
@@ -866,7 +866,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
866866

867867
// Calculate ideal/auto column width (that's the width required for all contents to be visible without clipping)
868868
// Combine width from regular rows + width from headers unless requested not to.
869-
if (!column->IsPreserveWidthAuto)
869+
if (!column->IsPreserveWidthAuto && table->InstanceCurrent == 0)
870870
column->WidthAuto = TableGetColumnWidthAuto(table, column);
871871

872872
// Non-resizable columns keep their requested width (apply user value regardless of IsPreserveWidthAuto)
@@ -1261,7 +1261,7 @@ void ImGui::TableUpdateLayout(ImGuiTable* table)
12611261
if (table->Flags & ImGuiTableFlags_NoClip)
12621262
table->DrawSplitter->SetCurrentChannel(inner_window->DrawList, TABLE_DRAW_CHANNEL_NOCLIP);
12631263
else
1264-
inner_window->DrawList->PushClipRect(inner_window->InnerClipRect.Min, inner_window->InnerClipRect.Max, false);
1264+
inner_window->DrawList->PushClipRect(inner_window->InnerClipRect.Min, inner_window->InnerClipRect.Max, false); // FIXME: use table->InnerClipRect?
12651265
}
12661266

12671267
// Process hit-testing on resizing borders. Actual size change will be applied in EndTable()
@@ -2011,7 +2011,7 @@ void ImGui::TableEndRow(ImGuiTable* table)
20112011
{
20122012
for (int column_n = 0; column_n < table->ColumnsCount; column_n++)
20132013
table->Columns[column_n].NavLayerCurrent = ImGuiNavLayer_Main;
2014-
const float y0 = ImMax(table->RowPosY2 + 1, window->InnerClipRect.Min.y);
2014+
const float y0 = ImMax(table->RowPosY2 + 1, table->InnerClipRect.Min.y);
20152015
table_instance->LastFrozenHeight = y0 - table->OuterRect.Min.y;
20162016

20172017
if (unfreeze_rows_actual)
@@ -2020,8 +2020,8 @@ void ImGui::TableEndRow(ImGuiTable* table)
20202020
table->IsUnfrozenRows = true;
20212021

20222022
// BgClipRect starts as table->InnerClipRect, reduce it now and make BgClipRectForDrawCmd == BgClipRect
2023-
table->BgClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y = ImMin(y0, window->InnerClipRect.Max.y);
2024-
table->BgClipRect.Max.y = table->Bg2ClipRectForDrawCmd.Max.y = window->InnerClipRect.Max.y;
2023+
table->BgClipRect.Min.y = table->Bg2ClipRectForDrawCmd.Min.y = ImMin(y0, table->InnerClipRect.Max.y);
2024+
table->BgClipRect.Max.y = table->Bg2ClipRectForDrawCmd.Max.y = table->InnerClipRect.Max.y;
20252025
table->Bg2DrawChannelCurrent = table->Bg2DrawChannelUnfrozen;
20262026
IM_ASSERT(table->Bg2ClipRectForDrawCmd.Min.y <= table->Bg2ClipRectForDrawCmd.Max.y);
20272027

@@ -4409,7 +4409,7 @@ void ImGui::EndColumns()
44094409
{
44104410
ButtonBehavior(column_hit_rect, column_id, &hovered, &held);
44114411
if (hovered || held)
4412-
g.MouseCursor = ImGuiMouseCursor_ResizeEW;
4412+
SetMouseCursor(ImGuiMouseCursor_ResizeEW);
44134413
if (held && !(column->Flags & ImGuiOldColumnFlags_NoResize))
44144414
dragging_column = n;
44154415
}

0 commit comments

Comments
 (0)