imgui
imgui copied to clipboard
Set font line height
Dear ImGui 1.83 (18300)
--------------------------------
sizeof(size_t): 8, sizeof(ImDrawIdx): 4, sizeof(ImDrawVert): 20
define: __cplusplus=201703
define: __linux__
define: __GNUC__=7
define: IMGUI_HAS_VIEWPORT
define: IMGUI_HAS_DOCK
--------------------------------
io.BackendPlatformName: imgui_impl_glfw
io.BackendRendererName: imgui_impl_opengl3
io.ConfigFlags: 0x00000000
io.ConfigViewportsNoDecoration
io.ConfigInputTextCursorBlink
io.ConfigWindowsResizeFromEdges
io.ConfigWindowsMoveFromTitleBarOnly
io.ConfigMemoryCompactTimer = 60.0
io.BackendFlags: 0x0000140E
HasMouseCursors
HasSetMousePos
PlatformHasViewports
RendererHasVtxOffset
RendererHasViewports
--------------------------------
io.Fonts: 2 fonts, Flags: 0x00000000, TexSize: 512,1024
io.DisplaySize: 1280.00,800.00
io.DisplayFramebufferScale: 1.00,1.00
--------------------------------
style.WindowPadding: 8.00,8.00
style.WindowBorderSize: 1.00
style.FramePadding: 4.00,3.00
style.FrameRounding: 0.00
style.FrameBorderSize: 0.00
style.ItemSpacing: 8.00,4.00
style.ItemInnerSpacing: 4.00,4.00
My Issue/Question:
I am using a custom font that has minimal vertical margins. This makes reading text with the font difficult. Obviously I can modify the font to increase those, but modifying fonts is non-trivial and error-prone. I was hoping that Dear Imgui would have a way to set the line height/spacing for the font, or some way to add more vertical margin. That way whenever the font was used, it would have the desired spacing.
Screenshots/Video

Standalone, minimal, complete and verifiable example: (see https://github.com/ocornut/imgui/issues/2261)
The font I am using is AcPlus_IBM_BIOS.ttf, as seen here. It can be downloaded as part of this ZIP.
I am using DearPyGUI so I don't have C/C++ code for you. I filed this issue here because I can't find anything about this in the upstream API.
My Python code simply just loads the font and the demo:
import dearpygui.dearpygui as dpg
font_chars = # all the character codes for this font
with dpg.font_registry():
with dpg.font("AcPlus_IBM_BIOS.ttf", 16, default_font=True):
dpg.add_font_chars(font_chars)
dpg.show_imgui_demo()
dpg.start_dearpygui()
Thank you!
Hello, I believe this is the same issue as #2945 Its simultaneously trivial and tricky as given the general use of FontSize as line height in much code, the most accessible solution is to bake GlyphExtraSpacing.y into output FontSize so Input FontSize will be != Output FontSize.
Will at least add this feature mentioned in #2945
Hi,
Is there an estimate when we can have this implemented? I have hacked an effective equivalent of this feature with SetCursorScreenPos(), but I would like to just set one parameter instead of sprinkling cursor adjustments across the code, along with modifications to the value returned by GetFontSize().
In the screenshot below the left hand side shows adjusted font height (with some issues, as only the cursor is moved, and the font height is left as is), and the right hand side shows how the text is rendered without any modifications.

Is there an estimate when we can have this implemented?
Not too long. https://github.com/ocornut/imgui/pull/4742
ExtraLineHeight=0 |
ExtraLineHeight=8 |
|---|---|
![]() |
![]() |

