From 5dd56d4bb5e0c0f0dbb317857157940188898853 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 9 Mar 2026 17:59:49 +0100 Subject: [PATCH] Demo: add an option to enable ImGuiSliderFlags_ColorMarkers in Multi-Components section + fixed warnings. --- imgui_demo.cpp | 30 ++++++++++++++++-------------- imgui_widgets.cpp | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/imgui_demo.cpp b/imgui_demo.cpp index 5f1e69d60..da8a78f81 100644 --- a/imgui_demo.cpp +++ b/imgui_demo.cpp @@ -284,7 +284,7 @@ static void HelpMarker(const char* desc) // Helper to wire demo markers located in code to an interactive browser (e.g. https://pthom.github.io/imgui_explorer) #if IMGUI_VERSION_NUM >= 19263 -namespace ImGui { extern IMGUI_API void DemoMarker(const char* file, int line, const char* section); }; +namespace ImGui { extern IMGUI_API void DemoMarker(const char* file, int line, const char* section); } #define IMGUI_DEMO_MARKER(section) do { ImGui::DemoMarker("imgui_demo.cpp", __LINE__, section); } while (0) #endif @@ -1726,7 +1726,6 @@ static void DemoWindowWidgetsDragsAndSliders() ImGui::CheckboxFlags("ImGuiSliderFlags_WrapAround", &flags, ImGuiSliderFlags_WrapAround); ImGui::SameLine(); HelpMarker("Enable wrapping around from max to min and from min to max (only supported by DragXXX() functions)"); ImGui::CheckboxFlags("ImGuiSliderFlags_ColorMarkers", &flags, ImGuiSliderFlags_ColorMarkers); - //ImGui::CheckboxFlags("ImGuiSliderFlags_ColorMarkersG", &flags, 1 << ImGuiSliderFlags_ColorMarkersIndexShift_); // Not explicitly documented but possible. // Drags static float drag_f = 0.5f; @@ -1942,29 +1941,32 @@ static void DemoWindowWidgetsMultiComponents() static float vec4f[4] = { 0.10f, 0.20f, 0.30f, 0.44f }; static int vec4i[4] = { 1, 5, 100, 255 }; + static ImGuiSliderFlags flags = 0; + ImGui::CheckboxFlags("ImGuiSliderFlags_ColorMarkers", &flags, ImGuiSliderFlags_ColorMarkers); // Only passing this to Drag/Sliders + ImGui::SeparatorText("2-wide"); ImGui::InputFloat2("input float2", vec4f); - ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f); - ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f); ImGui::InputInt2("input int2", vec4i); - ImGui::DragInt2("drag int2", vec4i, 1, 0, 255); - ImGui::SliderInt2("slider int2", vec4i, 0, 255); + ImGui::DragFloat2("drag float2", vec4f, 0.01f, 0.0f, 1.0f, NULL, flags); + ImGui::DragInt2("drag int2", vec4i, 1, 0, 255, NULL, flags); + ImGui::SliderFloat2("slider float2", vec4f, 0.0f, 1.0f, NULL, flags); + ImGui::SliderInt2("slider int2", vec4i, 0, 255, NULL, flags); ImGui::SeparatorText("3-wide"); ImGui::InputFloat3("input float3", vec4f); - ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f); - ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f); ImGui::InputInt3("input int3", vec4i); - ImGui::DragInt3("drag int3", vec4i, 1, 0, 255); - ImGui::SliderInt3("slider int3", vec4i, 0, 255); + ImGui::DragFloat3("drag float3", vec4f, 0.01f, 0.0f, 1.0f, NULL, flags); + ImGui::DragInt3("drag int3", vec4i, 1, 0, 255, NULL, flags); + ImGui::SliderFloat3("slider float3", vec4f, 0.0f, 1.0f, NULL, flags); + ImGui::SliderInt3("slider int3", vec4i, 0, 255, NULL, flags); ImGui::SeparatorText("4-wide"); ImGui::InputFloat4("input float4", vec4f); - ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f); - ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f); ImGui::InputInt4("input int4", vec4i); - ImGui::DragInt4("drag int4", vec4i, 1, 0, 255); - ImGui::SliderInt4("slider int4", vec4i, 0, 255); + ImGui::DragFloat4("drag float4", vec4f, 0.01f, 0.0f, 1.0f, NULL, flags); + ImGui::DragInt4("drag int4", vec4i, 1, 0, 255, NULL, flags); + ImGui::SliderFloat4("slider float4", vec4f, 0.0f, 1.0f, NULL, flags); + ImGui::SliderInt4("slider int4", vec4i, 0, 255, NULL, flags); ImGui::SeparatorText("Ranges"); static float begin = 10, end = 90; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 97e297caa..cbb512634 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2685,7 +2685,7 @@ static bool TempInputIsClampEnabled(ImGuiSliderFlags flags, ImGuiDataType data_t return ImGui::DataTypeIsZero(data_type, p_min) ? ((flags & ImGuiSliderFlags_ClampZeroRange) != 0) : true; } return false; -}; +} // Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a Drag widget, p_min and p_max are optional. // Read code of e.g. DragFloat(), DragInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly.