Skip to content

Commit fc7fc83

Browse files
committed
Data types: DragScalar, InputScalar: default parameters. Added IM_STATIC_ASSERT(). Comments.
1 parent 0dc18a6 commit fc7fc83

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

imgui.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
964964
// HELPERS
965965
//-----------------------------------------------------------------------------
966966

967+
#define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1]
967968
#define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose
968969
#define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255
969970

@@ -8509,6 +8510,7 @@ static inline int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType da
85098510
return 0;
85108511
}
85118512

8513+
// FIXME: Adding support for clamping on boundaries of the data type would be nice.
85128514
static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void* arg1, const void* arg2)
85138515
{
85148516
IM_ASSERT(op == '+' || op == '-');
@@ -8540,6 +8542,7 @@ static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void*
85408542
return;
85418543
case ImGuiDataType_COUNT: break;
85428544
}
8545+
IM_ASSERT(0);
85438546
}
85448547

85458548
struct ImGuiDataTypeInfo
@@ -8549,7 +8552,7 @@ struct ImGuiDataTypeInfo
85498552
const char* ScanFmt;
85508553
};
85518554

8552-
static const ImGuiDataTypeInfo GDataTypeInfo[ImGuiDataType_COUNT] =
8555+
static const ImGuiDataTypeInfo GDataTypeInfo[] =
85538556
{
85548557
{ sizeof(int), "%d", "%d" },
85558558
{ sizeof(unsigned int), "%u", "%u" },
@@ -8563,6 +8566,7 @@ static const ImGuiDataTypeInfo GDataTypeInfo[ImGuiDataType_COUNT] =
85638566
{ sizeof(float), "%f", "%f" }, // float are promoted to double in va_arg
85648567
{ sizeof(double), "%f", "%lf" },
85658568
};
8569+
IM_STATIC_ASSERT(IM_ARRAYSIZE(GDataTypeInfo) == ImGuiDataType_COUNT);
85668570

85678571
// User can input math operators (e.g. +100) to edit a numerical values.
85688572
// NB: This is _not_ a full expression evaluator. We should probably add one and replace this dumb mess..
@@ -8975,6 +8979,9 @@ static bool ImGui::SliderBehaviorT(const ImRect& bb, ImGuiID id, ImGuiDataType d
89758979
return value_changed;
89768980
}
89778981

8982+
// For 32-bits and larger types, slider bounds are limited to half the natural type range.
8983+
// So e.g. an integer Slider between INT_MAX-10 and INT_MAX will fail, but an integer Slider between INT_MAX/2-10 and INT_MAX/2.
8984+
// It would be possible to life that limitation with some work but it doesn't seem to be work it for sliders.
89788985
bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type, void* v, const void* v_min, const void* v_max, const char* format, float power, ImGuiSliderFlags flags)
89798986
{
89808987
switch (data_type)
@@ -8997,8 +9004,7 @@ bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type
89979004
case ImGuiDataType_Double:
89989005
IM_ASSERT(*(const double*)v_min >= -DBL_MAX/2.0f && *(const double*)v_max <= DBL_MAX/2.0f);
89999006
return SliderBehaviorT<double,double,double>(bb, id, data_type, (double*)v, *(const double*)v_min, *(const double*)v_max, format, power, flags);
9000-
case ImGuiDataType_COUNT:
9001-
break;
9007+
case ImGuiDataType_COUNT: break;
90029008
}
90039009
IM_ASSERT(0);
90049010
return false;

imgui.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ namespace ImGui
354354
IMGUI_API bool DragInt3(const char* label, int v[3], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%d");
355355
IMGUI_API bool DragInt4(const char* label, int v[4], float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%d");
356356
IMGUI_API bool DragIntRange2(const char* label, int* v_current_min, int* v_current_max, float v_speed = 1.0f, int v_min = 0, int v_max = 0, const char* format = "%d", const char* format_max = NULL);
357-
IMGUI_API bool DragScalar(const char* label, ImGuiDataType data_type, void* v, float v_speed, const void* v_min, const void* v_max, const char* format = NULL, float power = 1.0f);
358-
IMGUI_API bool DragScalarN(const char* label, ImGuiDataType data_type, void* v, int components, float v_speed, const void* v_min, const void* v_max, const char* format = NULL, float power = 1.0f);
357+
IMGUI_API bool DragScalar(const char* label, ImGuiDataType data_type, void* v, float v_speed, const void* v_min = NULL, const void* v_max = NULL, const char* format = NULL, float power = 1.0f);
358+
IMGUI_API bool DragScalarN(const char* label, ImGuiDataType data_type, void* v, int components, float v_speed, const void* v_min = NULL, const void* v_max = NULL, const char* format = NULL, float power = 1.0f);
359359

360360
// Widgets: Input with Keyboard
361361
IMGUI_API bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0, ImGuiTextEditCallback callback = NULL, void* user_data = NULL);
@@ -369,8 +369,8 @@ namespace ImGui
369369
IMGUI_API bool InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags = 0);
370370
IMGUI_API bool InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags = 0);
371371
IMGUI_API bool InputDouble(const char* label, double* v, double step = 0.0f, double step_fast = 0.0f, const char* format = "%.6f", ImGuiInputTextFlags extra_flags = 0);
372-
IMGUI_API bool InputScalar(const char* label, ImGuiDataType data_type, void* v, const void* step, const void* step_fast, const char* format = NULL, ImGuiInputTextFlags extra_flags = 0);
373-
IMGUI_API bool InputScalarN(const char* label, ImGuiDataType data_type, void* v, int components, const void* step, const void* step_fast, const char* format = NULL, ImGuiInputTextFlags extra_flags = 0);
372+
IMGUI_API bool InputScalar(const char* label, ImGuiDataType data_type, void* v, const void* step = NULL, const void* step_fast = NULL, const char* format = NULL, ImGuiInputTextFlags extra_flags = 0);
373+
IMGUI_API bool InputScalarN(const char* label, ImGuiDataType data_type, void* v, int components, const void* step = NULL, const void* step_fast = NULL, const char* format = NULL, ImGuiInputTextFlags extra_flags = 0);
374374

375375
// Widgets: Sliders (tip: ctrl+click on a slider to input with keyboard. manually input values aren't clamped, can go off-bounds)
376376
// Adjust format string to decorate the value with a prefix, a suffix, or adapt the editing and display precision e.g. "%.3f" -> 1.234; "%5.2f secs" -> 01.23 secs; "Biscuit: %.0f" -> Biscuit: 1; etc.

imgui_demo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
791791
ImGui::TreePop();
792792
}
793793

794-
if (ImGui::TreeNode("Plots widgets"))
794+
if (ImGui::TreeNode("Plots Widgets"))
795795
{
796796
static bool animate = true;
797797
ImGui::Checkbox("Animate", &animate);

imgui_internal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointe
8282

8383
#define IM_PI 3.14159265358979323846f
8484
#ifdef _WIN32
85-
#define IM_NEWLINE "\r\n" // Play it nice with Windows users (2018: Notepad _still_ doesn't display files properly when they use Unix-style carriage returns)
85+
#define IM_NEWLINE "\r\n" // Play it nice with Windows users (2018/05 news: Microsoft announced that Notepad will finally display Unix-style carriage returns!)
8686
#else
8787
#define IM_NEWLINE "\n"
8888
#endif

0 commit comments

Comments
 (0)