mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 03:58:47 +02:00
Merge branch 'master' into docking
# Conflicts: # docs/CHANGELOG.txt # imgui.h
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
// dear imgui, v1.78 WIP
|
||||
// dear imgui, v1.78
|
||||
// (widgets code)
|
||||
|
||||
/*
|
||||
@ -2005,13 +2005,13 @@ TYPE ImGui::RoundScalarWithFormatT(const char* format, ImGuiDataType data_type,
|
||||
|
||||
// This is called by DragBehavior() when the widget is active (held by mouse or being manipulated with Nav controls)
|
||||
template<typename TYPE, typename SIGNEDTYPE, typename FLOATTYPE>
|
||||
bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const TYPE v_min, const TYPE v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const TYPE v_min, const TYPE v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
const ImGuiAxis axis = (flags & ImGuiDragFlags_Vertical) ? ImGuiAxis_Y : ImGuiAxis_X;
|
||||
const ImGuiAxis axis = (flags & ImGuiSliderFlags_Vertical) ? ImGuiAxis_Y : ImGuiAxis_X;
|
||||
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_logarithmic = (flags & ImGuiSliderFlags_Logarithmic) && is_decimal;
|
||||
|
||||
// Default tweak speed
|
||||
if (v_speed == 0.0f && is_clamped && (v_max - v_min < FLT_MAX))
|
||||
@ -2084,7 +2084,7 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
||||
}
|
||||
|
||||
// Round to user desired precision based on format string
|
||||
if (!(flags & ImGuiDragFlags_NoRoundToFormat))
|
||||
if (!(flags & ImGuiSliderFlags_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.
|
||||
@ -2120,10 +2120,10 @@ bool ImGui::DragBehaviorT(ImGuiDataType data_type, TYPE* v, float v_speed, const
|
||||
return true;
|
||||
}
|
||||
|
||||
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, ImGuiDragFlags flags)
|
||||
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 & ImGuiDragFlags_InvalidMask_) == 0) && "Invalid ImGuiDragFlags flags! Has the 'float power' argument been mistakenly cast to flags? Call function with ImGuiDragFlags_Logarithmic flags instead.");
|
||||
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.");
|
||||
|
||||
ImGuiContext& g = *GImGui;
|
||||
if (g.ActiveId == id)
|
||||
@ -2135,7 +2135,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) || (flags & ImGuiDragFlags_ReadOnly))
|
||||
if ((g.CurrentWindow->DC.ItemFlags & ImGuiItemFlags_ReadOnly) || (flags & ImGuiSliderFlags_ReadOnly))
|
||||
return false;
|
||||
|
||||
switch (data_type)
|
||||
@ -2158,7 +2158,7 @@ bool ImGui::DragBehavior(ImGuiID id, ImGuiDataType data_type, void* p_v, float v
|
||||
|
||||
// Note: p_data, p_min and p_max are _pointers_ to a memory address holding the data. For a Drag widget, p_min and p_max are optional.
|
||||
// Read code of e.g. DragFloat(), DragInt() etc. or examples in 'Demo->Widgets->Data Types' to understand how to use this function directly.
|
||||
bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
@ -2184,7 +2184,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data,
|
||||
|
||||
// Tabbing or CTRL-clicking on Drag turns it into an input box
|
||||
const bool hovered = ItemHoverable(frame_bb, id);
|
||||
const bool temp_input_allowed = (flags & ImGuiDragFlags_NoInput) == 0;
|
||||
const bool temp_input_allowed = (flags & ImGuiSliderFlags_NoInput) == 0;
|
||||
bool temp_input_is_active = temp_input_allowed && TempInputIsActive(id);
|
||||
if (!temp_input_is_active)
|
||||
{
|
||||
@ -2207,8 +2207,8 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data,
|
||||
|
||||
if (temp_input_is_active)
|
||||
{
|
||||
// Only clamp CTRL+Click input when ImGuiDragFlags_ClampInput is set
|
||||
const bool is_clamp_input = (flags & ImGuiDragFlags_ClampOnInput) != 0;
|
||||
// Only clamp CTRL+Click input when ImGuiSliderFlags_ClampInput is set
|
||||
const bool is_clamp_input = (flags & ImGuiSliderFlags_ClampOnInput) != 0;
|
||||
return TempInputScalar(frame_bb, id, label, data_type, p_data, format, is_clamp_input ? p_min : NULL, is_clamp_input ? p_max : NULL);
|
||||
}
|
||||
|
||||
@ -2234,7 +2234,7 @@ bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data,
|
||||
return value_changed;
|
||||
}
|
||||
|
||||
bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, float v_speed, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
@ -2269,28 +2269,28 @@ bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* p_data
|
||||
return value_changed;
|
||||
}
|
||||
|
||||
bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, float v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, float v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
return DragScalar(label, ImGuiDataType_Float, v, v_speed, &v_min, &v_max, format, flags);
|
||||
}
|
||||
|
||||
bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
return DragScalarN(label, ImGuiDataType_Float, v, 2, v_speed, &v_min, &v_max, format, flags);
|
||||
}
|
||||
|
||||
bool ImGui::DragFloat3(const char* label, float v[3], float v_speed, float v_min, float v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragFloat3(const char* label, float v[3], float v_speed, float v_min, float v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
return DragScalarN(label, ImGuiDataType_Float, v, 3, v_speed, &v_min, &v_max, format, flags);
|
||||
}
|
||||
|
||||
bool ImGui::DragFloat4(const char* label, float v[4], float v_speed, float v_min, float v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragFloat4(const char* label, float v[4], float v_speed, float v_min, float v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
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)
|
||||
// NB: You likely want to specify the ImGuiSliderFlags_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, ImGuiSliderFlags flags)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
@ -2303,14 +2303,14 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu
|
||||
|
||||
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);
|
||||
ImGuiSliderFlags min_flags = flags | ((min_min == min_max) ? ImGuiSliderFlags_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);
|
||||
|
||||
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);
|
||||
ImGuiSliderFlags max_flags = flags | ((max_min == max_max) ? ImGuiSliderFlags_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);
|
||||
@ -2322,28 +2322,28 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu
|
||||
}
|
||||
|
||||
// NB: v_speed is float to allow adjusting the drag speed with more precision
|
||||
bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
return DragScalar(label, ImGuiDataType_S32, v, v_speed, &v_min, &v_max, format, flags);
|
||||
}
|
||||
|
||||
bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
return DragScalarN(label, ImGuiDataType_S32, v, 2, v_speed, &v_min, &v_max, format, flags);
|
||||
}
|
||||
|
||||
bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
return DragScalarN(label, ImGuiDataType_S32, v, 3, v_speed, &v_min, &v_max, format, flags);
|
||||
}
|
||||
|
||||
bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* format, ImGuiDragFlags flags)
|
||||
bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* format, ImGuiSliderFlags flags)
|
||||
{
|
||||
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)
|
||||
// NB: You likely want to specify the ImGuiSliderFlags_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, ImGuiSliderFlags flags)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
@ -2356,14 +2356,14 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_
|
||||
|
||||
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);
|
||||
ImGuiSliderFlags min_flags = flags | ((min_min == min_max) ? ImGuiSliderFlags_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);
|
||||
|
||||
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);
|
||||
ImGuiSliderFlags max_flags = flags | ((max_min == max_max) ? ImGuiSliderFlags_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);
|
||||
@ -2380,24 +2380,24 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_
|
||||
// Obsolete versions with power parameter. See https://github.com/ocornut/imgui/issues/3361 for details.
|
||||
bool ImGui::DragScalar(const char* label, ImGuiDataType data_type, void* p_data, float v_speed, const void* p_min, const void* p_max, const char* format, float power)
|
||||
{
|
||||
ImGuiDragFlags drag_flags = ImGuiDragFlags_None;
|
||||
ImGuiSliderFlags drag_flags = ImGuiSliderFlags_None;
|
||||
if (power != 1.0f)
|
||||
{
|
||||
IM_ASSERT(power == 1.0f && "Call function with ImGuiDragFlags_Logarithmic flags instead of using the old 'float power' function!");
|
||||
IM_ASSERT(power == 1.0f && "Call function with ImGuiSliderFlags_Logarithmic flags instead of using the old 'float power' function!");
|
||||
IM_ASSERT(p_min != NULL && p_max != NULL); // When using a power curve the drag needs to have known bounds
|
||||
drag_flags |= ImGuiDragFlags_Logarithmic; // Fallback for non-asserting paths
|
||||
drag_flags |= ImGuiSliderFlags_Logarithmic; // Fallback for non-asserting paths
|
||||
}
|
||||
return DragScalar(label, data_type, p_data, v_speed, p_min, p_max, format, drag_flags);
|
||||
}
|
||||
|
||||
bool ImGui::DragScalarN(const char* label, ImGuiDataType data_type, void* p_data, int components, float v_speed, const void* p_min, const void* p_max, const char* format, float power)
|
||||
{
|
||||
ImGuiDragFlags drag_flags = ImGuiDragFlags_None;
|
||||
ImGuiSliderFlags drag_flags = ImGuiSliderFlags_None;
|
||||
if (power != 1.0f)
|
||||
{
|
||||
IM_ASSERT(power == 1.0f && "Call function with ImGuiDragFlags_Logarithmic flags instead of using the old 'float power' function!");
|
||||
IM_ASSERT(power == 1.0f && "Call function with ImGuiSliderFlags_Logarithmic flags instead of using the old 'float power' function!");
|
||||
IM_ASSERT(p_min != NULL && p_max != NULL); // When using a power curve the drag needs to have known bounds
|
||||
drag_flags |= ImGuiDragFlags_Logarithmic; // Fallback for non-asserting paths
|
||||
drag_flags |= ImGuiSliderFlags_Logarithmic; // Fallback for non-asserting paths
|
||||
}
|
||||
return DragScalarN(label, data_type, p_data, components, v_speed, p_min, p_max, format, drag_flags);
|
||||
}
|
||||
@ -3140,7 +3140,7 @@ bool ImGui::TempInputText(const ImRect& bb, ImGuiID id, const char* label, char*
|
||||
}
|
||||
|
||||
// Note that Drag/Slider functions are only forwarding the min/max values clamping values if the
|
||||
// ImGuiDragFlags_ClampOnInput / ImGuiSliderFlags_ClampOnInput flag is set!
|
||||
// ImGuiSliderFlags_ClampOnInput / ImGuiSliderFlags_ClampOnInput flag is set!
|
||||
// This is intended: this way we allow CTRL+Click manual input to set a value out of bounds, for maximum flexibility.
|
||||
// However this may not be ideal for all uses, as some user code may break on out of bound values.
|
||||
bool ImGui::TempInputScalar(const ImRect& bb, ImGuiID id, const char* label, ImGuiDataType data_type, void* p_data, const char* format, const void* p_clamp_min, const void* p_clamp_max)
|
||||
|
Reference in New Issue
Block a user