mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-14 17:07:01 +00:00
Drags, Sliders: Removed locking behavior with min > max (added in 1.73)
This commit is contained in:
parent
7f8f0096d8
commit
f32663b33c
@ -60,6 +60,8 @@ Breaking Changes:
|
||||
See https://github.com/ocornut/imgui/issues/3361 for all details.
|
||||
Kept inline redirection functions (will obsolete) apart for: DragFloatRange2(), VSliderFloat(), VSliderScalar().
|
||||
For those three the 'float power=1.0f' version was removed directly as they were most unlikely ever used.
|
||||
- DragInt, DragFloat, DragScalar: Obsoleted use of v_min > v_max to lock edits (introduced in 1.73, this was not
|
||||
demoed nor documented much, will be replaced a more generic ReadOnly feature).
|
||||
|
||||
Other Changes:
|
||||
|
||||
|
@ -380,6 +380,7 @@ CODE
|
||||
- if you set the 'power' parameter to >1.0f (to enable non-linear editing): 1/ your compiler may warn on float>int conversion, 2/ code will assert at runtime, 3/ in case asserts are disabled, the code will not crash and enable the _Logarithmic flag. 4/ you can replace the >1.0f value with ImGuiDragFlags_Logarithmic or ImGuiSliderFlags_Logarithmic flag to fix the warning/assert and get a _similar_ effect as previous uses of power >1.0f.
|
||||
see https://github.com/ocornut/imgui/issues/3361 for all details.
|
||||
kept inline redirection functions (will obsolete) apart for: DragFloatRange2(), VSliderFloat(), VSliderScalar(). For those three the 'float power=1.0f' version were removed directly as they were most unlikely ever used.
|
||||
- obsoleted use of v_min > v_max in DragInt, DragFloat, DragScalar to lock edits (introduced in 1.73, was not demoed nor documented very), will be replaced by a more generic ReadOnly feature. You may use the ImGuiDragFlags_ReadOnly internal flag in the meantime.
|
||||
- 2020/06/23 (1.77) - removed BeginPopupContextWindow(const char*, int mouse_button, bool also_over_items) in favor of BeginPopupContextWindow(const char*, ImGuiPopupFlags flags) with ImGuiPopupFlags_NoOverItems.
|
||||
- 2020/06/15 (1.77) - renamed OpenPopupOnItemClick() to OpenPopupContextItem(). Kept inline redirection function (will obsolete).
|
||||
- 2020/06/15 (1.77) - removed CalcItemRectClosestPoint() entry point which was made obsolete and asserting in December 2017.
|
||||
|
@ -1534,7 +1534,7 @@ static void ShowDemoWindowWidgets()
|
||||
{
|
||||
static float begin = 10, end = 90;
|
||||
static int begin_i = 100, end_i = 1000;
|
||||
ImGui::DragFloatRange2("range float", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%");
|
||||
ImGui::DragFloatRange2("range float", &begin, &end, 0.25f, 0.0f, 100.0f, "Min: %.1f %%", "Max: %.1f %%", ImGuiDragFlags_ClampOnInput);
|
||||
ImGui::DragIntRange2("range int", &begin_i, &end_i, 5, 0, 1000, "Min: %d units", "Max: %d units");
|
||||
ImGui::DragIntRange2("range int (no bounds)", &begin_i, &end_i, 5, 0, 0, "Min: %d units", "Max: %d units");
|
||||
ImGui::TreePop();
|
||||
|
@ -634,13 +634,15 @@ enum ImGuiButtonFlagsPrivate_
|
||||
// Extend ImGuiDragFlags_
|
||||
enum ImGuiDragFlagsPrivate_
|
||||
{
|
||||
ImGuiDragFlags_Vertical = 1 << 20 // Should this widget be orientated vertically?
|
||||
ImGuiDragFlags_Vertical = 1 << 20, // Should this widget be orientated vertically?
|
||||
ImGuiDragFlags_ReadOnly = 1 << 21
|
||||
};
|
||||
|
||||
// Extend ImGuiSliderFlags_
|
||||
enum ImGuiSliderFlagsPrivate_
|
||||
{
|
||||
ImGuiSliderFlags_Vertical = 1 << 20 // Should this slider be orientated vertically?
|
||||
ImGuiSliderFlags_Vertical = 1 << 20, // Should this slider be orientated vertically?
|
||||
ImGuiSliderFlags_ReadOnly = 1 << 21
|
||||
};
|
||||
|
||||
// Extend ImGuiSelectableFlags_
|
||||
|
@ -2005,9 +2005,6 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
||||
const bool is_decimal = (data_type == ImGuiDataType_Float) || (data_type == ImGuiDataType_Double);
|
||||
const bool is_clamped = (v_min < v_max);
|
||||
const bool is_logarithmic = (flags & ImGuiDragFlags_Logarithmic) && is_decimal;
|
||||
const bool is_locked = (v_min > v_max);
|
||||
if (is_locked)
|
||||
return false;
|
||||
|
||||
// Default tweak speed
|
||||
if (v_speed == 0.0f && is_clamped && (v_max - v_min < FLT_MAX))
|
||||
@ -2131,7 +2128,7 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v
|
||||
}
|
||||
if (g.ActiveId != id)
|
||||
return false;
|
||||
if (g.CurrentWindow->DC.ItemFlags & ImGuiItemFlags_ReadOnly)
|
||||
if ((g.CurrentWindow->DC.ItemFlags & ImGuiItemFlags_ReadOnly) || (flags & ImGuiDragFlags_ReadOnly))
|
||||
return false;
|
||||
|
||||
switch (data_type)
|
||||
@ -2285,6 +2282,7 @@ bool ImGui::DragFloat4(const char* label, float v[4], float v_speed, float v_min
|
||||
return DragScalarN(label, ImGuiDataType_Float, v, 4, v_speed, &v_min, &v_max, format, flags);
|
||||
}
|
||||
|
||||
// NB: You likely want to specify the ImGuiDragFlags_ClampOnInput when using this.
|
||||
bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_current_max, float v_speed, float v_min, float v_max, const char* format, const char* format_max, ImGuiDragFlags flags)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
@ -2296,17 +2294,17 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu
|
||||
BeginGroup();
|
||||
PushMultiItemsWidths(2, CalcItemWidth());
|
||||
|
||||
float min = (v_min >= v_max) ? -FLT_MAX : v_min;
|
||||
float max = (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max);
|
||||
if (min == max) { min = FLT_MAX; max = -FLT_MAX; } // Lock edit
|
||||
bool value_changed = DragScalar("##min", ImGuiDataType_Float, v_current_min, v_speed, &min, &max, format, flags);
|
||||
float min_min = (v_min >= v_max) ? -FLT_MAX : v_min;
|
||||
float min_max = (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max);
|
||||
ImGuiDragFlags min_flags = flags | ((min_min == min_max) ? ImGuiDragFlags_ReadOnly : 0);
|
||||
bool value_changed = DragScalar("##min", ImGuiDataType_Float, v_current_min, v_speed, &min_min, &min_max, format, min_flags);
|
||||
PopItemWidth();
|
||||
SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
|
||||
min = (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min);
|
||||
max = (v_min >= v_max) ? FLT_MAX : v_max;
|
||||
if (min == max) { min = FLT_MAX; max = -FLT_MAX; } // Lock edit
|
||||
value_changed |= DragScalar("##max", ImGuiDataType_Float, v_current_max, v_speed, &min, &max, format_max ? format_max : format, flags);
|
||||
float max_min = (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min);
|
||||
float max_max = (v_min >= v_max) ? FLT_MAX : v_max;
|
||||
ImGuiDragFlags max_flags = flags | ((max_min == max_max) ? ImGuiDragFlags_ReadOnly : 0);
|
||||
value_changed |= DragScalar("##max", ImGuiDataType_Float, v_current_max, v_speed, &max_min, &max_max, format_max ? format_max : format, max_flags);
|
||||
PopItemWidth();
|
||||
SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
|
||||
@ -2337,6 +2335,7 @@ bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int
|
||||
return DragScalarN(label, ImGuiDataType_S32, v, 4, v_speed, &v_min, &v_max, format, flags);
|
||||
}
|
||||
|
||||
// NB: You likely want to specify the ImGuiDragFlags_ClampOnInput when using this.
|
||||
bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed, int v_min, int v_max, const char* format, const char* format_max, ImGuiDragFlags flags)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
@ -2348,17 +2347,17 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_
|
||||
BeginGroup();
|
||||
PushMultiItemsWidths(2, CalcItemWidth());
|
||||
|
||||
int min = (v_min >= v_max) ? INT_MIN : v_min;
|
||||
int max = (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max);
|
||||
if (min == max) { min = INT_MAX; max = INT_MIN; } // Lock edit
|
||||
bool value_changed = DragInt("##min", v_current_min, v_speed, min, max, format, flags);
|
||||
int min_min = (v_min >= v_max) ? INT_MIN : v_min;
|
||||
int min_max = (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max);
|
||||
ImGuiDragFlags min_flags = flags | ((min_min == min_max) ? ImGuiDragFlags_ReadOnly : 0);
|
||||
bool value_changed = DragInt("##min", v_current_min, v_speed, min_min, min_max, format, min_flags);
|
||||
PopItemWidth();
|
||||
SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
|
||||
min = (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min);
|
||||
max = (v_min >= v_max) ? INT_MAX : v_max;
|
||||
if (min == max) { min = INT_MAX; max = INT_MIN; } // Lock edit
|
||||
value_changed |= DragInt("##max", v_current_max, v_speed, min, max, format_max ? format_max : format, flags);
|
||||
int max_min = (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min);
|
||||
int max_max = (v_min >= v_max) ? INT_MAX : v_max;
|
||||
ImGuiDragFlags max_flags = flags | ((max_min == max_max) ? ImGuiDragFlags_ReadOnly : 0);
|
||||
value_changed |= DragInt("##max", v_current_max, v_speed, max_min, max_max, format_max ? format_max : format, max_flags);
|
||||
PopItemWidth();
|
||||
SameLine(0, g.Style.ItemInnerSpacing.x);
|
||||
|
||||
@ -2720,7 +2719,7 @@ bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type
|
||||
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.");
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.CurrentWindow->DC.ItemFlags & ImGuiItemFlags_ReadOnly)
|
||||
if ((g.CurrentWindow->DC.ItemFlags & ImGuiItemFlags_ReadOnly) || (flags & ImGuiSliderFlags_ReadOnly))
|
||||
return false;
|
||||
|
||||
switch (data_type)
|
||||
|
Loading…
Reference in New Issue
Block a user