Skip to content

InputText: Text is not clipped correctly #8967

Closed

Description

@Cyphall

Version/Branch of Dear ImGui:

v1.92.3

Back-ends:

imgui_impl_glfw.cpp + custom Vulkan backend

Compiler, OS:

Windows 11, MSVC

Full config/build information:

Dear ImGui 1.92.3 (19230)
--------------------------------

sizeof(size_t): 8, sizeof(ImDrawIdx): 2, sizeof(ImDrawVert): 20
define: __cplusplus=202002
define: IMGUI_DISABLE_OBSOLETE_FUNCTIONS
define: _WIN32
define: _WIN64
define: _MSC_VER=1944
define: _MSVC_LANG=202002
--------------------------------

io.BackendPlatformName: imgui_impl_glfw (3400)
io.BackendRendererName: ImGuiVulkanBackend
io.ConfigFlags: 0x00000000
io.ConfigNavCaptureKeyboard
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000001E
 HasMouseCursors
 HasSetMousePos
 RendererHasVtxOffset
 RendererHasTextures
--------------------------------

io.Fonts: 1 fonts, Flags: 0x00000000, TexSize: 512,128
io.Fonts->FontLoaderName: FreeType
io.DisplaySize: 3840.00,2120.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------

style.WindowPadding: 14.00,14.00
style.WindowBorderSize: 1.00
style.FramePadding: 7.00,5.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 14.00,7.00
style.ItemInnerSpacing: 7.00,7.00

Details:

When using ImGui::InputText, the characters at the left and right boundaries of the text field rect are not correctly clipped.

After investigation, this seems to be caused by a missing ImDrawTextFlags_CpuFineClip flag when RenderText is called:

imgui/imgui_widgets.cpp

Lines 5521 to 5528 in 3470e61

// Render text
if ((is_multiline || (buf_display_end - buf_display) < buf_display_max_length) && (text_col & IM_COL32_A_MASK) && (line_visible_n0 < line_visible_n1))
g.Font->RenderText(draw_window->DrawList, g.FontSize,
draw_pos - draw_scroll + ImVec2(0.0f, line_visible_n0 * g.FontSize),
text_col, clip_rect.AsVec4(),
line_index->get_line_begin(buf_display, line_visible_n0),
line_index->get_line_end(buf_display, line_visible_n1 - 1),
wrap_width, ImDrawTextFlags_WrapKeepBlanks);

Adding this flag fixes the issue.

Screenshots/Video:

Image

Minimal, Complete and Verifiable Example code:

ImGui::Begin("Example Bug");
static std::string str = "test_test_test_test_test_test_test_test_test_test_test_test_test_test_test_test;
ImGui::InputText("Text field", &str);
ImGui::End();

Activity

  1. ocornut commented on Sep 29, 2025

    @ocornut
    Owner

    Thank you. This is a regression in a82f66a caused by the change from DrawList->AddText(...) to lower-level g.Font->RenderText(....) which requires the flag. I have pushed the fix 1c87024. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      ⌂ 换网址