mirror of https://github.com/ocornut/imgui
Data types: DragScalar, InputScalar: default parameters. Added IM_STATIC_ASSERT(). Comments.
This commit is contained in:
parent
0dc18a6ca6
commit
fc7fc83f9e
12
imgui.cpp
12
imgui.cpp
|
@ -964,6 +964,7 @@ void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
|
|||
// HELPERS
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#define IM_STATIC_ASSERT(_COND) typedef char static_assertion_##__line__[(_COND)?1:-1]
|
||||
#define IM_F32_TO_INT8_UNBOUND(_VAL) ((int)((_VAL) * 255.0f + ((_VAL)>=0 ? 0.5f : -0.5f))) // Unsaturated, for display purpose
|
||||
#define IM_F32_TO_INT8_SAT(_VAL) ((int)(ImSaturate(_VAL) * 255.0f + 0.5f)) // Saturated, always output 0..255
|
||||
|
||||
|
@ -8509,6 +8510,7 @@ static inline int DataTypeFormatString(char* buf, int buf_size, ImGuiDataType da
|
|||
return 0;
|
||||
}
|
||||
|
||||
// FIXME: Adding support for clamping on boundaries of the data type would be nice.
|
||||
static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void* arg1, const void* arg2)
|
||||
{
|
||||
IM_ASSERT(op == '+' || op == '-');
|
||||
|
@ -8540,6 +8542,7 @@ static void DataTypeApplyOp(ImGuiDataType data_type, int op, void* output, void*
|
|||
return;
|
||||
case ImGuiDataType_COUNT: break;
|
||||
}
|
||||
IM_ASSERT(0);
|
||||
}
|
||||
|
||||
struct ImGuiDataTypeInfo
|
||||
|
@ -8549,7 +8552,7 @@ struct ImGuiDataTypeInfo
|
|||
const char* ScanFmt;
|
||||
};
|
||||
|
||||
static const ImGuiDataTypeInfo GDataTypeInfo[ImGuiDataType_COUNT] =
|
||||
static const ImGuiDataTypeInfo GDataTypeInfo[] =
|
||||
{
|
||||
{ sizeof(int), "%d", "%d" },
|
||||
{ sizeof(unsigned int), "%u", "%u" },
|
||||
|
@ -8563,6 +8566,7 @@ static const ImGuiDataTypeInfo GDataTypeInfo[ImGuiDataType_COUNT] =
|
|||
{ sizeof(float), "%f", "%f" }, // float are promoted to double in va_arg
|
||||
{ sizeof(double), "%f", "%lf" },
|
||||
};
|
||||
IM_STATIC_ASSERT(IM_ARRAYSIZE(GDataTypeInfo) == ImGuiDataType_COUNT);
|
||||
|
||||
// User can input math operators (e.g. +100) to edit a numerical values.
|
||||
// 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
|
|||
return value_changed;
|
||||
}
|
||||
|
||||
// For 32-bits and larger types, slider bounds are limited to half the natural type range.
|
||||
// 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.
|
||||
// It would be possible to life that limitation with some work but it doesn't seem to be work it for sliders.
|
||||
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)
|
||||
{
|
||||
switch (data_type)
|
||||
|
@ -8997,8 +9004,7 @@ bool ImGui::SliderBehavior(const ImRect& bb, ImGuiID id, ImGuiDataType data_type
|
|||
case ImGuiDataType_Double:
|
||||
IM_ASSERT(*(const double*)v_min >= -DBL_MAX/2.0f && *(const double*)v_max <= DBL_MAX/2.0f);
|
||||
return SliderBehaviorT<double,double,double>(bb, id, data_type, (double*)v, *(const double*)v_min, *(const double*)v_max, format, power, flags);
|
||||
case ImGuiDataType_COUNT:
|
||||
break;
|
||||
case ImGuiDataType_COUNT: break;
|
||||
}
|
||||
IM_ASSERT(0);
|
||||
return false;
|
||||
|
|
8
imgui.h
8
imgui.h
|
@ -354,8 +354,8 @@ namespace ImGui
|
|||
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");
|
||||
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");
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
// Widgets: Input with Keyboard
|
||||
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
|
|||
IMGUI_API bool InputInt3(const char* label, int v[3], ImGuiInputTextFlags extra_flags = 0);
|
||||
IMGUI_API bool InputInt4(const char* label, int v[4], ImGuiInputTextFlags extra_flags = 0);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
|
||||
// Widgets: Sliders (tip: ctrl+click on a slider to input with keyboard. manually input values aren't clamped, can go off-bounds)
|
||||
// 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.
|
||||
|
|
|
@ -791,7 +791,7 @@ void ImGui::ShowDemoWindow(bool* p_open)
|
|||
ImGui::TreePop();
|
||||
}
|
||||
|
||||
if (ImGui::TreeNode("Plots widgets"))
|
||||
if (ImGui::TreeNode("Plots Widgets"))
|
||||
{
|
||||
static bool animate = true;
|
||||
ImGui::Checkbox("Animate", &animate);
|
||||
|
|
|
@ -82,7 +82,7 @@ extern IMGUI_API ImGuiContext* GImGui; // Current implicit ImGui context pointe
|
|||
|
||||
#define IM_PI 3.14159265358979323846f
|
||||
#ifdef _WIN32
|
||||
#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)
|
||||
#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!)
|
||||
#else
|
||||
#define IM_NEWLINE "\n"
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue