mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-15 01:17:00 +00:00
DragFloat, DragInt: Cancel mouse tweak when current value is initially past the min/max boundaries and mouse is pushing in the same direction (keyboard/gamepad version already did this).
This commit is contained in:
parent
a84aff1875
commit
066550de68
@ -57,6 +57,7 @@ Other Changes:
|
|||||||
- InputText: On Mac OS X, filter out characters when the Cmd modifier is held. (#1747) [@sivu]
|
- InputText: On Mac OS X, filter out characters when the Cmd modifier is held. (#1747) [@sivu]
|
||||||
- InputText: On Mac OS X, support Cmd+Shift+Z for Redo. Cmd+Y is also supported as major apps seems to default to support both. (#1765) [@lfnoise]
|
- InputText: On Mac OS X, support Cmd+Shift+Z for Redo. Cmd+Y is also supported as major apps seems to default to support both. (#1765) [@lfnoise]
|
||||||
- InputText: Fixed returning true when edition is cancelled with Esc and the current buffer matches the initial value.
|
- InputText: Fixed returning true when edition is cancelled with Esc and the current buffer matches the initial value.
|
||||||
|
- DragFloat, DragInt: Cancel mouse tweak when current value is initially past the min/max boundaries and mouse is pushing in the same direction (keyboard/gamepad version already did this).
|
||||||
- Style: Changed default style.DisplaySafeAreaPadding values from (4,4) to (3,3) so it is smaller than FramePadding and has no effect on main menu bar on a computer. (#1439)
|
- Style: Changed default style.DisplaySafeAreaPadding values from (4,4) to (3,3) so it is smaller than FramePadding and has no effect on main menu bar on a computer. (#1439)
|
||||||
- Misc: Added IMGUI_CHECKVERSION() macro to compare version string and data structure sizes in order to catch issues with mismatching compilation unit settings. (#1695, #1769)
|
- Misc: Added IMGUI_CHECKVERSION() macro to compare version string and data structure sizes in order to catch issues with mismatching compilation unit settings. (#1695, #1769)
|
||||||
- Demo: Fixed Overlay: Added a context menu item to enable freely moving the window.
|
- Demo: Fixed Overlay: Added a context menu item to enable freely moving the window.
|
||||||
|
17
imgui.cpp
17
imgui.cpp
@ -9074,7 +9074,10 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
|
|||||||
if (g.ActiveId != id)
|
if (g.ActiveId != id)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool value_changed = false;
|
// Default tweak speed
|
||||||
|
if (v_speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
|
||||||
|
v_speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
|
||||||
|
|
||||||
if (g.ActiveIdIsJustActivated)
|
if (g.ActiveIdIsJustActivated)
|
||||||
{
|
{
|
||||||
// Lock current value on click
|
// Lock current value on click
|
||||||
@ -9082,10 +9085,6 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
|
|||||||
g.DragLastMouseDelta = ImVec2(0.f, 0.f);
|
g.DragLastMouseDelta = ImVec2(0.f, 0.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v_speed == 0.0f && (v_max - v_min) != 0.0f && (v_max - v_min) < FLT_MAX)
|
|
||||||
v_speed = (v_max - v_min) * g.DragSpeedDefaultRatio;
|
|
||||||
|
|
||||||
float v_cur = g.DragCurrentValue;
|
|
||||||
const ImVec2 mouse_drag_delta = GetMouseDragDelta(0, 1.0f);
|
const ImVec2 mouse_drag_delta = GetMouseDragDelta(0, 1.0f);
|
||||||
float adjust_delta = 0.0f;
|
float adjust_delta = 0.0f;
|
||||||
if (g.ActiveIdSource == ImGuiInputSource_Mouse && IsMousePosValid())
|
if (g.ActiveIdSource == ImGuiInputSource_Mouse && IsMousePosValid())
|
||||||
@ -9100,12 +9099,15 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
|
|||||||
if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
||||||
{
|
{
|
||||||
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
|
adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
|
||||||
if (v_min < v_max && ((v_cur >= v_max && adjust_delta > 0.0f) || (v_cur <= v_min && adjust_delta < 0.0f))) // This is to avoid applying the saturation when already past the limits
|
|
||||||
adjust_delta = 0.0f;
|
|
||||||
v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
|
v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
|
||||||
}
|
}
|
||||||
adjust_delta *= v_speed;
|
adjust_delta *= v_speed;
|
||||||
|
|
||||||
|
// Avoid applying the saturation 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
|
||||||
|
float v_cur = g.DragCurrentValue;
|
||||||
|
if (v_min < v_max && ((v_cur >= v_max && adjust_delta > 0.0f) || (v_cur <= v_min && adjust_delta < 0.0f)))
|
||||||
|
adjust_delta = 0.0f;
|
||||||
|
|
||||||
if (fabsf(adjust_delta) > 0.0f)
|
if (fabsf(adjust_delta) > 0.0f)
|
||||||
{
|
{
|
||||||
if (fabsf(power - 1.0f) > 0.001f)
|
if (fabsf(power - 1.0f) > 0.001f)
|
||||||
@ -9130,6 +9132,7 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Round to user desired precision, then apply
|
// Round to user desired precision, then apply
|
||||||
|
bool value_changed = false;
|
||||||
v_cur = RoundScalar(v_cur, decimal_precision);
|
v_cur = RoundScalar(v_cur, decimal_precision);
|
||||||
if (*v != v_cur)
|
if (*v != v_cur)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user