Skip to content

Commit 697ce2d

Browse files
committed
InputText: Fixed a one-frame display glitch where pressing Escape to revert after a deletion would lead to small garbage being displayed for one frame. (#3008)
Curiously very old, amend 83efdce and bdbb2b2. Using stb_ functions updated ->CurLenA without updating ->TextA, leading to `buf_display_end = buf_display + state->CurLenA;` in the display. Since f3ab5e6 they are 1 case out of 4 which didn't apply back to ->TextA and this is essentially the one where we ensure appliance. Another solution would be to alter the lower display code, but applying to TextA makes things more consistent.
1 parent 5139fb7 commit 697ce2d

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Other Changes:
8383
return value is overriden by focus when gamepad/keyboard navigation is active.
8484
- InputText: Fixed pressing Tab emitting two tabs characters because of dual Keys/Chars events being
8585
trickled with the new input queue (happened on some backends only). (#2467, #1336)
86+
- InputText: Fixed a one-frame display glitch where pressing Escape to revert after a deletion
87+
would lead to small garbage being displayed for one frame. Curiously a rather old bug! (#3008)
8688
- Tables: Fixed incorrect border height used for logic when resizing one of several synchronized
8789
instance of a same table ID, when instances have a different height. (#3955).
8890
- Tables: Fixed incorrect auto-fit of parent windows when using non-resizable weighted columns. (#5276)

imgui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Index of this file:
6565
// Version
6666
// (Integer encoded as XYYZZ for use in #if preprocessor conditionals. Work in progress versions typically starts at XYY99 then bounce up to XYY00, XYY01 etc. when release tagging happens)
6767
#define IMGUI_VERSION "1.88 WIP"
68-
#define IMGUI_VERSION_NUM 18723
68+
#define IMGUI_VERSION_NUM 18724
6969
#define IMGUI_CHECKVERSION() ImGui::DebugCheckVersionAndDataLayout(IMGUI_VERSION, sizeof(ImGuiIO), sizeof(ImGuiStyle), sizeof(ImVec2), sizeof(ImVec4), sizeof(ImDrawVert), sizeof(ImDrawIdx))
7070
#define IMGUI_HAS_TABLE
7171

imgui_widgets.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4425,22 +4425,24 @@ bool ImGui::InputTextEx(const char* label, const char* hint, char* buf, int buf_
44254425
}
44264426
}
44274427

4428+
// Apply ASCII value
4429+
if (!is_readonly)
4430+
{
4431+
state->TextAIsValid = true;
4432+
state->TextA.resize(state->TextW.Size * 4 + 1);
4433+
ImTextStrToUtf8(state->TextA.Data, state->TextA.Size, state->TextW.Data, NULL);
4434+
}
4435+
44284436
// 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.
44294437
// If we didn't do that, code like InputInt() with ImGuiInputTextFlags_EnterReturnsTrue would fail.
44304438
// 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).
4431-
bool apply_edit_back_to_user_buffer = !cancel_edit || (enter_pressed && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0);
4439+
const bool apply_edit_back_to_user_buffer = !cancel_edit || (enter_pressed && (flags & ImGuiInputTextFlags_EnterReturnsTrue) != 0);
44324440
if (apply_edit_back_to_user_buffer)
44334441
{
44344442
// Apply new value immediately - copy modified buffer back
44354443
// Note that as soon as the input box is active, the in-widget value gets priority over any underlying modification of the input buffer
44364444
// FIXME: We actually always render 'buf' when calling DrawList->AddText, making the comment above incorrect.
44374445
// FIXME-OPT: CPU waste to do this every time the widget is active, should mark dirty state from the stb_textedit callbacks.
4438-
if (!is_readonly)
4439-
{
4440-
state->TextAIsValid = true;
4441-
state->TextA.resize(state->TextW.Size * 4 + 1);
4442-
ImTextStrToUtf8(state->TextA.Data, state->TextA.Size, state->TextW.Data, NULL);
4443-
}
44444446

44454447
// User callback
44464448
if ((flags & (ImGuiInputTextFlags_CallbackCompletion | ImGuiInputTextFlags_CallbackHistory | ImGuiInputTextFlags_CallbackEdit | ImGuiInputTextFlags_CallbackAlways)) != 0)

0 commit comments

Comments
 (0)