Skip to content

Commit

Permalink
Merge branch 'master' into docking
Browse files Browse the repository at this point in the history
# Conflicts:
#	imgui.cpp
  • Loading branch information
ocornut committed Jan 22, 2025
2 parents a3802c8 + 6906ac9 commit 64e738c
Show file tree
Hide file tree
Showing 10 changed files with 134 additions and 68 deletions.
13 changes: 7 additions & 6 deletions backends/imgui_impl_sdlgpu3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ static void ImGui_ImplSDLGPU3_SetupRenderState(ImDrawData* draw_data, SDL_GPUGra
SDL_GPUBufferBinding index_buffer_binding = {};
index_buffer_binding.buffer = fd->IndexBuffer;
index_buffer_binding.offset = 0;
SDL_BindGPUVertexBuffers(render_pass,0,&vertex_buffer_binding,1);
SDL_BindGPUIndexBuffer(render_pass,&index_buffer_binding,sizeof(ImDrawIdx) == 2 ? SDL_GPU_INDEXELEMENTSIZE_16BIT : SDL_GPU_INDEXELEMENTSIZE_32BIT);
SDL_BindGPUVertexBuffers(render_pass,0, &vertex_buffer_binding, 1);
SDL_BindGPUIndexBuffer(render_pass, &index_buffer_binding, sizeof(ImDrawIdx) == 2 ? SDL_GPU_INDEXELEMENTSIZE_16BIT : SDL_GPU_INDEXELEMENTSIZE_32BIT);
}

// Setup viewport
Expand All @@ -103,7 +103,7 @@ static void ImGui_ImplSDLGPU3_SetupRenderState(ImDrawData* draw_data, SDL_GPUGra
viewport.h = (float)fb_height;
viewport.min_depth = 0.0f;
viewport.max_depth = 1.0f;
SDL_SetGPUViewport(render_pass,&viewport);
SDL_SetGPUViewport(render_pass, &viewport);

// Setup scale and translation
// Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
Expand All @@ -120,6 +120,7 @@ static void CreateOrResizeBuffer(SDL_GPUBuffer** buffer, uint32_t* old_size, uin
ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;

// Even though this is fairly rarely called.
SDL_WaitForGPUIdle(v->Device);
SDL_ReleaseGPUBuffer(v->Device, *buffer);

Expand Down Expand Up @@ -198,8 +199,8 @@ void Imgui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuff
index_buffer_region.size = index_size;

SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(command_buffer);
SDL_UploadToGPUBuffer(copy_pass, &vertex_buffer_location, &vertex_buffer_region,true);
SDL_UploadToGPUBuffer(copy_pass, &index_buffer_location, &index_buffer_region,true);
SDL_UploadToGPUBuffer(copy_pass, &vertex_buffer_location, &vertex_buffer_region, true);
SDL_UploadToGPUBuffer(copy_pass, &index_buffer_location, &index_buffer_region, true);
SDL_EndGPUCopyPass(copy_pass);
SDL_ReleaseGPUTransferBuffer(v->Device, index_transferbuffer);
SDL_ReleaseGPUTransferBuffer(v->Device, vertex_transferbuffer);
Expand Down Expand Up @@ -529,7 +530,7 @@ void ImGui_ImplSDLGPU3_CreateDeviceObjects()
sampler_info.mip_lod_bias = 0.0f;
sampler_info.min_lod = -1000.0f;
sampler_info.max_lod = 1000.0f;
sampler_info.enable_anisotropy = true;
sampler_info.enable_anisotropy = false;
sampler_info.max_anisotropy = 1.0f;
sampler_info.enable_compare = false;

Expand Down
19 changes: 19 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ HOW TO UPDATE?

Breaking changes:

- ColorEdit, ColorPicker: redesigned how alpha is displayed in the preview square. (#8335, #1578, #346)
- Removed ImGuiColorEditFlags_AlphaPreview (made value 0): it is now the default behavior.
- Prior to 1.91.8: alpha was made opaque in the preview by default _unless_ using ImGuiColorEditFlags_AlphaPreview.
- We now display the preview as transparent by default. You can use ImGuiColorEditFlags_AlphaOpaque to use old behavior.
- The new flags may be combined better and allow finer controls:
- ImGuiColorEditFlags_AlphaOpaque: disable alpha in the preview, but alpha value still editable.
- ImGuiColorEditFlags_AlphaNoBg: disable rendering a checkerboard background behind transparent color.
- ImGuiColorEditFlags_AlphaPreviewHalf: display half opaque / half transparent preview.
- Backends: SDLGPU3: Renamed ImGui_ImplSDLGPU3_InitInfo::GpuDevice to Device
for consistency. (#8163, #7998, #7988)

Expand All @@ -51,9 +59,20 @@ Other changes:
snapped to pixels. Effectively it would only be noticeable when hinting
is disabled with ImGuiFreeTypeBuilderFlags_NoHinting, as hinting itself
snaps glyph advances.
- Inputs: added IsMouseReleasedWithDelay() helper. (#8337, #8320)
Use if you absolutely need to distinguish single-click from double-clicks
by introducing a delay. This is a very rarely used UI idiom, but some apps
use this: e.g. MS Explorer single-click on an icon triggers a rename.
Generally use with 'delay >= io.MouseDoubleClickTime' + combine with a
'io.MouseClickedLastCount == 1' check.
- Windows: legacy SetWindowFontScale() is properly inherited by nested child
windows. Note that an upcoming major release should make this obsolete,
but in the meanwhile it works better now. (#2701, #8138, #1018)
- ColorEdit, ColorPicker: Fixed alpha preview broken in 1.91.7. (#8336, #8241). [@PathogenDavid]
- Tabs, Style: reworked selected overline rendering to better accommodate
for rounded tabs. Reduced default thickness (style.TabBarOverlineSize),
increased default rounding (style.TabRounding). (#8334) [@Kian738, @ocornut]
styles as the current look is not right (but ImGuiCol_TabSelectedOverline stays the same).
- Examples: DirectX12: Reduced number of frame in flight from 3 to 2 in
provided example, to reduce latency.
- Backends+Examples: Vulkan: better handle VK_SUBOPTIMAL_KHR being returned by
Expand Down
2 changes: 1 addition & 1 deletion examples/example_sdl2_vulkan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(g_PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_ARRAYSIZE(requestSurfaceImageFormat), requestSurfaceColorSpace);

// Select Present Mode
#ifdef APP_UNLIMITED_FRAME_RATE
#ifdef APP_USE_UNLIMITED_FRAME_RATE
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR };
#else
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_FIFO_KHR };
Expand Down
8 changes: 5 additions & 3 deletions examples/example_sdl3_sdlgpu3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// - Introduction, links and more at the top of imgui.cpp

// Important note to the reader who wish to integrate imgui_impl_sdlgpu3.cpp/.h in their own engine/app.
// - Unline other backends, the user must call the function Imgui_ImplSDLGPU_PrepareDrawData BEFORE issuing a SDL_GPURenderPass containing ImGui_ImplSDLGPU_RenderDrawData.
// - Unlike other backends, the user must call the function Imgui_ImplSDLGPU_PrepareDrawData() BEFORE issuing a SDL_GPURenderPass containing ImGui_ImplSDLGPU_RenderDrawData.
// Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.

#include "imgui.h"
Expand Down Expand Up @@ -54,6 +54,7 @@ int main(int, char**)
printf("Error: SDL_ClaimWindowForGPUDevice(): %s\n", SDL_GetError());
return -1;
}
SDL_SetGPUSwapchainParameters(gpu_device, window, SDL_GPU_SWAPCHAINCOMPOSITION_SDR, SDL_GPU_PRESENTMODE_MAILBOX);

// Setup Dear ImGui context
IMGUI_CHECKVERSION();
Expand Down Expand Up @@ -140,7 +141,7 @@ int main(int, char**)
ImGui::Checkbox("Another Window", &show_another_window);

ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
ImGui::ColorEdit4("clear color", (float*)&clear_color); // Edit 3 floats representing a color

if (ImGui::Button("Button")) // Buttons return true when clicked (most widgets return true when edited/activated)
counter++;
Expand Down Expand Up @@ -179,7 +180,7 @@ int main(int, char**)
// Setup and start a render pass
SDL_GPUColorTargetInfo target_info = {};
target_info.texture = swapchain_texture;
target_info.clear_color = SDL_FColor{ clear_color.x,clear_color.y,clear_color.z,clear_color.w };
target_info.clear_color = SDL_FColor { clear_color.x, clear_color.y, clear_color.z, clear_color.w };
target_info.load_op = SDL_GPU_LOADOP_CLEAR;
target_info.store_op = SDL_GPU_STOREOP_STORE;
target_info.mip_level = 0;
Expand All @@ -196,6 +197,7 @@ int main(int, char**)
// Submit the command buffer
SDL_SubmitGPUCommandBuffer(command_buffer);
}

// Cleanup
SDL_WaitForGPUIdle(gpu_device);
ImGui_ImplSDL3_Shutdown();
Expand Down
2 changes: 1 addition & 1 deletion examples/example_sdl3_vulkan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface
wd->SurfaceFormat = ImGui_ImplVulkanH_SelectSurfaceFormat(g_PhysicalDevice, wd->Surface, requestSurfaceImageFormat, (size_t)IM_ARRAYSIZE(requestSurfaceImageFormat), requestSurfaceColorSpace);

// Select Present Mode
#ifdef APP_UNLIMITED_FRAME_RATE
#ifdef APP_USE_UNLIMITED_FRAME_RATE
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_MAILBOX_KHR, VK_PRESENT_MODE_IMMEDIATE_KHR, VK_PRESENT_MODE_FIFO_KHR };
#else
VkPresentModeKHR present_modes[] = { VK_PRESENT_MODE_FIFO_KHR };
Expand Down
20 changes: 18 additions & 2 deletions imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ CODE
- likewise io.MousePos and GetMousePos() will use OS coordinates.
If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos.

- 2025/01/22 (1.91.8) - removed ImGuiColorEditFlags_AlphaPreview (made value 0): it is now the default behavior.
prior to 1.91.8: alpha was made opaque in the preview by default _unless_ using ImGuiColorEditFlags_AlphaPreview. We now display the preview as transparent by default. You can use ImGuiColorEditFlags_AlphaOpaque to use old behavior.
the new flags (ImGuiColorEditFlags_AlphaOpaque, ImGuiColorEditFlags_AlphaNoBg + existing ImGuiColorEditFlags_AlphaPreviewHalf) may be combined better and allow finer controls:
- 2025/01/14 (1.91.7) - renamed ImGuiTreeNodeFlags_SpanTextWidth to ImGuiTreeNodeFlags_SpanLabelWidth for consistency with other names. Kept redirection enum (will obsolete). (#6937)
- 2024/11/27 (1.91.6) - changed CRC32 table from CRC32-adler to CRC32c polynomial in order to be compatible with the result of SSE 4.2 instructions.
As a result, old .ini data may be partially lost (docking and tables information particularly).
Expand Down Expand Up @@ -1359,11 +1362,11 @@ ImGuiStyle::ImGuiStyle()
GrabMinSize = 12.0f; // Minimum width/height of a grab box for slider/scrollbar
GrabRounding = 0.0f; // Radius of grabs corners rounding. Set to 0.0f to have rectangular slider grabs.
LogSliderDeadzone = 4.0f; // The size in pixels of the dead-zone around zero on logarithmic sliders that cross zero.
TabRounding = 4.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
TabRounding = 5.0f; // Radius of upper corners of a tab. Set to 0.0f to have rectangular tabs.
TabBorderSize = 0.0f; // Thickness of border around tabs.
TabMinWidthForCloseButton = 0.0f; // Minimum width for close button to appear on an unselected tab when hovered. Set to 0.0f to always show when hovering, set to FLT_MAX to never show close button unless selected.
TabBarBorderSize = 1.0f; // Thickness of tab-bar separator, which takes on the tab active color to denote focus.
TabBarOverlineSize = 2.0f; // Thickness of tab-bar overline, which highlights the selected tab-bar.
TabBarOverlineSize = 1.0f; // Thickness of tab-bar overline, which highlights the selected tab-bar.
TableAngledHeadersAngle = 35.0f * (IM_PI / 180.0f); // Angle of angled headers (supported values range from -50 degrees to +50 degrees).
TableAngledHeadersTextAlign = ImVec2(0.5f,0.0f);// Alignment of angled headers within the cell
ColorButtonPosition = ImGuiDir_Right; // Side of the color button in the ColorEdit4 widget (left/right). Defaults to ImGuiDir_Right.
Expand Down Expand Up @@ -9833,6 +9836,17 @@ bool ImGui::IsMouseReleased(ImGuiMouseButton button, ImGuiID owner_id)
return g.IO.MouseReleased[button] && TestKeyOwner(MouseButtonToKey(button), owner_id); // Should be same as IsKeyReleased(MouseButtonToKey(button), owner_id)
}

// Use if you absolutely need to distinguish single-click from double-click by introducing a delay.
// Generally use with 'delay >= io.MouseDoubleClickTime' + combined with a 'io.MouseClickedLastCount == 1' test.
// This is a very rarely used UI idiom, but some apps use this: e.g. MS Explorer single click on an icon to rename.
bool ImGui::IsMouseReleasedWithDelay(ImGuiMouseButton button, float delay)
{
ImGuiContext& g = *GImGui;
IM_ASSERT(button >= 0 && button < IM_ARRAYSIZE(g.IO.MouseDown));
const float time_since_release = (float)(g.Time - g.IO.MouseReleasedTime[button]);
return !IsMouseDown(button) && (time_since_release - g.IO.DeltaTime < delay) && (time_since_release >= delay);
}

bool ImGui::IsMouseDoubleClicked(ImGuiMouseButton button)
{
ImGuiContext& g = *GImGui;
Expand Down Expand Up @@ -10108,6 +10122,8 @@ static void ImGui::UpdateMouseInputs()
io.MouseClicked[i] = io.MouseDown[i] && io.MouseDownDuration[i] < 0.0f;
io.MouseClickedCount[i] = 0; // Will be filled below
io.MouseReleased[i] = !io.MouseDown[i] && io.MouseDownDuration[i] >= 0.0f;
if (io.MouseReleased[i])
io.MouseReleasedTime[i] = g.Time;
io.MouseDownDurationPrev[i] = io.MouseDownDuration[i];
io.MouseDownDuration[i] = io.MouseDown[i] ? (io.MouseDownDuration[i] < 0.0f ? 0.0f : io.MouseDownDuration[i] + io.DeltaTime) : -1.0f;
if (io.MouseClicked[i])
Expand Down
Loading

0 comments on commit 64e738c

Please sign in to comment.