mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-26 13:37:00 +00:00
Drags, Sliders: Added ImGuiDragFlags_NoRoundToFormat / ImGuiSliderFlags_NoRoundToFormat flags (#642)
This commit is contained in:
parent
170d02bd99
commit
8018623c5b
@ -76,6 +76,8 @@ Other Changes:
|
|||||||
'float power' parameter which was obsoleted. (#1823, #1316, #642) [@Shironekoben, @AndrewBelt]
|
'float power' parameter which was obsoleted. (#1823, #1316, #642) [@Shironekoben, @AndrewBelt]
|
||||||
- Drag, Slider: Added ImGuiDragFlags_ClampOnInput/ImGuiSliderFlags_ClampOnInput flags to force
|
- Drag, Slider: Added ImGuiDragFlags_ClampOnInput/ImGuiSliderFlags_ClampOnInput flags to force
|
||||||
clamping value when using CTRL+Click to type in a value manually. (#1829, #3209, #946, #413).
|
clamping value when using CTRL+Click to type in a value manually. (#1829, #3209, #946, #413).
|
||||||
|
- Drag, Slider: Added ImGuiDragFlags_NoRoundToFormat/ImGuiSliderFlags_NoRoundToFormat flags
|
||||||
|
to disable rounding underlying value to match precision of the display format string. (#642)
|
||||||
- DragFloatRange2, DragIntRange2: Fixed an issue allowing to drag out of bounds when both
|
- DragFloatRange2, DragIntRange2: Fixed an issue allowing to drag out of bounds when both
|
||||||
min and max value are on the same value. (#1441)
|
min and max value are on the same value. (#1441)
|
||||||
- InputText, ImDrawList: Fixed assert triggering when drawing single line of text with more
|
- InputText, ImDrawList: Fixed assert triggering when drawing single line of text with more
|
||||||
|
6
imgui.h
6
imgui.h
@ -1296,7 +1296,8 @@ enum ImGuiDragFlags_
|
|||||||
ImGuiDragFlags_None = 0,
|
ImGuiDragFlags_None = 0,
|
||||||
ImGuiDragFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
|
ImGuiDragFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
|
||||||
ImGuiDragFlags_ClampOnInput = 1 << 4, // Clamp value to min/max bounds (if any) when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
|
ImGuiDragFlags_ClampOnInput = 1 << 4, // Clamp value to min/max bounds (if any) when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
|
||||||
ImGuiDragFlags_Logarithmic = 1 << 5 // Should this widget be logarithmic? (linear otherwise)
|
ImGuiDragFlags_Logarithmic = 1 << 5, // Make the widget logarithmic (linear otherwise)
|
||||||
|
ImGuiDragFlags_NoRoundToFormat = 1 << 6 // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flags for SliderFloat(), SliderInt() etc.
|
// Flags for SliderFloat(), SliderInt() etc.
|
||||||
@ -1305,7 +1306,8 @@ enum ImGuiSliderFlags_
|
|||||||
ImGuiSliderFlags_None = 0,
|
ImGuiSliderFlags_None = 0,
|
||||||
ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
|
ImGuiSliderFlags_InvalidMask_ = 0x7000000F, // [Internal] We treat using those bits as being potentially a 'float power' argument from the previous API that has got miscast to this enum, and will trigger an assert if needed.
|
||||||
ImGuiSliderFlags_ClampOnInput = 1 << 4, // Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
|
ImGuiSliderFlags_ClampOnInput = 1 << 4, // Clamp value to min/max bounds when input manually with CTRL+Click. By default CTRL+Click allows going out of bounds.
|
||||||
ImGuiSliderFlags_Logarithmic = 1 << 5 // Should this widget be logarithmic? (linear otherwise)
|
ImGuiSliderFlags_Logarithmic = 1 << 5, // Make the widget logarithmic (linear otherwise)
|
||||||
|
ImGuiSliderFlags_NoRoundToFormat = 1 << 6 // Disable rounding underlying value to match precision of the display format string (e.g. %.3f values are rounded to those 3 digits)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Identify a mouse button.
|
// Identify a mouse button.
|
||||||
|
@ -1496,13 +1496,16 @@ static void ShowDemoWindowWidgets()
|
|||||||
ImGui::SameLine(); HelpMarker("Always clamp value to min/max bounds (if any) when input manually with CTRL+Click.");
|
ImGui::SameLine(); HelpMarker("Always clamp value to min/max bounds (if any) when input manually with CTRL+Click.");
|
||||||
ImGui::CheckboxFlags("ImGuiDragFlags_Logarithmic", (unsigned int*)&drag_flags, ImGuiDragFlags_Logarithmic);
|
ImGui::CheckboxFlags("ImGuiDragFlags_Logarithmic", (unsigned int*)&drag_flags, ImGuiDragFlags_Logarithmic);
|
||||||
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
||||||
|
ImGui::CheckboxFlags("ImGuiDragFlags_NoRoundToFormat", (unsigned int*)&drag_flags, ImGuiDragFlags_NoRoundToFormat);
|
||||||
|
ImGui::SameLine(); HelpMarker("Disable rounding underlying value to match precision of the format string (e.g. %.3f values are rounded to those 3 digits).");
|
||||||
|
|
||||||
static float drag_f = 0.5f;
|
static float drag_f = 0.5f;
|
||||||
static int drag_i = 50;
|
static int drag_i = 50;
|
||||||
ImGui::DragFloat("DragFloat (0 -> 1)", &drag_f, 0.005f, 0.0f, 1.0f, "%f", drag_flags);
|
ImGui::Text("Underlying float value: %f", drag_f);
|
||||||
ImGui::DragFloat("DragFloat (0 -> +inf)", &drag_f, 0.005f, 0.0f, FLT_MAX, "%f", drag_flags);
|
ImGui::DragFloat("DragFloat (0 -> 1)", &drag_f, 0.005f, 0.0f, 1.0f, "%.3f", drag_flags);
|
||||||
ImGui::DragFloat("DragFloat (-inf -> 1)", &drag_f, 0.005f, -FLT_MAX, 1.0f, "%f", drag_flags);
|
ImGui::DragFloat("DragFloat (0 -> +inf)", &drag_f, 0.005f, 0.0f, FLT_MAX, "%.3f", drag_flags);
|
||||||
ImGui::DragFloat("DragFloat (-inf -> +inf)", &drag_f, 0.005f, -FLT_MAX, +FLT_MAX, "%f", drag_flags);
|
ImGui::DragFloat("DragFloat (-inf -> 1)", &drag_f, 0.005f, -FLT_MAX, 1.0f, "%.3f", drag_flags);
|
||||||
|
ImGui::DragFloat("DragFloat (-inf -> +inf)", &drag_f, 0.005f, -FLT_MAX, +FLT_MAX, "%.3f", drag_flags);
|
||||||
ImGui::DragInt("DragInt (0 -> 100)", &drag_i, 0.5f, 0, 100, "%d", drag_flags);
|
ImGui::DragInt("DragInt (0 -> 100)", &drag_i, 0.5f, 0, 100, "%d", drag_flags);
|
||||||
|
|
||||||
// Demonstrate using advanced flags for SliderXXX functions
|
// Demonstrate using advanced flags for SliderXXX functions
|
||||||
@ -1511,11 +1514,14 @@ static void ShowDemoWindowWidgets()
|
|||||||
ImGui::SameLine(); HelpMarker("Always clamp value to min/max bounds (if any) when input manually with CTRL+Click.");
|
ImGui::SameLine(); HelpMarker("Always clamp value to min/max bounds (if any) when input manually with CTRL+Click.");
|
||||||
ImGui::CheckboxFlags("ImGuiSliderFlags_Logarithmic", (unsigned int*)&slider_flags, ImGuiSliderFlags_Logarithmic);
|
ImGui::CheckboxFlags("ImGuiSliderFlags_Logarithmic", (unsigned int*)&slider_flags, ImGuiSliderFlags_Logarithmic);
|
||||||
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
ImGui::SameLine(); HelpMarker("Enable logarithmic editing (more precision for small values).");
|
||||||
|
ImGui::CheckboxFlags("ImGuiSliderFlags_NoRoundToFormat", (unsigned int*)&slider_flags, ImGuiSliderFlags_NoRoundToFormat);
|
||||||
|
ImGui::SameLine(); HelpMarker("Disable rounding underlying value to match precision of the format string (e.g. %.3f values are rounded to those 3 digits).");
|
||||||
|
|
||||||
static float slider_f = 0.5f;
|
static float slider_f = 0.5f;
|
||||||
static int slider_i = 50;
|
static int slider_i = 50;
|
||||||
ImGui::SliderFloat("SliderFloat (0 -> 1)", &slider_f, 0.0f, 1.0f, NULL, slider_flags);
|
ImGui::Text("Underlying float value: %f", slider_f);
|
||||||
ImGui::SliderInt("SliderInt (0 -> 100)", &slider_i, 0, 100, NULL, slider_flags);
|
ImGui::SliderFloat("SliderFloat (0 -> 1)", &slider_f, 0.0f, 1.0f, "%.3f", slider_flags);
|
||||||
|
ImGui::SliderInt("SliderInt (0 -> 100)", &slider_i, 0, 100, "%.3f", slider_flags);
|
||||||
|
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
|
@ -2079,7 +2079,8 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Round to user desired precision based on format string
|
// Round to user desired precision based on format string
|
||||||
v_cur = RoundScalarWithFormatT<TYPE, SIGNEDTYPE>(format, data_type, v_cur);
|
if (!(flags & ImGuiDragFlags_NoRoundToFormat))
|
||||||
|
v_cur = RoundScalarWithFormatT<TYPE, SIGNEDTYPE>(format, data_type, v_cur);
|
||||||
|
|
||||||
// Preserve remainder after rounding has been applied. This also allow slow tweaking of values.
|
// Preserve remainder after rounding has been applied. This also allow slow tweaking of values.
|
||||||
g.DragCurrentAccumDirty = false;
|
g.DragCurrentAccumDirty = false;
|
||||||
@ -2636,7 +2637,8 @@ bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType data_typ
|
|||||||
TYPE v_new = SliderCalcValueFromRatioT<TYPE, FLOATTYPE>(data_type, clicked_t, v_min, v_max, logarithmic_zero_epsilon, flags);
|
TYPE v_new = SliderCalcValueFromRatioT<TYPE, FLOATTYPE>(data_type, clicked_t, v_min, v_max, logarithmic_zero_epsilon, flags);
|
||||||
|
|
||||||
// Round to user desired precision based on format string
|
// Round to user desired precision based on format string
|
||||||
v_new = RoundScalarWithFormatT<TYPE, SIGNEDTYPE>(format, data_type, v_new);
|
if (!(flags & ImGuiSliderFlags_NoRoundToFormat))
|
||||||
|
v_new = RoundScalarWithFormatT<TYPE, SIGNEDTYPE>(format, data_type, v_new);
|
||||||
|
|
||||||
// Apply result
|
// Apply result
|
||||||
if (*v != v_new)
|
if (*v != v_new)
|
||||||
|
Loading…
Reference in New Issue
Block a user