From e6b29b70b4a49ff1731de8be73a49af4fd181e3c Mon Sep 17 00:00:00 2001 From: ocornut Date: Thu, 30 Jul 2015 21:51:55 -0600 Subject: [PATCH] Make internal SliderFloatAsInputText() take a size to match the calling widget --- imgui.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/imgui.cpp b/imgui.cpp index 1ba25c36f..d84544e2e 100644 --- a/imgui.cpp +++ b/imgui.cpp @@ -574,6 +574,7 @@ typedef int ImGuiButtonFlags; // enum ImGuiButtonFlags_ static bool ButtonBehavior(const ImRect& bb, ImGuiID id, bool* out_hovered, bool* out_held, bool allow_key_modifiers, ImGuiButtonFlags flags = 0); static void LogText(const ImVec2& ref_pos, const char* text, const char* text_end = NULL); +static bool InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiTextEditCallback callback = NULL, void* user_data = NULL); static void RenderText(ImVec2 pos, const char* text, const char* text_end = NULL, bool hide_text_after_hash = true); static void RenderTextWrapped(ImVec2 pos, const char* text, const char* text_end, float wrap_width); @@ -5871,7 +5872,7 @@ static void InputTextApplyArithmeticOp(const char* buf, float *v) } // Create text input in place of a slider (when CTRL+Clicking on slider) -static bool SliderFloatAsInputText(const char* label, float* v, ImGuiID id, int decimal_precision) +static bool SliderFloatAsInputText(const ImRect& aabb, const char* label, float* v, ImGuiID id, int decimal_precision) { ImGuiState& g = *GImGui; ImGuiWindow* window = GetCurrentWindow(); @@ -5885,7 +5886,7 @@ static bool SliderFloatAsInputText(const char* label, float* v, ImGuiID id, int // Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen) window->FocusItemUnregister(); - bool value_changed = ImGui::InputText(label, text_buf, IM_ARRAYSIZE(text_buf), ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll); + bool value_changed = InputTextEx(label, text_buf, (int)IM_ARRAYSIZE(text_buf), aabb.GetSize() - g.Style.FramePadding*2.0f, ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_AutoSelectAll); if (g.ScalarAsInputTextId == 0) { // First frame @@ -6121,7 +6122,7 @@ bool ImGui::SliderFloat(const char* label, float* v, float v_min, float v_max, c } } if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id)) - return SliderFloatAsInputText(label, v, id, decimal_precision); + return SliderFloatAsInputText(frame_bb, label, v, id, decimal_precision); ItemSize(total_bb, style.FramePadding.y); @@ -6424,7 +6425,7 @@ bool ImGui::DragFloat(const char* label, float *v, float v_speed, float v_min, f } } if (start_text_input || (g.ActiveId == id && g.ScalarAsInputTextId == id)) - return SliderFloatAsInputText(label, v, id, decimal_precision); + return SliderFloatAsInputText(frame_bb, label, v, id, decimal_precision); ItemSize(total_bb, style.FramePadding.y);