|
@@ -2305,12 +2305,13 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
|
|
{
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
const ImGuiAxis axis = (flags & ImGuiSliderFlags_Vertical) ? ImGuiAxis_Y : ImGuiAxis_X;
|
|
|
- const bool is_clamped = (v_min < v_max);
|
|
|
+ const bool is_bounded = (v_min < v_max);
|
|
|
+ const bool is_wrapped = is_bounded && (flags & ImGuisliderFlags_WrapAround);
|
|
|
const bool is_logarithmic = (flags & ImGuiSliderFlags_Logarithmic) != 0;
|
|
|
const bool is_floating_point = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);
|
|
|
|
|
|
// Default tweak speed
|
|
|
- if (v_speed == 0.0f && is_clamped && (v_max - v_min < FLT_MAX))
|
|
|
+ if (v_speed == 0.0f && is_bounded && (v_max - v_min < FLT_MAX))
|
|
|
v_speed = (float)((v_max - v_min) * g.DragSpeedDefaultRatio);
|
|
|
|
|
|
// Inputs accumulates into g.DragCurrentAccum, which is flushed into the current value as soon as it makes a difference with our precision settings
|
|
@@ -2344,8 +2345,8 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
|
|
|
|
|
// Clear current value on activation
|
|
|
// Avoid altering values and clamping when we are _already_ past the limits and heading in the same direction, so e.g. if range is 0..255, current value is 300 and we are pushing to the right side, keep the 300.
|
|
|
- bool is_just_activated = g.ActiveIdIsJustActivated;
|
|
|
- bool is_already_past_limits_and_pushing_outward = is_clamped && ((*v >= v_max && adjust_delta > 0.0f) || (*v <= v_min && adjust_delta < 0.0f));
|
|
|
+ const bool is_just_activated = g.ActiveIdIsJustActivated;
|
|
|
+ const bool is_already_past_limits_and_pushing_outward = is_bounded && !is_wrapped && ((*v >= v_max && adjust_delta > 0.0f) || (*v <= v_min && adjust_delta < 0.0f));
|
|
|
if (is_just_activated || is_already_past_limits_and_pushing_outward)
|
|
|
{
|
|
|
g.DragCurrentAccum = 0.0f;
|
|
@@ -2403,13 +2404,24 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
|
|
if (v_cur == (TYPE)-0)
|
|
|
v_cur = (TYPE)0;
|
|
|
|
|
|
- // Clamp values (+ handle overflow/wrap-around for integer types)
|
|
|
- if (*v != v_cur && is_clamped)
|
|
|
+ if (*v != v_cur && is_bounded)
|
|
|
{
|
|
|
- if (v_cur < v_min || (v_cur > *v && adjust_delta < 0.0f && !is_floating_point))
|
|
|
- v_cur = v_min;
|
|
|
- if (v_cur > v_max || (v_cur < *v && adjust_delta > 0.0f && !is_floating_point))
|
|
|
- v_cur = v_max;
|
|
|
+ if (is_wrapped)
|
|
|
+ {
|
|
|
+ // Wrap values
|
|
|
+ if (v_cur < v_min)
|
|
|
+ v_cur += v_max - v_min + (is_floating_point ? 0 : 1);
|
|
|
+ if (v_cur > v_max)
|
|
|
+ v_cur -= v_max - v_min + (is_floating_point ? 0 : 1);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Clamp values + handle overflow/wrap-around for integer types.
|
|
|
+ if (v_cur < v_min || (v_cur > *v && adjust_delta < 0.0f && !is_floating_point))
|
|
|
+ v_cur = v_min;
|
|
|
+ if (v_cur > v_max || (v_cur < *v && adjust_delta > 0.0f && !is_floating_point))
|
|
|
+ v_cur = v_max;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// Apply result
|
|
@@ -2422,7 +2434,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
|
|
bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags)
|
|
|
{
|
|
|
// Read imgui.cpp "API BREAKING CHANGES" section for 1.78 if you hit this assert.
|
|
|
- IM_ASSERT((flags == 1 || (flags & ImGuiSliderFlags_InvalidMask_) == 0) && "Invalid ImGuiSliderFlags flags! Has the 'float power' argument been mistakenly cast to flags? Call function with ImGuiSliderFlags_Logarithmic flags instead.");
|
|
|
+ IM_ASSERT((flags == 1 || (flags & ImGuiSliderFlags_InvalidMask_) == 0) && "Invalid ImGuiSliderFlags flags! Has the legacy 'float power' argument been mistakenly cast to flags? Call function with ImGuiSliderFlags_Logarithmic flags instead.");
|
|
|
|
|
|
ImGuiContext& g = *GImGui;
|
|
|
if (g.ActiveId == id)
|
|
@@ -3015,7 +3027,8 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
|
|
|
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, ImGuiSliderFlags flags, ImRect* out_grab_bb)
|
|
|
{
|
|
|
// Read imgui.cpp "API BREAKING CHANGES" section for 1.78 if you hit this assert.
|
|
|
- IM_ASSERT((flags == 1 || (flags & ImGuiSliderFlags_InvalidMask_) == 0) && "Invalid ImGuiSliderFlags flag! Has the 'float power' argument been mistakenly cast to flags? Call function with ImGuiSliderFlags_Logarithmic flags instead.");
|
|
|
+ IM_ASSERT((flags == 1 || (flags & ImGuiSliderFlags_InvalidMask_) == 0) && "Invalid ImGuiSliderFlags flags! Has the legacy 'float power' argument been mistakenly cast to flags? Call function with ImGuiSliderFlags_Logarithmic flags instead.");
|
|
|
+ IM_ASSERT((flags & ImGuisliderFlags_WrapAround) == 0); // Not supported by SliderXXX(), only by DragXXX()
|
|
|
|
|
|
switch (data_type)
|
|
|
{
|