Skip to content

Commit 916a895

Browse files
committed
DragFloat(): passing min>=max (e.g. 0.0f) for range makes the drag unbound #180, removed extra APIs
1 parent 61d886e commit 916a895

File tree

2 files changed

+5
-15
lines changed

2 files changed

+5
-15
lines changed

imgui.cpp

+3-11
Original file line numberDiff line numberDiff line change
@@ -5460,7 +5460,9 @@ static bool DragScalarBehavior(const ImRect& frame_bb, ImGuiID id, float* v, flo
54605460
step = v_step * g.DragSpeedScaleSlow;
54615461

54625462
*v += (mouse_drag_delta.x - g.DragLastMouseDelta.x) * step;
5463-
*v = ImClamp(*v, v_min, v_max);
5463+
5464+
if (v_min < v_max)
5465+
*v = ImClamp(*v, v_min, v_max);
54645466

54655467
g.DragLastMouseDelta.x = mouse_drag_delta.x;
54665468
value_changed = true;
@@ -5543,11 +5545,6 @@ bool ImGui::DragFloat(const char* label, float *v, float v_step, float v_min, fl
55435545
return value_changed;
55445546
}
55455547

5546-
bool ImGui::DragFloat(const char* label, float* v, float v_step, const char* display_format)
5547-
{
5548-
return ImGui::DragFloat(label, v, v_step, -FLT_MAX, FLT_MAX, display_format);
5549-
}
5550-
55515548
bool ImGui::DragInt(const char* label, int* v, int v_step, int v_min, int v_max, const char* display_format)
55525549
{
55535550
if (!display_format)
@@ -5558,11 +5555,6 @@ bool ImGui::DragInt(const char* label, int* v, int v_step, int v_min, int v_max,
55585555
return value_changed;
55595556
}
55605557

5561-
bool ImGui::DragInt(const char* label, int* v, int v_step, const char* display_format)
5562-
{
5563-
return ImGui::DragInt(label, v, v_step, IM_INT_MIN, IM_INT_MAX, display_format);
5564-
}
5565-
55665558
enum ImGuiPlotType
55675559
{
55685560
ImGuiPlotType_Lines,

imgui.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -301,10 +301,8 @@ namespace ImGui
301301
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));
302302

303303
// Widgets: Drags (tip: ctrl+click on a drag box to input text)
304-
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");
305-
IMGUI_API bool DragFloat(const char* label, float* v, float v_step, const char* display_format);
306-
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");
307-
IMGUI_API bool DragInt(const char* label, int* v, int v_step, const char* display_format = "%.0f");
304+
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
305+
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
308306

309307
// Widgets: Sliders (tip: ctrl+click on a slider to input text)
310308
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

0 commit comments

Comments
 (0)