|
|
@@ -262,6 +262,7 @@
|
|
|
Here is a change-log of API breaking changes, if you are using one of the functions listed, expect to have to fix some code.
|
|
|
Also read releases logs https://github.com/ocornut/imgui/releases for more details.
|
|
|
|
|
|
+ - 2018/04/28 (1.61) - obsoleted InputFloat() functions taking an optional "int decimal_precision" in favor of an equivalent and more flexible "const char* format", consistent with other functions. Kept redirection functions (will obsolete).
|
|
|
- 2018/04/09 (1.61) - IM_DELETE() helper function added in 1.60 doesn't clear the input _pointer_ reference, more consistent with expectation and allows passing r-value.
|
|
|
- 2018/03/20 (1.60) - Renamed io.WantMoveMouse to io.WantSetMousePos for consistency and ease of understanding (was added in 1.52, _not_ used by core and only honored by some binding ahead of merging the Nav branch).
|
|
|
- 2018/03/12 (1.60) - Removed ImGuiCol_CloseButton, ImGuiCol_CloseButtonActive, ImGuiCol_CloseButtonHovered as the closing cross uses regular button colors now.
|
|
|
@@ -749,10 +750,10 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInpu
|
|
|
static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end);
|
|
|
static ImVec2 InputTextCalcTextSizeW(const ImWchar* text_begin, const ImWchar* text_end, const ImWchar** remaining = NULL, ImVec2* out_offset = NULL, bool stop_on_new_line = false);
|
|
|
|
|
|
-static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, const char* display_format, char* buf, int buf_size);
|
|
|
-static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, int decimal_precision, char* buf, int buf_size);
|
|
|
+static inline int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* data_ptr, const char* format);
|
|
|
+static inline int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* data_ptr, int decimal_precision);
|
|
|
static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void* arg_1, const void* arg_2);
|
|
|
-static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* data_ptr, const char* scalar_format);
|
|
|
+static bool DataTypeApplyOpFromText(const char* buf, const char* initial_value_buf, ImGuiDataType data_type, void* data_ptr, const char* format);
|
|
|
|
|
|
namespace ImGui
|
|
|
{
|
|
|
@@ -8445,39 +8446,40 @@ void ImGui::BulletText(const char* fmt, ...)
|
|
|
va_end(args);
|
|
|
}
|
|
|
|
|
|
-static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, const char* display_format, char* buf, int buf_size)
|
|
|
+static inline int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* data_ptr, const char* format)
|
|
|
{
|
|
|
if (data_type == ImGuiDataType_Int)
|
|
|
- ImFormatString(buf, buf_size, display_format, *(int*)data_ptr);
|
|
|
- else if (data_type == ImGuiDataType_Float)
|
|
|
- ImFormatString(buf, buf_size, display_format, *(float*)data_ptr);
|
|
|
- else if (data_type == ImGuiDataType_Double)
|
|
|
- ImFormatString(buf, buf_size, display_format, *(double*)data_ptr);
|
|
|
+ return ImFormatString(buf, buf_size, format, *(const int*)data_ptr);
|
|
|
+ if (data_type == ImGuiDataType_Float)
|
|
|
+ return ImFormatString(buf, buf_size, format, *(const float*)data_ptr);
|
|
|
+ if (data_type == ImGuiDataType_Double)
|
|
|
+ return ImFormatString(buf, buf_size, format, *(const double*)data_ptr);
|
|
|
+ IM_ASSERT(0);
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
-static inline void DataTypeFormatString(ImGuiDataType data_type, void* data_ptr, int decimal_precision, char* buf, int buf_size)
|
|
|
+static inline int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType data_type, const void* data_ptr, int decimal_precision)
|
|
|
{
|
|
|
- if (data_type == ImGuiDataType_Int)
|
|
|
- {
|
|
|
- if (decimal_precision < 0)
|
|
|
- ImFormatString(buf, buf_size, "%d", *(int*)data_ptr);
|
|
|
- else
|
|
|
- ImFormatString(buf, buf_size, "%.*d", decimal_precision, *(int*)data_ptr);
|
|
|
- }
|
|
|
- else if (data_type == ImGuiDataType_Float)
|
|
|
+ if (decimal_precision < 0)
|
|
|
{
|
|
|
- if (decimal_precision < 0)
|
|
|
- ImFormatString(buf, buf_size, "%f", *(float*)data_ptr); // Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding non-significant digits?
|
|
|
- else
|
|
|
- ImFormatString(buf, buf_size, "%.*f", decimal_precision, *(float*)data_ptr);
|
|
|
+ if (data_type == ImGuiDataType_Int)
|
|
|
+ return ImFormatString(buf, buf_size, "%d", *(const int*)data_ptr);
|
|
|
+ if (data_type == ImGuiDataType_Float)
|
|
|
+ return ImFormatString(buf, buf_size, "%f", *(const float*)data_ptr); // Ideally we'd have a minimum decimal precision of 1 to visually denote that it is a float, while hiding non-significant digits?
|
|
|
+ if (data_type == ImGuiDataType_Double)
|
|
|
+ return ImFormatString(buf, buf_size, "%f", *(const double*)data_ptr);
|
|
|
}
|
|
|
- else if (data_type == ImGuiDataType_Double)
|
|
|
+ else
|
|
|
{
|
|
|
- if (decimal_precision < 0)
|
|
|
- ImFormatString(buf, buf_size, "%f", *(double*)data_ptr);
|
|
|
- else
|
|
|
- ImFormatString(buf, buf_size, "%.*f", decimal_precision, *(double*)data_ptr);
|
|
|
+ if (data_type == ImGuiDataType_Int)
|
|
|
+ return ImFormatString(buf, buf_size, "%.*d", decimal_precision, *(const int*)data_ptr);
|
|
|
+ if (data_type == ImGuiDataType_Float)
|
|
|
+ return ImFormatString(buf, buf_size, "%.*f", decimal_precision, *(const float*)data_ptr);
|
|
|
+ if (data_type == ImGuiDataType_Double)
|
|
|
+ return ImFormatString(buf, buf_size, "%.*g", decimal_precision, *(const double*)data_ptr);
|
|
|
}
|
|
|
+ IM_ASSERT(0);
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void* arg1, const void* arg2)
|
|
|
@@ -8485,18 +8487,18 @@ static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void*
|
|
|
IM_ASSERT(op == '+' || op == '-');
|
|
|
if (data_type == ImGuiDataType_Int)
|
|
|
{
|
|
|
- if (op == '+') *(int*)output = *(int*)arg1 + *(const int*)arg2;
|
|
|
- else if (op == '-') *(int*)output = *(int*)arg1 - *(const int*)arg2;
|
|
|
+ if (op == '+') *(int*)output = *(const int*)arg1 + *(const int*)arg2;
|
|
|
+ else if (op == '-') *(int*)output = *(const int*)arg1 - *(const int*)arg2;
|
|
|
}
|
|
|
else if (data_type == ImGuiDataType_Float)
|
|
|
{
|
|
|
- if (op == '+') *(float*)output = *(float*)arg1 + *(const float*)arg2;
|
|
|
- else if (op == '-') *(float*)output = *(float*)arg1 - *(const float*)arg2;
|
|
|
+ if (op == '+') *(float*)output = *(const float*)arg1 + *(const float*)arg2;
|
|
|
+ else if (op == '-') *(float*)output = *(const float*)arg1 - *(const float*)arg2;
|
|
|
}
|
|
|
else if (data_type == ImGuiDataType_Double)
|
|
|
{
|
|
|
- if (op == '+') *(double*)output = *(double*)arg1 + *(const double*)arg2;
|
|
|
- else if (op == '-') *(double*)output = *(double*)arg1 - *(const double*)arg2;
|
|
|
+ if (op == '+') *(double*)output = *(const double*)arg1 + *(const double*)arg2;
|
|
|
+ else if (op == '-') *(double*)output = *(const double*)arg1 - *(const double*)arg2;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -8597,8 +8599,9 @@ bool ImGui::InputScalarAsWidgetReplacement(const ImRect& aabb, const char* label
|
|
|
FocusableItemUnregister(window);
|
|
|
|
|
|
char buf[32];
|
|
|
- DataTypeFormatString(data_type, data_ptr, decimal_precision, buf, IM_ARRAYSIZE(buf));
|
|
|
- bool text_value_changed = InputTextEx(label, buf, IM_ARRAYSIZE(buf), aabb.GetSize(), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll);
|
|
|
+ DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, data_ptr, decimal_precision);
|
|
|
+ ImGuiInputTextFlags flags = ImGuiInputTextFlags_AutoSelectAll | ((data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImGuiInputTextFlags_CharsScientific : ImGuiInputTextFlags_CharsDecimal);
|
|
|
+ bool text_value_changed = InputTextEx(label, buf, IM_ARRAYSIZE(buf), aabb.GetSize(), flags);
|
|
|
if (g.ScalarAsInputTextId == 0) // First frame we started displaying the InputText widget
|
|
|
{
|
|
|
IM_ASSERT(g.ActiveId == id); // InputText ID expected to match the Slider ID (else we'd need to store them both, which is also possible)
|
|
|
@@ -8834,11 +8837,11 @@ bool ImGui::SliderBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v
|
|
|
}
|
|
|
|
|
|
// Use power!=1.0 for logarithmic sliders.
|
|
|
-// Adjust display_format to decorate the value with a prefix or a suffix.
|
|
|
+// Adjust format to decorate the value with a prefix or a suffix.
|
|
|
// "%.3f" 1.234
|
|
|
// "%5.2f secs" 01.23 secs
|
|
|
// "Gold: %.0f" Gold: 1
|
|
|
-bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -8861,9 +8864,9 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
|
|
|
}
|
|
|
const bool hovered = ItemHoverable(frame_bb, id);
|
|
|
|
|
|
- if (!display_format)
|
|
|
- display_format = "%.3f";
|
|
|
- int decimal_precision = ParseFormatPrecision(display_format, 3);
|
|
|
+ if (!format)
|
|
|
+ format = "%.3f";
|
|
|
+ int decimal_precision = ParseFormatPrecision(format, 3);
|
|
|
|
|
|
// Tabbing or CTRL-clicking on Slider turns it into an input box
|
|
|
bool start_text_input = false;
|
|
|
@@ -8889,7 +8892,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
|
|
|
|
|
|
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
|
|
|
char value_buf[64];
|
|
|
- const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
|
|
|
+ const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), format, *v);
|
|
|
RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f,0.5f));
|
|
|
|
|
|
if (label_size.x > 0.0f)
|
|
|
@@ -8898,7 +8901,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -8917,9 +8920,9 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float
|
|
|
return false;
|
|
|
const bool hovered = ItemHoverable(frame_bb, id);
|
|
|
|
|
|
- if (!display_format)
|
|
|
- display_format = "%.3f";
|
|
|
- int decimal_precision = ParseFormatPrecision(display_format, 3);
|
|
|
+ if (!format)
|
|
|
+ format = "%.3f";
|
|
|
+ int decimal_precision = ParseFormatPrecision(format, 3);
|
|
|
|
|
|
if ((hovered && g.IO.MouseClicked[0]) || g.NavActivateId == id || g.NavInputId == id)
|
|
|
{
|
|
|
@@ -8935,7 +8938,7 @@ bool ImGui::VSliderFloat(const char* label, const ImVec2& size, float* v, float
|
|
|
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
|
|
|
// For the vertical slider we allow centered text to overlap the frame padding
|
|
|
char value_buf[64];
|
|
|
- char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
|
|
|
+ char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), format, *v);
|
|
|
RenderTextClipped(ImVec2(frame_bb.Min.x, frame_bb.Min.y + style.FramePadding.y), frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f,0.0f));
|
|
|
if (label_size.x > 0.0f)
|
|
|
RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, frame_bb.Min.y + style.FramePadding.y), label);
|
|
|
@@ -8951,28 +8954,28 @@ bool ImGui::SliderAngle(const char* label, float* v_rad, float v_degrees_min, fl
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::SliderInt(const char* label, int* v, int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- if (!display_format)
|
|
|
- display_format = "%.0f";
|
|
|
+ if (!format)
|
|
|
+ format = "%.0f";
|
|
|
float v_f = (float)*v;
|
|
|
- bool value_changed = SliderFloat(label, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
|
|
|
+ bool value_changed = SliderFloat(label, &v_f, (float)v_min, (float)v_max, format, 1.0f);
|
|
|
*v = (int)v_f;
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::VSliderInt(const char* label, const ImVec2& size, int* v, int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- if (!display_format)
|
|
|
- display_format = "%.0f";
|
|
|
+ if (!format)
|
|
|
+ format = "%.0f";
|
|
|
float v_f = (float)*v;
|
|
|
- bool value_changed = VSliderFloat(label, size, &v_f, (float)v_min, (float)v_max, display_format, 1.0f);
|
|
|
+ bool value_changed = VSliderFloat(label, size, &v_f, (float)v_min, (float)v_max, format, 1.0f);
|
|
|
*v = (int)v_f;
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
// Add multiple sliders on 1 line for compact edition of multiple components
|
|
|
-bool ImGui::SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::SliderFloatN(const char* label, float* v, int components, float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -8986,7 +8989,7 @@ bool ImGui::SliderFloatN(const char* label, float* v, int components, float v_mi
|
|
|
for (int i = 0; i < components; i++)
|
|
|
{
|
|
|
PushID(i);
|
|
|
- value_changed |= SliderFloat("##v", &v[i], v_min, v_max, display_format, power);
|
|
|
+ value_changed |= SliderFloat("##v", &v[i], v_min, v_max, format, power);
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
PopID();
|
|
|
PopItemWidth();
|
|
|
@@ -8999,22 +9002,22 @@ bool ImGui::SliderFloatN(const char* label, float* v, int components, float v_mi
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::SliderFloat2(const char* label, float v[2], float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
- return SliderFloatN(label, v, 2, v_min, v_max, display_format, power);
|
|
|
+ return SliderFloatN(label, v, 2, v_min, v_max, format, power);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::SliderFloat3(const char* label, float v[3], float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
- return SliderFloatN(label, v, 3, v_min, v_max, display_format, power);
|
|
|
+ return SliderFloatN(label, v, 3, v_min, v_max, format, power);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::SliderFloat4(const char* label, float v[4], float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
- return SliderFloatN(label, v, 4, v_min, v_max, display_format, power);
|
|
|
+ return SliderFloatN(label, v, 4, v_min, v_max, format, power);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::SliderIntN(const char* label, int* v, int components, int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -9028,7 +9031,7 @@ bool ImGui::SliderIntN(const char* label, int* v, int components, int v_min, int
|
|
|
for (int i = 0; i < components; i++)
|
|
|
{
|
|
|
PushID(i);
|
|
|
- value_changed |= SliderInt("##v", &v[i], v_min, v_max, display_format);
|
|
|
+ value_changed |= SliderInt("##v", &v[i], v_min, v_max, format);
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
PopID();
|
|
|
PopItemWidth();
|
|
|
@@ -9041,19 +9044,19 @@ bool ImGui::SliderIntN(const char* label, int* v, int components, int v_min, int
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::SliderInt2(const char* label, int v[2], int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- return SliderIntN(label, v, 2, v_min, v_max, display_format);
|
|
|
+ return SliderIntN(label, v, 2, v_min, v_max, format);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::SliderInt3(const char* label, int v[3], int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- return SliderIntN(label, v, 3, v_min, v_max, display_format);
|
|
|
+ return SliderIntN(label, v, 3, v_min, v_max, format);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::SliderInt4(const char* label, int v[4], int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- return SliderIntN(label, v, 4, v_min, v_max, display_format);
|
|
|
+ return SliderIntN(label, v, 4, v_min, v_max, format);
|
|
|
}
|
|
|
|
|
|
bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_speed, float v_min, float v_max, int decimal_precision, float power)
|
|
|
@@ -9066,8 +9069,6 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
|
|
|
RenderNavHighlight(frame_bb, id);
|
|
|
RenderFrame(frame_bb.Min, frame_bb.Max, frame_col, true, style.FrameRounding);
|
|
|
|
|
|
- bool value_changed = false;
|
|
|
-
|
|
|
// Process interacting with the drag
|
|
|
if (g.ActiveId == id)
|
|
|
{
|
|
|
@@ -9076,75 +9077,79 @@ bool ImGui::DragBehavior(const ImRect& frame_bb, ImGuiID id, float* v, float v_s
|
|
|
else if (g.ActiveIdSource == ImGuiInputSource_Nav && g.NavActivatePressedId == id && !g.ActiveIdIsJustActivated)
|
|
|
ClearActiveID();
|
|
|
}
|
|
|
- if (g.ActiveId == id)
|
|
|
+ if (g.ActiveId != id)
|
|
|
+ return 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
|
|
|
- g.DragCurrentValue = *v;
|
|
|
- g.DragLastMouseDelta = ImVec2(0.f, 0.f);
|
|
|
- }
|
|
|
+ // Lock current value on click
|
|
|
+ g.DragCurrentValue = *v;
|
|
|
+ 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;
|
|
|
+ const ImVec2 mouse_drag_delta = GetMouseDragDelta(0, 1.0f);
|
|
|
+ float adjust_delta = 0.0f;
|
|
|
+ if (g.ActiveIdSource == ImGuiInputSource_Mouse && IsMousePosValid())
|
|
|
+ {
|
|
|
+ adjust_delta = mouse_drag_delta.x - g.DragLastMouseDelta.x;
|
|
|
+ if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
|
|
|
+ adjust_delta *= g.DragSpeedScaleFast;
|
|
|
+ if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
|
|
|
+ adjust_delta *= g.DragSpeedScaleSlow;
|
|
|
+ g.DragLastMouseDelta.x = mouse_drag_delta.x;
|
|
|
+ }
|
|
|
+ if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
|
|
+ {
|
|
|
+ adjust_delta = GetNavInputAmount2d(ImGuiNavDirSourceFlags_Keyboard|ImGuiNavDirSourceFlags_PadDPad, ImGuiInputReadMode_RepeatFast, 1.0f/10.0f, 10.0f).x;
|
|
|
+ v_speed = ImMax(v_speed, GetMinimumStepAtDecimalPrecision(decimal_precision));
|
|
|
+ }
|
|
|
+ adjust_delta *= v_speed;
|
|
|
|
|
|
- float v_cur = g.DragCurrentValue;
|
|
|
- const ImVec2 mouse_drag_delta = GetMouseDragDelta(0, 1.0f);
|
|
|
- float adjust_delta = 0.0f;
|
|
|
- if (g.ActiveIdSource == ImGuiInputSource_Mouse && IsMousePosValid())
|
|
|
+ // 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(power - 1.0f) > 0.001f)
|
|
|
{
|
|
|
- adjust_delta = mouse_drag_delta.x - g.DragLastMouseDelta.x;
|
|
|
- if (g.IO.KeyShift && g.DragSpeedScaleFast >= 0.0f)
|
|
|
- adjust_delta *= g.DragSpeedScaleFast;
|
|
|
- if (g.IO.KeyAlt && g.DragSpeedScaleSlow >= 0.0f)
|
|
|
- adjust_delta *= g.DragSpeedScaleSlow;
|
|
|
- g.DragLastMouseDelta.x = mouse_drag_delta.x;
|
|
|
+ // Logarithmic curve on both side of 0.0
|
|
|
+ float v0_abs = v_cur >= 0.0f ? v_cur : -v_cur;
|
|
|
+ float v0_sign = v_cur >= 0.0f ? 1.0f : -1.0f;
|
|
|
+ float v1 = powf(v0_abs, 1.0f / power) + (adjust_delta * v0_sign);
|
|
|
+ float v1_abs = v1 >= 0.0f ? v1 : -v1;
|
|
|
+ float v1_sign = v1 >= 0.0f ? 1.0f : -1.0f; // Crossed sign line
|
|
|
+ v_cur = powf(v1_abs, power) * v0_sign * v1_sign; // Reapply sign
|
|
|
}
|
|
|
- if (g.ActiveIdSource == ImGuiInputSource_Nav)
|
|
|
+ else
|
|
|
{
|
|
|
- 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_cur += adjust_delta;
|
|
|
}
|
|
|
- adjust_delta *= v_speed;
|
|
|
-
|
|
|
- if (fabsf(adjust_delta) > 0.0f)
|
|
|
- {
|
|
|
- if (fabsf(power - 1.0f) > 0.001f)
|
|
|
- {
|
|
|
- // Logarithmic curve on both side of 0.0
|
|
|
- float v0_abs = v_cur >= 0.0f ? v_cur : -v_cur;
|
|
|
- float v0_sign = v_cur >= 0.0f ? 1.0f : -1.0f;
|
|
|
- float v1 = powf(v0_abs, 1.0f / power) + (adjust_delta * v0_sign);
|
|
|
- float v1_abs = v1 >= 0.0f ? v1 : -v1;
|
|
|
- float v1_sign = v1 >= 0.0f ? 1.0f : -1.0f; // Crossed sign line
|
|
|
- v_cur = powf(v1_abs, power) * v0_sign * v1_sign; // Reapply sign
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- v_cur += adjust_delta;
|
|
|
- }
|
|
|
|
|
|
- // Clamp
|
|
|
- if (v_min < v_max)
|
|
|
- v_cur = ImClamp(v_cur, v_min, v_max);
|
|
|
- g.DragCurrentValue = v_cur;
|
|
|
- }
|
|
|
+ // Clamp
|
|
|
+ if (v_min < v_max)
|
|
|
+ v_cur = ImClamp(v_cur, v_min, v_max);
|
|
|
+ g.DragCurrentValue = v_cur;
|
|
|
+ }
|
|
|
|
|
|
- // Round to user desired precision, then apply
|
|
|
- v_cur = RoundScalar(v_cur, decimal_precision);
|
|
|
- if (*v != v_cur)
|
|
|
- {
|
|
|
- *v = v_cur;
|
|
|
- value_changed = true;
|
|
|
- }
|
|
|
+ // Round to user desired precision, then apply
|
|
|
+ bool value_changed = false;
|
|
|
+ v_cur = RoundScalar(v_cur, decimal_precision);
|
|
|
+ if (*v != v_cur)
|
|
|
+ {
|
|
|
+ *v = v_cur;
|
|
|
+ value_changed = true;
|
|
|
}
|
|
|
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -9168,9 +9173,9 @@ bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, f
|
|
|
}
|
|
|
const bool hovered = ItemHoverable(frame_bb, id);
|
|
|
|
|
|
- if (!display_format)
|
|
|
- display_format = "%.3f";
|
|
|
- int decimal_precision = ParseFormatPrecision(display_format, 3);
|
|
|
+ if (!format)
|
|
|
+ format = "%.3f";
|
|
|
+ int decimal_precision = ParseFormatPrecision(format, 3);
|
|
|
|
|
|
// Tabbing or CTRL-clicking on Drag turns it into an input box
|
|
|
bool start_text_input = false;
|
|
|
@@ -9196,7 +9201,7 @@ bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, f
|
|
|
|
|
|
// Display value using user-provided display format so user can add prefix/suffix/decorations to the value.
|
|
|
char value_buf[64];
|
|
|
- const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), display_format, *v);
|
|
|
+ const char* value_buf_end = value_buf + ImFormatString(value_buf, IM_ARRAYSIZE(value_buf), format, *v);
|
|
|
RenderTextClipped(frame_bb.Min, frame_bb.Max, value_buf, value_buf_end, NULL, ImVec2(0.5f,0.5f));
|
|
|
|
|
|
if (label_size.x > 0.0f)
|
|
|
@@ -9205,7 +9210,7 @@ bool ImGui::DragFloat(const char* label, float* v, float v_speed, float v_min, f
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::DragFloatN(const char* label, float* v, int components, float v_speed, float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -9219,7 +9224,7 @@ bool ImGui::DragFloatN(const char* label, float* v, int components, float v_spee
|
|
|
for (int i = 0; i < components; i++)
|
|
|
{
|
|
|
PushID(i);
|
|
|
- value_changed |= DragFloat("##v", &v[i], v_speed, v_min, v_max, display_format, power);
|
|
|
+ value_changed |= DragFloat("##v", &v[i], v_speed, v_min, v_max, format, power);
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
PopID();
|
|
|
PopItemWidth();
|
|
|
@@ -9232,22 +9237,22 @@ bool ImGui::DragFloatN(const char* label, float* v, int components, float v_spee
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::DragFloat2(const char* label, float v[2], float v_speed, float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
- return DragFloatN(label, v, 2, v_speed, v_min, v_max, display_format, power);
|
|
|
+ return DragFloatN(label, v, 2, v_speed, v_min, v_max, format, power);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragFloat3(const char* label, float v[3], float v_speed, float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::DragFloat3(const char* label, float v[3], float v_speed, float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
- return DragFloatN(label, v, 3, v_speed, v_min, v_max, display_format, power);
|
|
|
+ return DragFloatN(label, v, 3, v_speed, v_min, v_max, format, power);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragFloat4(const char* label, float v[4], float v_speed, float v_min, float v_max, const char* display_format, float power)
|
|
|
+bool ImGui::DragFloat4(const char* label, float v[4], float v_speed, float v_min, float v_max, const char* format, float power)
|
|
|
{
|
|
|
- return DragFloatN(label, v, 4, v_speed, v_min, v_max, display_format, power);
|
|
|
+ return DragFloatN(label, v, 4, v_speed, v_min, v_max, format, power);
|
|
|
}
|
|
|
|
|
|
-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* display_format, const char* display_format_max, float power)
|
|
|
+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, float power)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -9258,10 +9263,10 @@ bool ImGui::DragFloatRange2(const char* label, float* v_current_min, float* v_cu
|
|
|
BeginGroup();
|
|
|
PushMultiItemsWidths(2);
|
|
|
|
|
|
- bool value_changed = DragFloat("##min", v_current_min, v_speed, (v_min >= v_max) ? -FLT_MAX : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format, power);
|
|
|
+ bool value_changed = DragFloat("##min", v_current_min, v_speed, (v_min >= v_max) ? -FLT_MAX : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), format, power);
|
|
|
PopItemWidth();
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
- value_changed |= DragFloat("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? FLT_MAX : v_max, display_format_max ? display_format_max : display_format, power);
|
|
|
+ value_changed |= DragFloat("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? FLT_MAX : v_max, format_max ? format_max : format, power);
|
|
|
PopItemWidth();
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
|
|
|
@@ -9273,17 +9278,17 @@ 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* display_format)
|
|
|
+bool ImGui::DragInt(const char* label, int* v, float v_speed, int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- if (!display_format)
|
|
|
- display_format = "%.0f";
|
|
|
+ if (!format)
|
|
|
+ format = "%.0f";
|
|
|
float v_f = (float)*v;
|
|
|
- bool value_changed = DragFloat(label, &v_f, v_speed, (float)v_min, (float)v_max, display_format);
|
|
|
+ bool value_changed = DragFloat(label, &v_f, v_speed, (float)v_min, (float)v_max, format);
|
|
|
*v = (int)v_f;
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::DragIntN(const char* label, int* v, int components, float v_speed, int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -9297,7 +9302,7 @@ bool ImGui::DragIntN(const char* label, int* v, int components, float v_speed, i
|
|
|
for (int i = 0; i < components; i++)
|
|
|
{
|
|
|
PushID(i);
|
|
|
- value_changed |= DragInt("##v", &v[i], v_speed, v_min, v_max, display_format);
|
|
|
+ value_changed |= DragInt("##v", &v[i], v_speed, v_min, v_max, format);
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
PopID();
|
|
|
PopItemWidth();
|
|
|
@@ -9310,22 +9315,22 @@ bool ImGui::DragIntN(const char* label, int* v, int components, float v_speed, i
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::DragInt2(const char* label, int v[2], float v_speed, int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- return DragIntN(label, v, 2, v_speed, v_min, v_max, display_format);
|
|
|
+ return DragIntN(label, v, 2, v_speed, v_min, v_max, format);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::DragInt3(const char* label, int v[3], float v_speed, int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- return DragIntN(label, v, 3, v_speed, v_min, v_max, display_format);
|
|
|
+ return DragIntN(label, v, 3, v_speed, v_min, v_max, format);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* display_format)
|
|
|
+bool ImGui::DragInt4(const char* label, int v[4], float v_speed, int v_min, int v_max, const char* format)
|
|
|
{
|
|
|
- return DragIntN(label, v, 4, v_speed, v_min, v_max, display_format);
|
|
|
+ return DragIntN(label, v, 4, v_speed, v_min, v_max, format);
|
|
|
}
|
|
|
|
|
|
-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* display_format, const char* display_format_max)
|
|
|
+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)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -9336,10 +9341,10 @@ bool ImGui::DragIntRange2(const char* label, int* v_current_min, int* v_current_
|
|
|
BeginGroup();
|
|
|
PushMultiItemsWidths(2);
|
|
|
|
|
|
- bool value_changed = DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), display_format);
|
|
|
+ bool value_changed = DragInt("##min", v_current_min, v_speed, (v_min >= v_max) ? INT_MIN : v_min, (v_min >= v_max) ? *v_current_max : ImMin(v_max, *v_current_max), format);
|
|
|
PopItemWidth();
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
- value_changed |= DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? INT_MAX : v_max, display_format_max ? display_format_max : display_format);
|
|
|
+ value_changed |= DragInt("##max", v_current_max, v_speed, (v_min >= v_max) ? *v_current_min : ImMax(v_min, *v_current_min), (v_min >= v_max) ? INT_MAX : v_max, format_max ? format_max : format);
|
|
|
PopItemWidth();
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
|
|
|
@@ -10249,8 +10254,8 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
|
|
{
|
|
|
if (cancel_edit)
|
|
|
{
|
|
|
- // Restore initial value
|
|
|
- if (is_editable)
|
|
|
+ // Restore initial value. Only return true if restoring to the initial value changes the current buffer contents.
|
|
|
+ if (is_editable && strncmp(buf, edit_state.InitialText.Data, buf_size) != 0)
|
|
|
{
|
|
|
ImStrncpy(buf, edit_state.InitialText.Data, buf_size);
|
|
|
value_changed = true;
|
|
|
@@ -10543,7 +10548,7 @@ bool ImGui::InputTextMultiline(const char* label, char* buf, size_t buf_size, co
|
|
|
return InputTextEx(label, buf, (int)buf_size, size, flags | ImGuiInputTextFlags_Multiline, callback, user_data);
|
|
|
}
|
|
|
|
|
|
-// NB: scalar_format here must be a simple "%xx" format string with no prefix/suffix (unlike the Drag/Slider functions "display_format" argument)
|
|
|
+// NB: scalar_format here must be a simple "%xx" format string with no prefix/suffix (unlike the Drag/Slider functions "format" argument)
|
|
|
bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data_ptr, void* step_ptr, void* step_fast_ptr, const char* scalar_format, ImGuiInputTextFlags extra_flags)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
@@ -10561,7 +10566,7 @@ bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data
|
|
|
PushItemWidth(ImMax(1.0f, CalcItemWidth() - (button_sz.x + style.ItemInnerSpacing.x)*2));
|
|
|
|
|
|
char buf[64];
|
|
|
- DataTypeFormatString(data_type, data_ptr, scalar_format, buf, IM_ARRAYSIZE(buf));
|
|
|
+ DataTypeFormatString(buf, IM_ARRAYSIZE(buf), data_type, data_ptr, scalar_format);
|
|
|
|
|
|
bool value_changed = false;
|
|
|
if ((extra_flags & (ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0)
|
|
|
@@ -10600,36 +10605,26 @@ bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
-bool ImGui::InputFloat(const char* label, float* v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags)
|
|
|
+bool ImGui::InputFloat(const char* label, float* v, float step, float step_fast, const char* format, ImGuiInputTextFlags extra_flags)
|
|
|
{
|
|
|
extra_flags |= ImGuiInputTextFlags_CharsScientific;
|
|
|
- if (decimal_precision < 0)
|
|
|
- {
|
|
|
- // Ideally we'd have a minimum decimal precision of 1 to visually denote that this is a float, while hiding non-significant digits? %f doesn't have a minimum of 1
|
|
|
- return InputScalarEx(label, ImGuiDataType_Float, (void*)v, (void*)(step>0.0f ? &step : NULL), (void*)(step_fast>0.0f ? &step_fast : NULL), "%f", extra_flags);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- char display_format[16];
|
|
|
- ImFormatString(display_format, IM_ARRAYSIZE(display_format), "%%.%df", decimal_precision);
|
|
|
- return InputScalarEx(label, ImGuiDataType_Float, (void*)v, (void*)(step>0.0f ? &step : NULL), (void*)(step_fast>0.0f ? &step_fast : NULL), display_format, extra_flags);
|
|
|
- }
|
|
|
+ return InputScalarEx(label, ImGuiDataType_Float, (void*)v, (void*)(step>0.0f ? &step : NULL), (void*)(step_fast>0.0f ? &step_fast : NULL), format, extra_flags);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::InputDouble(const char* label, double* v, double step, double step_fast, const char* display_format, ImGuiInputTextFlags extra_flags)
|
|
|
+bool ImGui::InputDouble(const char* label, double* v, double step, double step_fast, const char* format, ImGuiInputTextFlags extra_flags)
|
|
|
{
|
|
|
extra_flags |= ImGuiInputTextFlags_CharsScientific;
|
|
|
- return InputScalarEx(label, ImGuiDataType_Double, (void*)v, (void*)(step>0.0 ? &step : NULL), (void*)(step_fast>0.0 ? &step_fast : NULL), display_format, extra_flags);
|
|
|
+ return InputScalarEx(label, ImGuiDataType_Double, (void*)v, (void*)(step>0.0 ? &step : NULL), (void*)(step_fast>0.0 ? &step_fast : NULL), format, extra_flags);
|
|
|
}
|
|
|
|
|
|
bool ImGui::InputInt(const char* label, int* v, int step, int step_fast, ImGuiInputTextFlags extra_flags)
|
|
|
{
|
|
|
// Hexadecimal input provided as a convenience but the flag name is awkward. Typically you'd use InputText() to parse your own data, if you want to handle prefixes.
|
|
|
- const char* scalar_format = (extra_flags & ImGuiInputTextFlags_CharsHexadecimal) ? "%08X" : "%d";
|
|
|
- return InputScalarEx(label, ImGuiDataType_Int, (void*)v, (void*)(step>0 ? &step : NULL), (void*)(step_fast>0 ? &step_fast : NULL), scalar_format, extra_flags);
|
|
|
+ const char* format = (extra_flags & ImGuiInputTextFlags_CharsHexadecimal) ? "%08X" : "%d";
|
|
|
+ return InputScalarEx(label, ImGuiDataType_Int, (void*)v, (void*)(step>0 ? &step : NULL), (void*)(step_fast>0 ? &step_fast : NULL), format, extra_flags);
|
|
|
}
|
|
|
|
|
|
-bool ImGui::InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags)
|
|
|
+bool ImGui::InputFloatN(const char* label, float* v, int components, const char* format, ImGuiInputTextFlags extra_flags)
|
|
|
{
|
|
|
ImGuiWindow* window = GetCurrentWindow();
|
|
|
if (window->SkipItems)
|
|
|
@@ -10643,7 +10638,7 @@ bool ImGui::InputFloatN(const char* label, float* v, int components, int decimal
|
|
|
for (int i = 0; i < components; i++)
|
|
|
{
|
|
|
PushID(i);
|
|
|
- value_changed |= InputFloat("##v", &v[i], 0, 0, decimal_precision, extra_flags);
|
|
|
+ value_changed |= InputFloat("##v", &v[i], 0, 0, format, extra_flags);
|
|
|
SameLine(0, g.Style.ItemInnerSpacing.x);
|
|
|
PopID();
|
|
|
PopItemWidth();
|
|
|
@@ -10656,20 +10651,55 @@ bool ImGui::InputFloatN(const char* label, float* v, int components, int decimal
|
|
|
return value_changed;
|
|
|
}
|
|
|
|
|
|
+bool ImGui::InputFloat2(const char* label, float v[2], const char* format, ImGuiInputTextFlags extra_flags)
|
|
|
+{
|
|
|
+ return InputFloatN(label, v, 2, format, extra_flags);
|
|
|
+}
|
|
|
+
|
|
|
+bool ImGui::InputFloat3(const char* label, float v[3], const char* format, ImGuiInputTextFlags extra_flags)
|
|
|
+{
|
|
|
+ return InputFloatN(label, v, 3, format, extra_flags);
|
|
|
+}
|
|
|
+
|
|
|
+bool ImGui::InputFloat4(const char* label, float v[4], const char* format, ImGuiInputTextFlags extra_flags)
|
|
|
+{
|
|
|
+ return InputFloatN(label, v, 4, format, extra_flags);
|
|
|
+}
|
|
|
+
|
|
|
+// Prefer using "const char* format" directly, which is more flexible and consistent with other API.
|
|
|
+#ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
|
|
+bool ImGui::InputFloat(const char* label, float* v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags)
|
|
|
+{
|
|
|
+ char format[16] = "%f";
|
|
|
+ if (decimal_precision >= 0)
|
|
|
+ ImFormatString(format, IM_ARRAYSIZE(format), "%%.%df", decimal_precision);
|
|
|
+ return InputFloat(label, v, step, step_fast, format, extra_flags);
|
|
|
+}
|
|
|
+
|
|
|
bool ImGui::InputFloat2(const char* label, float v[2], int decimal_precision, ImGuiInputTextFlags extra_flags)
|
|
|
{
|
|
|
- return InputFloatN(label, v, 2, decimal_precision, extra_flags);
|
|
|
+ char format[16] = "%f";
|
|
|
+ if (decimal_precision >= 0)
|
|
|
+ ImFormatString(format, IM_ARRAYSIZE(format), "%%.%df", decimal_precision);
|
|
|
+ return InputFloatN(label, v, 2, format, extra_flags);
|
|
|
}
|
|
|
|
|
|
bool ImGui::InputFloat3(const char* label, float v[3], int decimal_precision, ImGuiInputTextFlags extra_flags)
|
|
|
{
|
|
|
- return InputFloatN(label, v, 3, decimal_precision, extra_flags);
|
|
|
+ char format[16] = "%f";
|
|
|
+ if (decimal_precision >= 0)
|
|
|
+ ImFormatString(format, IM_ARRAYSIZE(format), "%%.%df", decimal_precision);
|
|
|
+ return InputFloatN(label, v, 3, format, extra_flags);
|
|
|
}
|
|
|
|
|
|
bool ImGui::InputFloat4(const char* label, float v[4], int decimal_precision, ImGuiInputTextFlags extra_flags)
|
|
|
{
|
|
|
- return InputFloatN(label, v, 4, decimal_precision, extra_flags);
|
|
|
+ char format[16] = "%f";
|
|
|
+ if (decimal_precision >= 0)
|
|
|
+ ImFormatString(format, IM_ARRAYSIZE(format), "%%.%df", decimal_precision);
|
|
|
+ return InputFloatN(label, v, 4, format, extra_flags);
|
|
|
}
|
|
|
+#endif // IMGUI_DISABLE_OBSOLETE_FUNCTIONS
|
|
|
|
|
|
bool ImGui::InputIntN(const char* label, int* v, int components, ImGuiInputTextFlags extra_flags)
|
|
|
{
|