mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 03:58:47 +02:00
InputText: Add ImGuiInputTextFlags_CallbackEdit, selection helpers in ImGuiInputTextCallbackData(). Add simple InputText() callbacks demo.
This commit is contained in:
@ -3514,6 +3514,7 @@ static void STB_TEXTEDIT_DELETECHARS(STB_TEXTEDIT_STRING* obj, int pos, int n)
|
||||
ImWchar* dst = obj->TextW.Data + pos;
|
||||
|
||||
// We maintain our buffer length in both UTF-8 and wchar formats
|
||||
obj->Edited = true;
|
||||
obj->CurLenA -= ImTextCountUtf8BytesFromStr(dst, dst + n);
|
||||
obj->CurLenW -= n;
|
||||
|
||||
@ -3548,6 +3549,7 @@ static bool STB_TEXTEDIT_INSERTCHARS(STB_TEXTEDIT_STRING* obj, int pos, const Im
|
||||
memmove(text + pos + new_text_len, text + pos, (size_t)(text_len - pos) * sizeof(ImWchar));
|
||||
memcpy(text + pos, new_text, (size_t)new_text_len * sizeof(ImWchar));
|
||||
|
||||
obj->Edited = true;
|
||||
obj->CurLenW += new_text_len;
|
||||
obj->CurLenA += new_text_len_utf8;
|
||||
obj->TextW[obj->CurLenW] = '\0';
|
||||
@ -3946,6 +3948,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
{
|
||||
IM_ASSERT(state != NULL);
|
||||
backup_current_text_length = state->CurLenA;
|
||||
state->Edited = false;
|
||||
state->BufCapacityA = buf_size;
|
||||
state->UserFlags = flags;
|
||||
state->UserCallback = callback;
|
||||
@ -4183,7 +4186,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
}
|
||||
|
||||
// User callback
|
||||
if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackAlways)) != 0)
|
||||
if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CallbackAlways)) != 0)
|
||||
{
|
||||
IM_ASSERT(callback != NULL);
|
||||
|
||||
@ -4205,8 +4208,14 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
||||
event_flag = ImGuiInputTextFlags_CallbackHistory;
|
||||
event_key = ImGuiKey_DownArrow;
|
||||
}
|
||||
else if ((flags & ImGuiInputTextFlags_CallbackEdit) && state->Edited)
|
||||
{
|
||||
event_flag = ImGuiInputTextFlags_CallbackEdit;
|
||||
}
|
||||
else if (flags & ImGuiInputTextFlags_CallbackAlways)
|
||||
{
|
||||
event_flag = ImGuiInputTextFlags_CallbackAlways;
|
||||
}
|
||||
|
||||
if (event_flag)
|
||||
{
|
||||
|
Reference in New Issue
Block a user