mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 03:58:47 +02:00
InputFloat: Scientific input. InputText: Added ImGuiInputTextFlags_CharsScientific to add 'e' 'E' to list of characters that can be input. (later useful for #1011)
This commit is contained in:
11
imgui.cpp
11
imgui.cpp
@ -9779,12 +9779,16 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
||||
if (c >= 0xE000 && c <= 0xF8FF) // Filter private Unicode range. I don't imagine anybody would want to input them. GLFW on OSX seems to send private characters for special keys like arrow keys.
|
||||
return false;
|
||||
|
||||
if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank))
|
||||
if (flags & (ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsUppercase | ImGuiInputTextFlags_CharsNoBlank | ImGuiInputTextFlags_CharsScientific))
|
||||
{
|
||||
if (flags & ImGuiInputTextFlags_CharsDecimal)
|
||||
if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/'))
|
||||
return false;
|
||||
|
||||
if (flags & ImGuiInputTextFlags_CharsScientific)
|
||||
if (!(c >= '0' && c <= '9') && (c != '.') && (c != '-') && (c != '+') && (c != '*') && (c != '/') && (c != 'e') && (c != 'E'))
|
||||
return false;
|
||||
|
||||
if (flags & ImGuiInputTextFlags_CharsHexadecimal)
|
||||
if (!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f') && !(c >= 'A' && c <= 'F'))
|
||||
return false;
|
||||
@ -10446,7 +10450,7 @@ bool ImGui::InputScalarEx(const char* label, ImGuiDataType data_type, void* data
|
||||
DataTypeFormatString(data_type, data_ptr, scalar_format, buf, IM_ARRAYSIZE(buf));
|
||||
|
||||
bool value_changed = false;
|
||||
if (!(extra_flags & ImGuiInputTextFlags_CharsHexadecimal))
|
||||
if ((extra_flags & (ImGuiInputTextFlags_CharsHexadecimal | ImGuiInputTextFlags_CharsScientific)) == 0)
|
||||
extra_flags |= ImGuiInputTextFlags_CharsDecimal;
|
||||
extra_flags |= ImGuiInputTextFlags_AutoSelectAll;
|
||||
if (InputText("", buf, IM_ARRAYSIZE(buf), extra_flags)) // PushId(label) + "" gives us the expected ID from outside point of view
|
||||
@ -10489,6 +10493,7 @@ bool ImGui::InputFloat(const char* label, float* v, float step, float step_fast,
|
||||
strcpy(display_format, "%f"); // 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
|
||||
else
|
||||
ImFormatString(display_format, IM_ARRAYSIZE(display_format), "%%.%df", decimal_precision);
|
||||
extra_flags |= ImGuiInputTextFlags_CharsScientific;
|
||||
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);
|
||||
}
|
||||
|
||||
@ -10496,7 +10501,7 @@ bool ImGui::InputInt(const char* label, int* v, int step, int step_fast, ImGuiIn
|
||||
{
|
||||
// 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.0f ? &step : NULL), (void*)(step_fast>0.0f ? &step_fast : NULL), scalar_format, extra_flags);
|
||||
return InputScalarEx(label, ImGuiDataType_Int, (void*)v, (void*)(step>0 ? &step : NULL), (void*)(step_fast>0 ? &step_fast : NULL), scalar_format, extra_flags);
|
||||
}
|
||||
|
||||
bool ImGui::InputFloatN(const char* label, float* v, int components, int decimal_precision, ImGuiInputTextFlags extra_flags)
|
||||
|
Reference in New Issue
Block a user