From fdc526e8f81b74752c6d057e7e28629336e66f30 Mon Sep 17 00:00:00 2001 From: omar Date: Thu, 23 Jul 2020 18:18:30 +0200 Subject: [PATCH] Stop advertisting for Drag v_min>v_max which was introduced in 1.73 likely for 0537ac00 then made unnecessary with 32c33c66, added undocumented ImGuiItemFlags_ReadOnly as possible replacement (unused), (#211) --- imgui.h | 1 - imgui_internal.h | 1 + imgui_widgets.cpp | 6 ++++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/imgui.h b/imgui.h index 4517aabc..bc056857 100644 --- a/imgui.h +++ b/imgui.h @@ -464,7 +464,6 @@ namespace ImGui // - Speed are per-pixel of mouse movement (v_speed=0.2f: mouse needs to move by 5 pixels to increase value by 1). For gamepad/keyboard navigation, minimum speed is Max(v_speed, minimum_step_at_given_precision). // - Use v_min < v_max to clamp edits to given limits. Note that CTRL+Click manual input can override those limits. // - Use v_max = FLT_MAX / INT_MAX etc to avoid clamping to a maximum, same with v_min = -FLT_MAX / INT_MIN to avoid clamping to a minimum. - // - Use v_min > v_max to lock edits. IMGUI_API bool DragFloat(const char* label, float* v, float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f); // If v_min >= v_max we have no bound IMGUI_API bool DragFloat2(const char* label, float v[2], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f); IMGUI_API bool DragFloat3(const char* label, float v[3], float v_speed = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* format = "%.3f", float power = 1.0f); diff --git a/imgui_internal.h b/imgui_internal.h index 27212402..5399a122 100644 --- a/imgui_internal.h +++ b/imgui_internal.h @@ -575,6 +575,7 @@ enum ImGuiItemFlags_ ImGuiItemFlags_NoNavDefaultFocus = 1 << 4, // false ImGuiItemFlags_SelectableDontClosePopup = 1 << 5, // false // MenuItem/Selectable() automatically closes current Popup window ImGuiItemFlags_MixedValue = 1 << 6, // false // [BETA] Represent a mixed/indeterminate value, generally multi-selection where values differ. Currently only supported by Checkbox() (later should support all sorts of widgets) + ImGuiItemFlags_ReadOnly = 1 << 7, // false // [ALPHA] Allow hovering interactions but underlying value is not changed. ImGuiItemFlags_Default_ = 0 }; diff --git a/imgui_widgets.cpp b/imgui_widgets.cpp index 86295bcd..9b3ec52d 100644 --- a/imgui_widgets.cpp +++ b/imgui_widgets.cpp @@ -2113,6 +2113,8 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v } if (g.ActiveId != id) return false; + if (g.CurrentWindow->DC.ItemFlags & ImGuiItemFlags_ReadOnly) + return false; switch (data_type) { @@ -2558,6 +2560,10 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ // It would be possible to lift that limitation with some work but it doesn't seem to be worth it for sliders. bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* p_v, const void* p_min, const void* p_max, const char* format, float power, ImGuiSliderFlags flags, ImRect* out_grab_bb) { + ImGuiContext& g = *GImGui; + if (g.CurrentWindow->DC.ItemFlags & ImGuiItemFlags_ReadOnly) + return false; + switch (data_type) { case ImGuiDataType_S8: { ImS32 v32 = (ImS32)*(ImS8*)p_v; bool r = SliderBehaviorT(bb, id, ImGuiDataType_S32, &v32, *(const ImS8*)p_min, *(const ImS8*)p_max, format, power, flags, out_grab_bb); if (r) *(ImS8*)p_v = (ImS8)v32; return r; }