From 916a8955ec46af391c8761dd6eb436311272efd9 Mon Sep 17 00:00:00 2001 From: ocornut Date: Fri, 3 Apr 2015 15:13:59 +0100 Subject: [PATCH] DragFloat(): passing min>=max (e.g. 0.0f) for range makes the drag unbound #180, removed extra APIs --- imgui.cpp | 14 +++----------- imgui.h | 6 ++---- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index a08a35c2..9cbb93a5 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -5460,7 +5460,9 @@ static bool DragScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, flo step = v_step * g.DragSpeedScaleSlow; *v += (mouse_drag_delta.x - g.DragLastMouseDelta.x) * step; - *v = ImClamp(*v, v_min, v_max); + + if (v_min < v_max) + *v = ImClamp(*v, v_min, v_max); g.DragLastMouseDelta.x = mouse_drag_delta.x; value_changed = true; @@ -5543,11 +5545,6 @@ bool ImGui::DragFloat(const char* label, float *v, float v_step, float v_min, fl return value_changed; } -bool ImGui::DragFloat(const char* label, float* v, float v_step, const char* display_format) -{ - return ImGui::DragFloat(label, v, v_step, -FLT_MAX, FLT_MAX, display_format); -} - bool ImGui::DragInt(const char* label, int* v, int v_step, int v_min, int v_max, const char* display_format) { if (!display_format) @@ -5558,11 +5555,6 @@ bool ImGui::DragInt(const char* label, int* v, int v_step, int v_min, int v_max, return value_changed; } -bool ImGui::DragInt(const char* label, int* v, int v_step, const char* display_format) -{ - return ImGui::DragInt(label, v, v_step, IM_INT_MIN, IM_INT_MAX, display_format); -} - enum ImGuiPlotType { ImGuiPlotType_Lines, diff --git a/imgui.h b/imgui.h index f0220421..56bfc277 100644 --- a/imgui.h +++ b/imgui.h @@ -301,10 +301,8 @@ namespace ImGui IMGUI_API void PlotHistogram(const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0,0)); // Widgets: Drags (tip: ctrl+click on a drag box to input text) - IMGUI_API bool DragFloat(const char* label, float* v, float v_step = 1.0f, float v_min = -FLT_MAX, float v_max = FLT_MAX, const char* display_format = "%.3f"); - IMGUI_API bool DragFloat(const char* label, float* v, float v_step, const char* display_format); - IMGUI_API bool DragInt(const char* label, int* v, int v_step = 1, int v_min = -0x7fffffff-1, int v_max = 0x7fffffff, const char* display_format = "%.0f"); - IMGUI_API bool DragInt(const char* label, int* v, int v_step, const char* display_format = "%.0f"); + IMGUI_API bool DragFloat(const char* label, float* v, float v_step = 1.0f, float v_min = 0.0f, float v_max = 0.0f, const char* display_format = "%.3f"); // If v_max >= v_max we have no bound + IMGUI_API bool DragInt(const char* label, int* v, int v_step = 1, int v_min = 0.0f, int v_max = 0.0f, const char* display_format = "%.0f"); // If v_max >= v_max we have no bound // Widgets: Sliders (tip: ctrl+click on a slider to input text) IMGUI_API bool SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format = "%.3f", float power = 1.0f); // adjust display_format to decorate the value with a prefix or a suffix. Use power!=1.0 for logarithmic sliders