mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Added InputTextWithHint() (#2400)
Squashed commit of the following: commit 1970d84051d3878f8c1354d9c33c795d9c66143f Author: Lucas Lazare <lazarelucas@yahoo.fr> Date: Tue Mar 5 12:20:39 2019 -0500 Removing sneaky tabulations #2 (why, editor T-T) I should update my settings, I guess commit 219bdfcb7fbd17edf3048cb0edfde2532e4d6ac3 Author: Lucas Lazare <lazarelucas@yahoo.fr> Date: Tue Mar 5 12:17:27 2019 -0500 Removing useless check introduced in b0d172 commit 8afd7a2b459df0eb14eca88d832d2bebd1e684e6 Author: Lucas Lazare <lazarelucas@yahoo.fr> Date: Tue Mar 5 11:49:24 2019 -0500 Removing sneaky tabulations commit 8e0490863126d63cafc782a6aac8707e44f95653 Author: Lucas Lazare <lazarelucas@yahoo.fr> Date: Tue Mar 5 11:45:13 2019 -0500 Moving InputTextHinted code to InputTextEx commit b0d1723a2fb02d17ba15b9c1e679dedbbe3c17fd Author: Lucas Lazare <lazarelucas@yahoo.fr> Date: Tue Mar 5 00:23:02 2019 -0500 C++11 to C++98 commit 9afeae399826015357962607b4aeb0109fde698e Author: Lucas Lazare <lazarelucas@yahoo.fr> Date: Mon Mar 4 23:43:28 2019 -0500 Added InputTextHinted
This commit is contained in:
@ -2692,7 +2692,7 @@ bool ImGui::InputScalarAsWidgetReplacement(const ImRect& bb, ImGuiID id, const c
|
||||
DataTypeFormatString(data_buf, IM_ARRAYSIZE(data_buf), data_type, data_ptr, format);
|
||||
ImStrTrimBlanks(data_buf);
|
||||
ImGuiInputTextFlags flags = ImGuiInputTextFlags_AutoSelectAll | ((data_type == ImGuiDataType_Float || data_type == ImGuiDataType_Double) ? ImGuiInputTextFlags_CharsScientific : ImGuiInputTextFlags_CharsDecimal);
|
||||
bool value_changed = InputTextEx(label, data_buf, IM_ARRAYSIZE(data_buf), bb.GetSize(), flags);
|
||||
bool value_changed = InputTextEx(label, NULL, data_buf, IM_ARRAYSIZE(data_buf), bb.GetSize(), flags);
|
||||
if (g.ScalarAsInputTextId == 0)
|
||||
{
|
||||
// First frame we started displaying the InputText widget, we expect it to take the active id.
|
||||
@ -2883,9 +2883,10 @@ bool ImGui::InputDouble(const char* label, double* v, double step, double step_f
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
// [SECTION] Widgets: InputText, InputTextMultiline
|
||||
// [SECTION] Widgets: InputText, InputTextMultiline, InputTextWithHint
|
||||
//-------------------------------------------------------------------------
|
||||
// - InputText()
|
||||
// - InputTextWithHint()
|
||||
// - InputTextMultiline()
|
||||
// - InputTextEx() [Internal]
|
||||
//-------------------------------------------------------------------------
|
||||
@ -2893,12 +2894,17 @@ bool ImGui::InputDouble(const char* label, double* v, double step, double step_f
|
||||
bool ImGui::InputText(const char* label, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
|
||||
{
|
||||
IM_ASSERT(!(flags & ImGuiInputTextFlags_Multiline)); // call InputTextMultiline()
|
||||
return InputTextEx(label, buf, (int)buf_size, ImVec2(0,0), flags, callback, user_data);
|
||||
return InputTextEx(label, NULL, buf, (int)buf_size, ImVec2(0,0), flags, callback, user_data);
|
||||
}
|
||||
|
||||
bool ImGui::InputTextMultiline(const char* label, char* buf, size_t buf_size, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
|
||||
{
|
||||
return InputTextEx(label, buf, (int)buf_size, size, flags | ImGuiInputTextFlags_Multiline, callback, user_data);
|
||||
return InputTextEx(label, NULL, buf, (int)buf_size, size, flags | ImGuiInputTextFlags_Multiline, callback, user_data);
|
||||
}
|
||||
|
||||
bool ImGui::InputTextWithHint(const char* label, const char* hint, char* buf, size_t buf_size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data)
|
||||
{
|
||||
return InputTextEx(label, hint, buf, (int)buf_size, ImVec2(0,0), flags, callback, user_data);
|
||||
}
|
||||
|
||||
static int InputTextCalcTextLenAndLineCount(const char* text_begin, const char** out_text_end)
|
||||
@ -3193,7 +3199,7 @@ static bool InputTextFilterCharacter(unsigned int* p_char, ImGuiInputTextFlags f
|
||||
// - If you want to use ImGui::InputText() with std::string, see misc/cpp/imgui_stdlib.h
|
||||
// (FIXME: Rather confusing and messy function, among the worse part of our codebase, expecting to rewrite a V2 at some point.. Partly because we are
|
||||
// doing UTF8 > U16 > UTF8 conversions on the go to easily interface with stb_textedit. Ideally should stay in UTF-8 all the time. See https://github.com/nothings/stb/issues/188)
|
||||
bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* callback_user_data)
|
||||
bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_size, const ImVec2& size_arg, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* callback_user_data)
|
||||
{
|
||||
ImGuiWindow* window = GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
@ -3725,6 +3731,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
const int buf_display_max_length = 2 * 1024 * 1024;
|
||||
const char* buf_display = NULL;
|
||||
const char* buf_display_end = NULL;
|
||||
ImGuiCol text_color = ImGuiCol_COUNT;
|
||||
|
||||
// Render text. We currently only render selection when the widget is active or while scrolling.
|
||||
// FIXME: We could remove the '&& render_cursor' to keep rendering selection when inactive.
|
||||
@ -3861,11 +3868,26 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
}
|
||||
}
|
||||
|
||||
if (state->CurLenA != 0 || hint == NULL)
|
||||
{
|
||||
buf_display = (!is_readonly && state->TextAIsValid) ? state->TextA.Data : buf;
|
||||
buf_display_end = buf_display + state->CurLenA;
|
||||
text_color = ImGuiCol_Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
buf_display = hint;
|
||||
buf_display_end = hint + strlen(hint);
|
||||
text_color = ImGuiCol_TextDisabled;
|
||||
}
|
||||
|
||||
|
||||
// We test for 'buf_display_max_length' as a way to avoid some pathological cases (e.g. single-line 1 MB string) which would make ImDrawList crash.
|
||||
buf_display = (!is_readonly && state->TextAIsValid) ? state->TextA.Data : buf;
|
||||
buf_display_end = buf_display + state->CurLenA;
|
||||
if (is_multiline || (buf_display_end - buf_display) < buf_display_max_length)
|
||||
draw_window->DrawList->AddText(g.Font, g.FontSize, draw_pos - draw_scroll, GetColorU32(ImGuiCol_Text), buf_display, buf_display_end, 0.0f, is_multiline ? NULL : &clip_rect);
|
||||
{
|
||||
IM_ASSERT(text_color != ImGuiCol_COUNT);
|
||||
draw_window->DrawList->AddText(g.Font, g.FontSize, draw_pos - draw_scroll, GetColorU32(text_color), buf_display, buf_display_end, 0.0f, is_multiline ? NULL : &clip_rect);
|
||||
}
|
||||
|
||||
// Draw blinking cursor
|
||||
if (render_cursor)
|
||||
@ -3885,6 +3907,7 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
else
|
||||
{
|
||||
// Render text only (no selection, no cursor)
|
||||
text_color = ImGuiCol_Text;
|
||||
buf_display = (g.ActiveId == id && !is_readonly && state->TextAIsValid) ? state->TextA.Data : buf;
|
||||
if (is_multiline)
|
||||
text_size = ImVec2(size.x, InputTextCalcTextLenAndLineCount(buf_display, &buf_display_end) * g.FontSize); // We don't need width
|
||||
@ -3892,8 +3915,19 @@ bool ImGui::InputTextEx(const char* label, char* buf, int buf_size, const ImVec2
|
||||
buf_display_end = buf_display + state->CurLenA;
|
||||
else
|
||||
buf_display_end = buf_display + strlen(buf_display);
|
||||
|
||||
if (buf_display_end == buf_display && hint != NULL)
|
||||
{
|
||||
buf_display = hint;
|
||||
buf_display_end = buf_display + strlen(buf_display);
|
||||
text_color = ImGuiCol_TextDisabled;
|
||||
}
|
||||
|
||||
if (is_multiline || (buf_display_end - buf_display) < buf_display_max_length)
|
||||
draw_window->DrawList->AddText(g.Font, g.FontSize, draw_pos, GetColorU32(ImGuiCol_Text), buf_display, buf_display_end, 0.0f, is_multiline ? NULL : &clip_rect);
|
||||
{
|
||||
IM_ASSERT(text_color != ImGuiCol_COUNT);
|
||||
draw_window->DrawList->AddText(g.Font, g.FontSize, draw_pos, GetColorU32(text_color), buf_display, buf_display_end, 0.0f, is_multiline ? NULL : &clip_rect);
|
||||
}
|
||||
}
|
||||
|
||||
if (is_multiline)
|
||||
|
Reference in New Issue
Block a user