InputText: avoid continuously overwriting ownership of ImGuiKey_Enter / ImGuiKey_KeypadEnter in order to allow e.g. external Shortcut to override behavior. (#9004)
This commit is contained in:
@@ -47,6 +47,8 @@ Other Changes:
|
|||||||
result in temporarily incorrect state, which would lead to bugs to side effects
|
result in temporarily incorrect state, which would lead to bugs to side effects
|
||||||
in various locations, e.g. GetContentRegionAvail() calls or using clipper. (#9005)
|
in various locations, e.g. GetContentRegionAvail() calls or using clipper. (#9005)
|
||||||
EndTable() was mistakenly restoring a wrong current table.
|
EndTable() was mistakenly restoring a wrong current table.
|
||||||
|
- InputText: avoid continuously overwriting ownership of ImGuiKey_Enter/_KeypadEnter
|
||||||
|
keys in order to allow e.g. external Shortcut override behavior. (#9004)
|
||||||
- InputTextMultiline: fixed a crash when using ImGuiInputTextFlags_WordWrap and
|
- InputTextMultiline: fixed a crash when using ImGuiInputTextFlags_WordWrap and
|
||||||
resizing the parent window while keeping the multi-line field active (which is
|
resizing the parent window while keeping the multi-line field active (which is
|
||||||
most typically achieved when resizing programmatically or via a docking layout
|
most typically achieved when resizing programmatically or via a docking layout
|
||||||
|
|||||||
+7
-5
@@ -4820,7 +4820,7 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
{
|
{
|
||||||
// Declare some inputs, the other are registered and polled via Shortcut() routing system.
|
// Declare some inputs, the other are registered and polled via Shortcut() routing system.
|
||||||
// FIXME: The reason we don't use Shortcut() is we would need a routing flag to specify multiple mods, or to all mods combination into individual shortcuts.
|
// FIXME: The reason we don't use Shortcut() is we would need a routing flag to specify multiple mods, or to all mods combination into individual shortcuts.
|
||||||
const ImGuiKey always_owned_keys[] = { ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_Enter, ImGuiKey_KeypadEnter, ImGuiKey_Delete, ImGuiKey_Backspace, ImGuiKey_Home, ImGuiKey_End };
|
const ImGuiKey always_owned_keys[] = { ImGuiKey_LeftArrow, ImGuiKey_RightArrow, ImGuiKey_Delete, ImGuiKey_Backspace, ImGuiKey_Home, ImGuiKey_End };
|
||||||
for (ImGuiKey key : always_owned_keys)
|
for (ImGuiKey key : always_owned_keys)
|
||||||
SetKeyOwner(key, id);
|
SetKeyOwner(key, id);
|
||||||
if (user_clicked)
|
if (user_clicked)
|
||||||
@@ -5028,7 +5028,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
|
|
||||||
// We allow validate/cancel with Nav source (gamepad) to makes it easier to undo an accidental NavInput press with no keyboard wired, but otherwise it isn't very useful.
|
// We allow validate/cancel with Nav source (gamepad) to makes it easier to undo an accidental NavInput press with no keyboard wired, but otherwise it isn't very useful.
|
||||||
const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
||||||
const bool is_enter_pressed = IsKeyPressed(ImGuiKey_Enter, true) || IsKeyPressed(ImGuiKey_KeypadEnter, true);
|
const bool is_enter = Shortcut(ImGuiKey_Enter, f_repeat, id) || Shortcut(ImGuiKey_KeypadEnter, f_repeat, id);
|
||||||
|
const bool is_ctrl_enter = Shortcut(ImGuiMod_Ctrl | ImGuiKey_Enter, f_repeat, id) || Shortcut(ImGuiMod_Ctrl | ImGuiKey_KeypadEnter, f_repeat, id);
|
||||||
const bool is_gamepad_validate = nav_gamepad_active && (IsKeyPressed(ImGuiKey_NavGamepadActivate, false) || IsKeyPressed(ImGuiKey_NavGamepadInput, false));
|
const bool is_gamepad_validate = nav_gamepad_active && (IsKeyPressed(ImGuiKey_NavGamepadActivate, false) || IsKeyPressed(ImGuiKey_NavGamepadInput, false));
|
||||||
const bool is_cancel = Shortcut(ImGuiKey_Escape, f_repeat, id) || (nav_gamepad_active && Shortcut(ImGuiKey_NavGamepadCancel, f_repeat, id));
|
const bool is_cancel = Shortcut(ImGuiKey_Escape, f_repeat, id) || (nav_gamepad_active && Shortcut(ImGuiKey_NavGamepadCancel, f_repeat, id));
|
||||||
|
|
||||||
@@ -5063,11 +5064,11 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
}
|
}
|
||||||
state->OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask);
|
state->OnKeyPressed(STB_TEXTEDIT_K_BACKSPACE | k_mask);
|
||||||
}
|
}
|
||||||
else if (is_enter_pressed || is_gamepad_validate)
|
else if (is_enter || is_ctrl_enter || is_gamepad_validate)
|
||||||
{
|
{
|
||||||
// Determine if we turn Enter into a \n character
|
// Determine if we turn Enter into a \n character
|
||||||
bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0;
|
bool ctrl_enter_for_new_line = (flags & ImGuiInputTextFlags_CtrlEnterForNewLine) != 0;
|
||||||
if (!is_multiline || is_gamepad_validate || (ctrl_enter_for_new_line != io.KeyCtrl))
|
if (!is_multiline || is_gamepad_validate || (ctrl_enter_for_new_line != is_ctrl_enter))
|
||||||
{
|
{
|
||||||
validated = true;
|
validated = true;
|
||||||
if (io.ConfigInputTextEnterKeepActive && !is_multiline)
|
if (io.ConfigInputTextEnterKeepActive && !is_multiline)
|
||||||
@@ -5077,7 +5078,8 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
|
|||||||
}
|
}
|
||||||
else if (!is_readonly)
|
else if (!is_readonly)
|
||||||
{
|
{
|
||||||
unsigned int c = '\n'; // Insert new line
|
// Insert new line
|
||||||
|
unsigned int c = '\n';
|
||||||
if (InputTextFilterCharacter(&g, &c, flags, callback, callback_user_data))
|
if (InputTextFilterCharacter(&g, &c, flags, callback, callback_user_data))
|
||||||
state->OnCharPressed(c);
|
state->OnCharPressed(c);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user