mirror of
https://github.com/ocornut/imgui.git
synced 2026-02-07 04:30:08 +00:00
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_glfw.cpp # backends/imgui_impl_osx.mm # backends/imgui_impl_sdl.cpp # backends/imgui_impl_win32.cpp # imgui.cpp
This commit is contained in:
commit
1dc7d0e633
36 changed files with 357 additions and 253 deletions
|
|
@ -3753,11 +3753,12 @@ static void stb_textedit_replace(ImGuiInputTextState* str, STB_TexteditState* st
|
|||
{
|
||||
stb_text_makeundo_replace(str, state, 0, str->CurLenW, text_len);
|
||||
ImStb::STB_TEXTEDIT_DELETECHARS(str, 0, str->CurLenW);
|
||||
state->cursor = state->select_start = state->select_end = 0;
|
||||
if (text_len <= 0)
|
||||
return;
|
||||
if (ImStb::STB_TEXTEDIT_INSERTCHARS(str, 0, text, text_len))
|
||||
{
|
||||
state->cursor = text_len;
|
||||
state->cursor = state->select_start = state->select_end = text_len;
|
||||
state->has_preferred_x = 0;
|
||||
return;
|
||||
}
|
||||
|
|
@ -4160,7 +4161,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
clear_active_id = true;
|
||||
|
||||
// Lock the decision of whether we are going to take the path displaying the cursor or selection
|
||||
const bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active);
|
||||
bool render_cursor = (g.ActiveId == id) || (state && user_scroll_active);
|
||||
bool render_selection = state && (state->HasSelection() || select_all) && (RENDER_SELECTION_WHEN_INACTIVE || render_cursor);
|
||||
bool value_changed = false;
|
||||
bool validated = false;
|
||||
|
|
@ -4308,7 +4309,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
}
|
||||
|
||||
// Process other shortcuts/key-presses
|
||||
bool cancel_edit = false;
|
||||
bool revert_edit = false;
|
||||
if (g.ActiveId == id && !g.ActiveIdIsJustActivated && !clear_active_id)
|
||||
{
|
||||
IM_ASSERT(state != NULL);
|
||||
|
|
@ -4318,12 +4319,12 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
|
||||
const int k_mask = (io.KeyShift ? STB_TEXTEDIT_K_SHIFT : 0);
|
||||
const bool is_osx = io.ConfigMacOSXBehaviors;
|
||||
const bool is_osx_shift_shortcut = is_osx && (io.KeyMods == (ImGuiModFlags_Super | ImGuiModFlags_Shift));
|
||||
const bool is_osx_shift_shortcut = is_osx && (io.KeyMods == (ImGuiMod_Super | ImGuiMod_Shift));
|
||||
const bool is_wordmove_key_down = is_osx ? io.KeyAlt : io.KeyCtrl; // OS X style: Text editing cursor movement using Alt instead of Ctrl
|
||||
const bool is_startend_key_down = is_osx && io.KeySuper && !io.KeyCtrl && !io.KeyAlt; // OS X style: Line/Text Start and End using Cmd+Arrows instead of Home/End
|
||||
const bool is_ctrl_key_only = (io.KeyMods == ImGuiModFlags_Ctrl);
|
||||
const bool is_shift_key_only = (io.KeyMods == ImGuiModFlags_Shift);
|
||||
const bool is_shortcut_key = g.IO.ConfigMacOSXBehaviors ? (io.KeyMods == ImGuiModFlags_Super) : (io.KeyMods == ImGuiModFlags_Ctrl);
|
||||
const bool is_ctrl_key_only = (io.KeyMods == ImGuiMod_Ctrl);
|
||||
const bool is_shift_key_only = (io.KeyMods == ImGuiMod_Shift);
|
||||
const bool is_shortcut_key = g.IO.ConfigMacOSXBehaviors ? (io.KeyMods == ImGuiMod_Super) : (io.KeyMods == ImGuiMod_Ctrl);
|
||||
|
||||
const bool is_cut = ((is_shortcut_key && IsKeyPressed(ImGuiKey_X)) || (is_shift_key_only && IsKeyPressed(ImGuiKey_Delete))) && !is_readonly && !is_password && (!is_multiline || state->HasSelection());
|
||||
const bool is_copy = ((is_shortcut_key && IsKeyPressed(ImGuiKey_C)) || (is_ctrl_key_only && IsKeyPressed(ImGuiKey_Insert))) && !is_password && (!is_multiline || state->HasSelection());
|
||||
|
|
@ -4379,7 +4380,23 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
}
|
||||
else if (is_cancel)
|
||||
{
|
||||
clear_active_id = cancel_edit = true;
|
||||
if (flags & ImGuiInputTextFlags_EscapeClearsAll)
|
||||
{
|
||||
if (state->CurLenA > 0)
|
||||
{
|
||||
revert_edit = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
render_cursor = render_selection = false;
|
||||
clear_active_id = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
clear_active_id = revert_edit = true;
|
||||
render_cursor = render_selection = false;
|
||||
}
|
||||
}
|
||||
else if (is_undo || is_redo)
|
||||
{
|
||||
|
|
@ -4450,11 +4467,19 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
if (g.ActiveId == id)
|
||||
{
|
||||
IM_ASSERT(state != NULL);
|
||||
if (cancel_edit)
|
||||
if (revert_edit && !is_readonly)
|
||||
{
|
||||
// Restore initial value. Only return true if restoring to the initial value changes the current buffer contents.
|
||||
if (!is_readonly && strcmp(buf, state->InitialTextA.Data) != 0)
|
||||
if (flags & ImGuiInputTextFlags_EscapeClearsAll)
|
||||
{
|
||||
// Clear input
|
||||
apply_new_text = "";
|
||||
apply_new_text_length = 0;
|
||||
STB_TEXTEDIT_CHARTYPE empty_string;
|
||||
stb_textedit_replace(state, &state->Stb, &empty_string, 0);
|
||||
}
|
||||
else if (strcmp(buf, state->InitialTextA.Data) != 0)
|
||||
{
|
||||
// Restore initial value. Only return true if restoring to the initial value changes the current buffer contents.
|
||||
// Push records into the undo stack so we can CTRL+Z the revert operation itself
|
||||
apply_new_text = state->InitialTextA.Data;
|
||||
apply_new_text_length = state->InitialTextA.Size - 1;
|
||||
|
|
@ -4479,7 +4504,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||
// When using 'ImGuiInputTextFlags_EnterReturnsTrue' as a special case we reapply the live buffer back to the input buffer before clearing ActiveId, even though strictly speaking it wasn't modified on this frame.
|
||||
// If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail.
|
||||
// This also allows the user to use InputText() with ImGuiInputTextFlags_EnterReturnsTrue without maintaining any user-side storage (please note that if you use this property along ImGuiInputTextFlags_CallbackResize you can end up with your temporary string object unnecessarily allocating once a frame, either store your string data, either if you don't then don't use ImGuiInputTextFlags_CallbackResize).
|
||||
const bool apply_edit_back_to_user_buffer = !cancel_edit || (validated && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0);
|
||||
const bool apply_edit_back_to_user_buffer = !revert_edit || (validated && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0);
|
||||
if (apply_edit_back_to_user_buffer)
|
||||
{
|
||||
// Apply new value immediately - copy modified buffer back
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue