From 62d233aaabaee87cb2b7d246585edd767a580a72 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 8 Sep 2014 16:50:09 +0100 Subject: [PATCH] Added extra_flags parameters to InputInt(), InputFloat(). Used in example code. Commented out broken ImGuiInputTextFlags_AlignCenter. --- imgui.cpp | 13 +++++++------ imgui.h | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index cc9dc920..6905ac35 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -3279,7 +3279,7 @@ bool SliderFloat(const char* label, float* v, float v_min, float v_max, const ch g.ActiveId = g.SliderAsInputTextId; g.HoveredId = 0; window->FocusItemUnregister(); // Our replacement slider will override the focus ID (that we needed to declare previously to allow for a TAB focus to happen before we got selected) - value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_AlignCenter); + value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll); if (g.SliderAsInputTextId == 0) { // First frame @@ -3834,7 +3834,7 @@ void ImGuiTextEditState::RenderTextScrolledClipped(ImFont font, float font_size, namespace ImGui { -bool InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision) +bool InputFloat(const char* label, float *v, float step, float step_fast, int decimal_precision, ImGuiInputTextFlags extra_flags) { ImGuiState& g = GImGui; ImGuiWindow* window = GetCurrentWindow(); @@ -3857,7 +3857,8 @@ bool InputFloat(const char* label, float *v, float step, float step_fast, int de else ImFormatString(buf, IM_ARRAYSIZE(buf), "%.*f", decimal_precision, *v); bool value_changed = false; - if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AlignCenter|ImGuiInputTextFlags_AutoSelectAll)) + const ImGuiInputTextFlags flags = extra_flags | (ImGuiInputTextFlags_CharsDecimal|ImGuiInputTextFlags_AutoSelectAll); + if (ImGui::InputText("", buf, IM_ARRAYSIZE(buf), flags)) { ApplyNumericalTextInput(buf, v); value_changed = true; @@ -3891,10 +3892,10 @@ bool InputFloat(const char* label, float *v, float step, float step_fast, int de return value_changed; } -bool InputInt(const char* label, int *v, int step, int step_fast) +bool InputInt(const char* label, int *v, int step, int step_fast, ImGuiInputTextFlags extra_flags) { float f = (float)*v; - const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0); + const bool value_changed = ImGui::InputFloat(label, &f, (float)step, (float)step_fast, 0, extra_flags); *v = (int)f; return value_changed; } @@ -5871,7 +5872,7 @@ void ShowTestWindow(bool* open) bool goto_line = ImGui::Button("Goto"); ImGui::SameLine(); ImGui::PushItemWidth(100); - ImGui::InputInt("##Line", &line, 0); + goto_line |= ImGui::InputInt("##Line", &line, 0, 0, ImGuiInputTextFlags_EnterReturnsTrue); ImGui::PopItemWidth(); ImGui::BeginChild("Sub1", ImVec2(ImGui::GetWindowWidth()*0.5f,300)); for (int i = 0; i < 100; i++) diff --git a/imgui.h b/imgui.h index 444e583c..c5d19946 100644 --- a/imgui.h +++ b/imgui.h @@ -215,12 +215,12 @@ namespace ImGui bool CheckboxFlags(const char* label, unsigned int* flags, unsigned int flags_value); bool RadioButton(const char* label, bool active); bool RadioButton(const char* label, int* v, int v_button); - bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1); + bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0); + bool InputFloat(const char* label, float* v, float step = 0.0f, float step_fast = 0.0f, int decimal_precision = -1, ImGuiInputTextFlags extra_flags = 0); bool InputFloat2(const char* label, float v[2], int decimal_precision = -1); bool InputFloat3(const char* label, float v[3], int decimal_precision = -1); bool InputFloat4(const char* label, float v[4], int decimal_precision = -1); - bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100); - bool InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags = 0); + bool InputInt(const char* label, int* v, int step = 1, int step_fast = 100, ImGuiInputTextFlags extra_flags = 0); bool Combo(const char* label, int* current_item, const char** items, int items_count, int popup_height_items = 7); bool Combo(const char* label, int* current_item, const char* items_separated_by_zeros, int popup_height_items = 7); // Separate items with \0, end item-list with \0\0 bool Combo(const char* label, int* current_item, bool (*items_getter)(void* data, int idx, const char** out_text), void* data, int items_count, int popup_height_items = 7); @@ -292,9 +292,9 @@ enum ImGuiInputTextFlags_ // Default: 0 ImGuiInputTextFlags_CharsDecimal = 1 << 0, // Allow 0123456789.+-*/ ImGuiInputTextFlags_CharsHexadecimal = 1 << 1, // Allow 0123456789ABCDEFabcdef - ImGuiInputTextFlags_AutoSelectAll = 1 << 2, - ImGuiInputTextFlags_AlignCenter = 1 << 3, - ImGuiInputTextFlags_EnterReturnsTrue = 1 << 4, + ImGuiInputTextFlags_AutoSelectAll = 1 << 2, // Select entire text when first taking focus + ImGuiInputTextFlags_EnterReturnsTrue = 1 << 3, // Return 'true' when Enter is pressed (as opposed to when the value was modified) + //ImGuiInputTextFlags_AlignCenter = 1 << 3, }; // User fill ImGuiIO.KeyMap[] array with indices into the ImGuiIO.KeysDown[512] array