Skip to content

Commit

Permalink
Sliders: Fixed using ImGuiSliderFlags_ClampOnInput with reverse slide…
Browse files Browse the repository at this point in the history
…rs. (#3432, #3449)
  • Loading branch information
ocornut committed Sep 7, 2020
1 parent b2039aa commit 36af398
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Other Changes:
- InputText: Fixed callback's helper DeleteChars() function when cursor is inside the deleted block. (#3454).
- DragFloat, DragScalar: Fixed ImGuiSliderFlags_ClampOnInput not being honored in the special case
where v_min == v_max. (#3361)
- SliderInt, SliderScalar: Fixed reaching of maximum value with inverted integer min/max ranges, both
with signed and unsigned types. Added reverse Sliders to Demo. (#3432, #3449) [@rokups]
- BeginMenuBar: Fixed minor bug where CursorPosMax gets pushed to CursorPos prior to calling BeginMenuBar(),
so e.g. calling the function at the end of a window would often add +ItemSpacing.y to scrolling range.
- TreeNode, CollapsingHeader: Made clicking on arrow toggle toggle the open state on the Mouse Down event
Expand Down
6 changes: 5 additions & 1 deletion imgui_widgets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1942,7 +1942,7 @@ static bool DataTypeClampT(T* v, const T* v_min, const T* v_max)
{
// Clamp, both sides are optional, return true if modified
if (v_min && *v < *v_min) { *v = *v_min; return true; }
if (v_max && *v > * v_max) { *v = *v_max; return true; }
if (v_max && *v > *v_max) { *v = *v_max; return true; }
return false;
}

Expand Down Expand Up @@ -3191,7 +3191,11 @@ bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImG
// Apply new value (or operations) then clamp
DataTypeApplyOpFromText(data_buf, g.InputTextState.InitialTextA.Data, data_type, p_data, NULL);
if (p_clamp_min || p_clamp_max)

This comment has been minimized.

Copy link
@elect86

elect86 Nov 6, 2020

Contributor

I think it should be &&

This comment has been minimized.

Copy link
@ocornut

ocornut Nov 6, 2020

Author Owner

No, because its possible to clamp only on one side.

{
if (DataTypeCompare(data_type, p_clamp_min, p_clamp_max) > 0)
ImSwap(p_clamp_min, p_clamp_max);
DataTypeClamp(data_type, p_data, p_clamp_min, p_clamp_max);
}

// Only mark as edited if new value is different
value_changed = memcmp(&data_backup, p_data, data_type_size) != 0;
Expand Down

0 comments on commit 36af398

Please sign in to comment.