f5befd2d29 Version 1.91.9b cfed7a3a54 Tables: fixed assert/issues loading settings. (#8496, #7934) 93b446a962 Backtrack of version tagging 1.92.0 > 1.91.9b for publishing a hotfix (#8496) a7dc184772 Moved ImDrawIdx definition lower in imgui.h. Moved ImTextureID slightly below in its own section. bfaef8ca17 Version 1.92.0 WIP 2737dbb1e1 Docs: Fixed typo. Very oops. (#8495) 4d4f1fd364 Docs: retroactively document ConfigData->Sources renaming. (#8495) d6493aab02 Fix typo in comment (#8494) 97428e8ac9 Version 1.91.9 ea2a12112d Misc: Various zealous warning fixes for newer version of Clang. b758b8223f InputText: Pasting a multi-line buffer into a single-line edit replaces carriage return by spaces. (#8459) 79bba34c5f Revert "Added ImGuiKey_AbntC1, ImGuiKey_AbntC2 + Backends: GLFW, Win32: added support. (#8468)" d9dad2f4a1 Scrollbar: stabilize visibility of ScrollbarX when detecting a feedback loop. (#8488, #3285, #4539) 6e30c42101 Tables: fixed an issue with TableSetupColumn() overriding ini data. (#7934) de4f77b0ac Backends: DX12: comment about using SrvDescriptorAllocFn/SrvDescriptorFreeFn. 09654f4e8c Revert "Examples: Updated all .vcxproj from VS2015 to VS2019 (toolset v140 to v142), Windows SDK 8.1 to 10." 557c77e455 Added ImGuiKey_AbntC1, ImGuiKey_AbntC2 + Backends: GLFW, Win32: added support. (#8468) 6da230636b Examples: Updated all .vcxproj from VS2015 to VS2019 (toolset v140 to v142), Windows SDK 8.1 to 10. 51e4cba909 Backends: Fixed zealous warnings. 39585aa90d Amend Changelog to talk about OEM keys. (#7136, #7201, #7206, #7306, #7670, #7672, #8468) a9e53829d2 Backends: Win32, SDL2, SDL3, GLFW: prioritize scancodes instead of translated keycodes when dealing with OEM keys + Added ImGuiKey_Oem102. (#7136, #7201, #7206, #7306, #7670, #7672, #8468) 88d4827b64 Update FAQ.md for SDL3 (#8480) 3c3d943fb1 Docs: Fix some typos (#8473) 806731e37a Set IMGUI_DISABLE_DEFAULT_SHELL_FUNCTIONS on 3DS sdk (#8477, #8476) 1ec99f4fd3 Internals: added ImStrlen/ImMemchr #define to facilitate experimenting with variations. (#8421) 377a387a42 Add proper ImGuiTextBuffer::resize() support other than 0. 9f49292b35 Internals: Menus: reworked mangling of menu windows to use "###Menu_00" etc. instead of "##Menu_00". 119dfbc627 Debug Tools: Tweaked layout of ID Stack Tool and always display full path. (#4631) fcec08f7ae Demo: (Refactor) Moved ExampleTreeNode contents below ShowDemoWindow() so main entry point is more visible to casual reader. 324172fb1f Demo: (Refactor) Moved DemoWindowWidgets() below the functions it calls, reducing amount of forward declarations. a7657f2ed4 Examples: SDL3: Added comments to clarify setup for users of the unfortunate SDL_MAIN_USE_CALLBACKS feature. (#8455) df31774327 Disabled: Fixed an issue restoring Alpha in EndDisabled() when using nested BeginDisabled() calls with PushStyleVar(ImGuiStyleVar_DisabledAlpha) within. (#8454, #7640) 71b160cdbb Demo: (Refactor) Moved code into DemoWindowWidgetsDisableBlocks() section. 7a919e80c9 Demo: (Refactor) Moved code into DemoWindowWidgetsQueryingStatuses() section. 0758594bd2 Demo: (Refactor) Moved code into DemoWindowWidgetsDragAndDrop() section. 9b486e47fe Demo: (Refactor) Moved code into DemoWindowWidgetsDragsAndSliders(), DemoWindowWidgetsMultiComponents(), DemoWindowWidgetsVerticalSliders() sections. caf3faa054 Demo: (Refactor) Moved code into DemoWindowWidgetsColorAndPickers() section. 510a9a77d6 Demo: (Refactor) Moved code into DemoWindowWidgetsDataTypes() section. 4d0c776a80 Demo: (Refactor) Moved code into DemoWindowWidgetsPlotting(), DemoWindowWidgetsProgressBars(), DemoWindowWidgetsTabs() sections. 4450d61ac2 Demo: (Refactor) Moved code into DemoWindowWidgetsSelectables(), DemoWindowWidgetsTextFilter(), DemoWindowWidgetsTextInputs() sections. 22baec494b Demo: (Refactor) Moved code into DemoWindowWidgetsComboBoxes(), DemoWindowWidgetsImages(), DemoWindowWidgetsListBoxes() sections. 94877a137d Demo: (Refactor) Moved code into DemoWindowWidgetsBullets(), DemoWindowWidgetsCollapsingHeaders(), DemoWindowWidgetsCollapsingText() sections. de3f68a233 Demo: (Refactor) Moved code into DemoWindowWidgetsTooltips(), DemoWindowWidgetsTreeNodes() sections. b2c55c9db5 Demo: (Refactor) Moved code into DemoWindowWidgetsBasic() section. eefd2da0f6 Demo: (Refactor) Added new empty sections.. Renamed existing helper functions. ce13f6b73e Backends: GLFW: Fixed clipboard handler assertion when using GLFW <= 3.2.1 compiled with asserts enabled. (#8452) 4819eae867 Clipper: Fixed an issue where passing an out of bound index to IncludeItemByIndex() could incorrectly offset the final cursor. c5ade6591e TextLink(), TextLinkOpenURL(): fixed honoring text baseline alignment. (#8451, #7660) 9c2876b9f8 ShowFontAtlas() uses ImageWithBg(). (#8131, #8238) 1aab00da85 Misc shallow tweaks/tidying up. (#8446) 482a1f50b6 Internals: rename ImGuiDataVarInfo to ImGuiStyleVarInfo. Move ImGuiStyleMod, ImGuiColorMod to own section. 494ea57b65 Image: removed 'tint_col', 'border_col' parameters from Image(). Added ImageWithBg(). Added style.ImageBorderSize, ImGuiStyleVar_ImageBorderSize. (#8131, #8238) cdafefd4be Backends: WebGPU: Add nextInChain field for VertexAttributes under Dawn (#8438) 8bd3e20c86 Backends: WebGPU: include imgui.h before backend check (#8437) aa83d5d455 Backends: SDL2, SDL3: Only start SDL_CaptureMouse() when mouse is being dragged. (#6410, #3650) aaacb01b8d Backends: WebGPU: Recreate image bind groups during render. (#8426, #8046, #7765, #8027) 9996a2d51b Backends: WebGPU: update code for latest webgpu-native changes. Fix for Emscripten. (#8426) 6aa0810de5 Backends: WebGPU: update code for latest webgpu-native changes. Amend. (#8426) 4f4fb1d220 Backends: WebGPU: update code for latest webgpu-native changes. (#8426) 242d856ede Examples: SDL3+SDL_Renderer: removed reference to OpenGL to remove confusion. (#8434) a86fcbd947 Examples: SDL3+SDL_Renderer: removed reference to OpenGL to remove confusion. (#8434) 4c0604ec2e Font: shallow refactor, rename ConfigData[] fields to Sources[], ConfigDataCount to SourcesCount. 6e29450f76 Internals: added IsItemActiveAsInputText() helper. 030746faff Debug Tools: Added io.ConfigDebugHighlightIdConflictsShowItemPicker. (#7961, #7669) dac40d0487 Backends: SDL2, SDL3: don't call SDL_GetGlobalMouseState() when mouse position is in relative mode. (#8425, #8407) ef969a53f5 Tabs: fixed Unsaved Marker not being visible when Close Button is. (#8430, #8387) 5dce79e941 Backends: DirectX12: Fixed an issue where pre-1.91.5 legacy ImGui_ImplDX12_Init() signature started breaking in 1.91.8 due to missing command queue. (#8429) 74afea04d6 Fix typos in docs (#8427) edc66d79c7 Nav: extract code into a NavUpdateWindowingApplyFocus() so it may be reused elsewhere. 434b7710f3 Internals: packing ImGuiDataVarInfo + misc renaming + value of ImGuiDataType_Pointer doesn't need to be Count+1 1e18a6cf60 Examples: GLFW+Vulkan: make GLFW_DIR overridable in cmake bit. (#8419) a6bcbb173b Examples: Android: Update kotlin version (#8409) 6dc376f676 ImFontAtlas: added software/drawlist version of ImGuiMouseCursor_Wait/ImGuiMouseCursor_Progress + moved GetMouseCursorTexData() to internals. 85c488ee12 Hot-fix for broken MouseDrawCursor support for ImGuiMouseCursor_Wait/ImGuiMouseCursor_Progress/ImGuiMouseCursor_NotAllowed. 05742f9b6f Tables: share code between TableSetupColumn() and TableLoadSettings(). (#7934) 8b7b3ce03e Tables: fixed an issue where Columns Width state wouldn't be correctly restored when hot-reloading .ini state. (#7934) eec097fe35 Added ImGuiMouseCursor_Progress mouse cursor 8a35386+ support in SDL2,SDL3,Win32,Allegro5 backends. 8a35386ba7 Added ImGuiMouseCursor_Wait mouse cursor (busy/wait/hourglass shape) + support in SDL2,SDL3,Win32,Allegro5 backends. 8f0411ff03 Backends: OpenGL3: Lazily reinitialize embedded GL loader for when calling backend from e.g. other DLL boundaries. (#8406) c4a32a129d Tabs: fixed middle-button to close not checking hovering, only close button visibility. (#8399, #8387) 78ec1272e9 ImDrawList: added InitialFringeScale in ImDrawListSharedData. Default to 1.0f. 2860d7ba05 Selectable: Fixed horizontal label alignment with SelectableTextAlign.x > 0 and specifying a selectable size. (#8338) 474305c476 ImFont: simpler constructor. ec4cd2cb8c Backends: Vulkan: Fixed crash with using no prototypes + *BREAKING* Added ApiVersion to ImGui_ImplVulkan_LoadFunctions(). (#8326, #8365, #8400) 98c2f6b0c4 Tables, Error Handling: Recovery from invalid index in TableSetColumnIndex(). (#1651) e1ae7db4cc Backends: Vulkan: Fixed building with older headers not supporting VK_HEADER_VERSION_COMPLETE. (#8326, #8365) 12963f5231 Examples: Vulkan: make ApiVersion a little more visible in examples. (#8326, #8365) 890ead6a71 Backends: Vulkan: Added ApiVersion field in ImGui_ImplVulkan_InitInfo. Dynamic rendering path loads "vkCmdBeginRendering/vkCmdEndRendering" without -KHR on API 1.3. (#8326, #8365) f94a5f0e8c Docs: Update doc about plutosvg (#8395) b78cc37891 Backends: SDL2: Fixed build for versions older than 2.0.14. (#7660) a931fb7f51 Fixed static analyzer warning. 7cd31c3557 Tables: tamed some .ini settings optimizations to more accurately allow overwriting/hot-reloading settings. (#7934) 7221f5e739 Styles, Tabs: Fixed ef7ffaf. (#8387) ef7ffaff74 Styles, Tabs: (Breaking) Renamed TabMinWidthForCloseButton to TabCloseButtonMinWidthUnselected. Added TabCloseButtonMinWidthSelected. (#8387) 3d900edba7 Examples: Win32+DirectX12: Fixed ExampleDescriptorHeapAllocator overflow free index. 6916f935eb InputText: Allow CTRL+Shift+Z to redo even outside of OSX. (#8389) 3b2f2602b4 Windows: Fixed an issue where BeginChild() inside a collapsed Begin() wouldn't inherit the SkipItems flag. 4dc9df6aae Tables: fixed an issue where Columns Visible/Hidden state wouldn't be correctly overridden when hot-reloading .ini state. (#7934) 88cda0cab6 Fixed minor warning. Added comment. a431e1277e Backends: SDL2, SDL3: Using SDL_OpenURL() in platform_io.Platform_OpenInShellFn handler. (#7660) a18622c369 TextLinkOpenURL(): fixed default Win32 io.PlatformOpenInShellFn handler to handle UTF-8 regardless of system regional settings. (#7660) 2206e31e54 Demo: Combos: demonstrate a very simple way to add a filter to a combo. (#718) e8ad60cc4f Fix typo (#8382) 50dbb086f2 Tables: sneakily honor ImGuiNextWindowDataFlags_HasChildFlags/ImGuiNextWindowDataFlags_HasWindowFlags as a way to facilitate various hacks/workarounds. e368015d79 Tables: a clipped scrolling table correctly clears SetNextWindowXXX flags. (#8196) e5668b8c73 Internals: rename ImGuiNextWindowData::Flags to HasFlags for consistency and to reduce mistakes. 4982602f6f Windows, Style: Added style.WindowBorderHoverPadding setting to configure inner/outer padding applied to hit-testing of windows borders. 914fbcf2e5 Fonts: removed unnecessary const qualifier from ImFont::FindGlyph() 4f1d3809c3 Fixed tabs and spaces (#8377) 0625b37760 Scrollbar: Rework logic that fades-out scrollbar when it becomes too small. cfed18afc7 Add ImFontConfig::GlyphExtraAdvanceX as a replacement for GlyphExtraSpacing.x (#242) 2d20e13746 Backends: GLFW: Added comment about io.AddMouseSourceEvent() not being properly called. (#8374) 1a31e31ae9 (Breaking) Fonts: removed ImFontConfig::GlyphExtraSpacing option which seems largely obsolete and unused. (#242) de962e83d0 ImFont: remove SetGlyphVisible() da0ba9e2fe Backends: WebGPU: add type alias for dawn WGPUProgrammableStageDescriptor -> WGPUComputeState. (#8369) 5dd84082ab InputTextWithHint(): Fixed buffer overflow when user callback modifies the buffer contents in a way that alters hint visibility. (#8368) 204cebc8fc Backends: Metal: Fixed a crash on application resources. (#8367, #7419) [@anszom] 6265339995 Fixed IsItemDeactivatedAfterEdit() signal being broken for Checkbox(), RadioButton(), Selectable(). (#8370) f820bf7cd4 Version 1.91.9 WIP e4db4e423d Internals: renamed GetIOEx() to GetIO(). Added GetPlatformIO() explicit context variant. - OOPS e2a99b5760 Internals: renamed GetIOEx() to GetIO(). Added GetPlatformIO() explicit context variant. dbb5eeaadf Version 1.91.8 e6c5296f30 Examples: SDL3: Fix for Emscripten platform (#8363) ae6cfd32a0 Tables, Menus: Fixed tables or child windows submitted inside BeginMainMenuBar() being unable to save their settings. (#8356) fa178f4235 Error Handling: Recovery from missing EndMenuBar() call. (#1651) c0308da665 Fixed zealous GCC warning. (#8355) dabc990189 Rename internal id for standardizing naming convention. "##menubar" -> "##MenuBar", "###NavWindowingList" -> "###NavWindowingOverlay" a71191515a EndMainMenuBar doesn't attempt to restore focus when there's an active id. (#8355) dfd1bc3c5b Tables, Menus: Fixed using BeginTable() in menu layer (any menu bar). (#8355) 4230e98720 Error Handling, Debug Log: IMGUI_DEBUG_LOG_ERROR() doesn't need the extra variable. ea0da0bf47 Extracted PushPasswordFont() out of InputText code. 9c4948a4d1 TabBar: Internals: added TabItemSpacing(). (#8349, #3291) a05d547ae8 Windows: separating WindowItemStatusFlags from ChildItemStatusFlag, because IsItemXXX _after_ BeginChild()>Begin() shouldn't return last status emitted by e.g. EndChild() 134fbe1245 Windows: Fixed IsItemXXXX() functions not working on append-version of EndChild(). (#8350) 5a28f188ff Fixed parameter names to SetLastItemData() to align with current names. 96e3b147f0 Fixed build with IMGUI_ENABLE_FREETYPE (#8346) afb6e9a879 Fonts: OversampleH auto-selection uses 36 as heuristic for now. 8a1613a382 Fonts: OversampleH/OversampleV value defaults to 0 for automatic selection. 4211fdc70b ImFont: compact comments in header section. 9eafb7bbfb ImFont: IndexLookup[] table hold 16-bit values even in ImWchar32 mode. 53244aaac7 Amend 9bc5b04 with a shadowed variable warning fix. ed7551c1d4 Selectable: Fixed horizontal label alignment when combined with using ImGuiSelectableFlags_SpanAllColumns. (#8338) bbf957875b Amend 9bc5b04 to avoid using GImGui mid-function. 9bc5b0406d Windows, Style: Fixed small rendering issues with menu bar, resize grip and scrollbar when using thick border sizes. (#8267, #7887) 10199341b1 ImFontAtlas: made calling ClearFonts() call ClearInputData(). (#8174, #6556, #6336, #4723) 71da34c48c Debug Tools: Tweaked font preview + indent "Glyphs" block. 6906ac979e ColorEdit, ColorPicker: (Breaking) redesigned how alpha is displayed in the preview square. (#8335, #1578, #346) fdca6c08ad Inputs: added IsMouseReleasedWithDelay() helper. (#8337, #8320) d17e9fc107 Backends: SDL_GPU: shallow tweaks + disable anisotropy in sampler. Examples: SDL+Vulkan: Fixed incorrect defines. 3e6bdc2242 Examples: SDL3+SDL_GPU: use SDL_GPU_PRESENTMODE_MAILBOX swapchain parameters. bf13442c7c Moved ImGuiColorEditFlags_AlphaPreview/ImGuiColorEditFlags_AlphaPreviewHalf flags. Demo: reorganized some of color edit/picker demo section. 2af26b75d1 ColorEdit, ColorPicker: Fixed alpha preview broken in 1.91.7. (#8336, #8241). [@PathogenDavid] 7ae7c90790 Tabs, Style: reworked selected overline rendering to better accommodate for rounded tabs. (#8334) e8779a67b1 Font: direct AddText()/RenderText() calls don't need to call strlen() if below clipping region. 4c2e7bb035 Backends: SDL2,SDL3: removed assert preventing using ImGui_ImplSDL2_SetGamepadMode()/ImGui_ImplSDL3_SetGamepadMode() with ImGui_ImplSDL2_GamepadMode_Manual/ImGui_ImplSDL3_GamepadMode_Manual and an empty array. (#8329) 8b0af7fddc Backends: SDL: update comments regarding API stability, regarding SDL_GPU and SDL_Renderer. aa1b4ea861 Backends: OSX: Remove notification observer when shutting down. (#8331) aa23f3801b Backends: SDL_Renderer2/3: Use endian-dependent RGBA32 texture format, to match SDL_Color. (#8327) 80c9cd1f6e Font: reduce unnecessary padding in ImFontConfig struct too. d7454de80a Font: minor tweak to struct alignment. dd89a3741b Backends: Vulkan: sharing duplicate code. (#5446, #8326) 487d7f9a29 Font: Internals: make used page maps smaller. Since it's extremely rarely used and for iterations only. ~34->16 bytes with ImWchar32. f2262eb81a Windows: latch FontRefSize at time of Begin(), consistent with e.g. TitleBarHeight, and to avoid calling CalcFontSize() on non-current window. b7c27c5333 Windows: legacy SetWindowFontScale() is properly inherited by nested child windows. (#2701, #8138, #1018) 4c64ba16c5 imgui_freetype: fixed issue where glyph advances would incorrectly be snapped to pixels. 007735737a Ignore vscode artifacts (#8324) b4a5d1dc53 Backends: SDLGPU3: Rename GpuDevice->Device. Expose ImGui_ImplSDLGPU3_CreateDeviceObjects(), ImGui_ImplSDLGPU3_DestroyDeviceObjects(). Misc renaming. (#8163, #7998, #7988) 0f33d7185f Examples: Vulkan: vkAcquireNextImageKHR() and vkQueuePresentKHR() returning VK_SUBOPTIMAL_KHR keeps moving forward. (#7825, #7831) 8ebf22d3c1 Backends: Vulkan: use ImVector<> for simplicity. 6684984c49 Examples: DirectX12: Reduced number of frame in flight from 3 to 2 in provided example, to reduce latency. 0e21bde77b Misc shallow merge to reduce diff in other branches. 8a9de84cd0 FontAtlas: reduced baked IM_DRAWLIST_TEX_LINES_WIDTH_MAX from 63 to 32. (#3245) 100075f2be Backends: DirectX12: Texture upload use the command queue provided in ImGui_ImplDX12_InitInfo instead of creating its own. c59a2267d0 Version 1.91.8 WIP git-subtree-dir: external/imgui/imgui git-subtree-split: f5befd2d29e66809cd1110a152e375a7f1981f06
24 KiB
(You may browse this at https://github.com/ocornut/imgui/blob/master/docs/FONTS.md or view this file with any Markdown viewer)
Dear ImGui: Using Fonts
The code in imgui.cpp embeds a copy of 'ProggyClean.ttf' (by Tristan Grimmer), a 13 pixels high, pixel-perfect font used by default. We embed it in the source code so you can use Dear ImGui without any file system access. ProggyClean does not scale smoothly, therefore it is recommended that you load your own file when using Dear ImGui in an application aiming to look nice and wanting to support multiple resolutions.
You may also load external .TTF/.OTF files. In the misc/fonts/ folder you can find a few suggested fonts, provided as a convenience.
Also read the FAQ: https://www.dearimgui.com/faq (there is a Fonts section!)
Index
- Troubleshooting
- How should I handle DPI in my application?
- Fonts Loading Instructions
- Loading Font Data from Memory
- Loading Font Data Embedded In Source Code
- Using Icon Fonts
- Using FreeType Rasterizer (imgui_freetype)
- Using Colorful Glyphs/Emojis
- Using Custom Glyph Ranges
- Using Custom Colorful Icons
- About Filenames
- About UTF-8 Encoding
- Debug Tools
- Credits/Licenses For Fonts Included In Repository
- Font Links
Troubleshooting
A vast majority of font and text related issues encountered comes from 4 things:
(1) Invalid filename due to use of \
or unexpected working directory.
See About Filenames. AddFontXXX functions should assert if the filename is incorrect.
(2) Invalid UTF-8 encoding of your non-ASCII strings.
See About UTF-8 Encoding. Use the encoding viewer to confirm encoding of string literal in your source code is correct.
(3) Missing glyph ranges.
You need to load a font with explicit glyph ranges if you want to use non-ASCII characters. See Fonts Loading Instructions. Use Debug Tools confirm loaded fonts and loaded glyph ranges.
This is a current constraint of Dear ImGui (which we will lift in the future): when loading a font you need to specify which characters glyphs to load.
All loaded fonts glyphs are rendered into a single texture atlas ahead of time. Calling either of io.Fonts->GetTexDataAsAlpha8()
, io.Fonts->GetTexDataAsRGBA32()
or io.Fonts->Build()
will build the atlas. This is generally called by the Renderer backend, e.g. ImGui_ImplDX11_NewFrame()
calls it. If you use custom glyphs ranges, make sure the array is persistent and available during the calls to GetTexDataAsAlpha8()/GetTexDataAsRGBA32()/Build()
.
(4) Font atlas texture fails to upload to GPU.
This is often of byproduct of point 3. If you have large number of glyphs or multiple fonts, the texture may become too big for your graphics API. The typical result of failing to upload a texture is if every glyph or everything appears as empty white rectangles. Mind the fact that some graphics drivers have texture size limitation. If you are building a PC application, mind the fact that your users may use hardware with lower limitations than yours.
Some solutions:
- You may reduce oversampling, e.g.
font_config.OversampleH = 1
, this will half your texture size for a quality loss. Note that while OversampleH = 2 looks visibly very close to 3 in most situations, with OversampleH = 1 the quality drop will be noticeable. Read about oversampling here. - Reduce glyphs ranges by calculating them from source localization data.
You can use the
ImFontGlyphRangesBuilder
for this purpose and rebuilding your atlas between frames when new characters are needed. This will be the biggest win! - Set
io.Fonts.Flags |= ImFontAtlasFlags_NoPowerOfTwoHeight;
to disable rounding the texture height to the next power of two. - Set
io.Fonts.TexDesiredWidth
to specify a texture width to reduce maximum texture height (see comment inImFontAtlas::Build()
function).
Future versions of Dear ImGui should solve this problem.
Return to Index
How should I handle DPI in my application?
See FAQ entry.
Return to Index
Fonts Loading Instructions
Load default font:
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontDefault();
Load .TTF/.OTF file with:
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels);
If you get an assert stating "Could not load font file!", your font filename is likely incorrect. Read About filenames carefully.
Load multiple fonts:
// Init
ImGuiIO& io = ImGui::GetIO();
ImFont* font1 = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels);
ImFont* font2 = io.Fonts->AddFontFromFileTTF("anotherfont.otf", size_pixels);
In your application loop, select which font to use:
ImGui::Text("Hello"); // use the default font (which is the first loaded font)
ImGui::PushFont(font2);
ImGui::Text("Hello with another font");
ImGui::PopFont();
For advanced options create a ImFontConfig structure and pass it to the AddFont() function (it will be copied internally):
ImFontConfig config;
config.RasterizerDensity = 2.0f;
ImFont* font = io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, &config);
Combine multiple fonts into one:
// Load a first font
ImFont* font = io.Fonts->AddFontDefault();
// Add character ranges and merge into the previous font
// The ranges array is not copied by the AddFont* functions and is used lazily
// so ensure it is available at the time of building or calling GetTexDataAsRGBA32().
static const ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 }; // Will not be copied by AddFont* so keep in scope.
ImFontConfig config;
config.MergeMode = true;
io.Fonts->AddFontFromFileTTF("DroidSans.ttf", 18.0f, &config, io.Fonts->GetGlyphRangesJapanese()); // Merge into first font
io.Fonts->AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, &config, icons_ranges); // Merge into first font
io.Fonts->Build();
Add a fourth parameter to bake specific font ranges only:
// Basic Latin, Extended Latin
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, nullptr, io.Fonts->GetGlyphRangesDefault());
// Default + Selection of 2500 Ideographs used by Simplified Chinese
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, nullptr, io.Fonts->GetGlyphRangesChineseSimplifiedCommon());
// Default + Hiragana, Katakana, Half-Width, Selection of 1946 Ideographs
io.Fonts->AddFontFromFileTTF("font.ttf", size_pixels, nullptr, io.Fonts->GetGlyphRangesJapanese());
See Using Custom Glyph Ranges section to create your own ranges.
Example loading and using a Japanese font:
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontFromFileTTF("NotoSansCJKjp-Medium.otf", 20.0f, nullptr, io.Fonts->GetGlyphRangesJapanese());
ImGui::Text(u8"こんにちは!テスト %d", 123);
if (ImGui::Button(u8"ロード"))
{
// do stuff
}
ImGui::InputText("string", buf, IM_ARRAYSIZE(buf));
ImGui::SliderFloat("float", &f, 0.0f, 1.0f);
(settings: Dark style (left), Light style (right) / Font: NotoSansCJKjp-Medium, 20px / Rounding: 5)
Return to Index
Loading Font Data from Memory
ImFont* font = io.Fonts->AddFontFromMemoryTTF(data, data_size, size_pixels, ...);
IMPORTANT: AddFontFromMemoryTTF()
by default transfer ownership of the data buffer to the font atlas, which will attempt to free it on destruction.
This was to avoid an unnecessary copy, and is perhaps not a good API (a future version will redesign it).
If you want to keep ownership of the data and free it yourself, you need to clear the FontDataOwnedByAtlas
field:
ImFontConfig font_cfg;
font_cfg.FontDataOwnedByAtlas = false;
ImFont* font = io.Fonts->AddFontFromMemoryTTF(data, data_size, size_pixels, &font_cfg);
Return to Index
Loading Font Data Embedded In Source Code
- Compile and use binary_to_compressed_c.cpp to create a compressed C style array that you can embed in source code.
- See the documentation in binary_to_compressed_c.cpp for instructions on how to use the tool.
- You may find a precompiled version binary_to_compressed_c.exe for Windows inside the demo binaries package (see README).
- The tool can optionally output Base85 encoding to reduce the size of source code but the read-only arrays in the actual binary will be about 20% bigger.
Then load the font with:
ImFont* font = io.Fonts->AddFontFromMemoryCompressedTTF(compressed_data, compressed_data_size, size_pixels, ...);
or
ImFont* font = io.Fonts->AddFontFromMemoryCompressedBase85TTF(compressed_data_base85, size_pixels, ...);
Return to Index
Using Icon Fonts
Using an icon font (such as FontAwesome or OpenFontIcons) is an easy and practical way to use icons in your Dear ImGui application. A common pattern is to merge the icon font within your main font, so you can embed icons directly from your strings without having to change fonts back and forth.
To refer to the icon UTF-8 codepoints from your C++ code, you may use those headers files created by Juliette Foucaut: https://github.com/juliettef/IconFontCppHeaders.
So you can use ICON_FA_SEARCH
as a string that will render as a "Search" icon.
Example Setup:
// Merge icons into default tool font
#include "IconsFontAwesome.h"
ImGuiIO& io = ImGui::GetIO();
io.Fonts->AddFontDefault();
ImFontConfig config;
config.MergeMode = true;
config.GlyphMinAdvanceX = 13.0f; // Use if you want to make the icon monospaced
static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
io.Fonts->AddFontFromFileTTF("fonts/fontawesome-webfont.ttf", 13.0f, &config, icon_ranges);
Example Usage:
// Usage, e.g.
ImGui::Text("%s among %d items", ICON_FA_SEARCH, count);
ImGui::Button(ICON_FA_SEARCH " Search");
// C string _literals_ can be concatenated at compilation time, e.g. "hello" " world"
// ICON_FA_SEARCH is defined as a string literal so this is the same as "A" "B" becoming "AB"
See Links below for other icons fonts and related tools.
Monospace Icons?
To make your icon look more monospace and facilitate alignment, you may want to set the ImFontConfig::GlyphMinAdvanceX value when loading an icon font.
Screenshot
Here's an application using icons ("Avoyd", https://www.avoyd.com):
Return to Index
Using FreeType Rasterizer (imgui_freetype)
- Dear ImGui uses imstb_truetype.h to rasterize fonts (with optional oversampling). This technique and its implementation are not ideal for fonts rendered at small sizes, which may appear a little blurry or hard to read.
- There is an implementation of the ImFontAtlas builder using FreeType that you can use in the misc/freetype/ folder.
- FreeType supports auto-hinting which tends to improve the readability of small fonts.
- Read documentation in the misc/freetype/ folder.
- Correct sRGB space blending will have an important effect on your font rendering quality.
Return to Index
Using Colorful Glyphs/Emojis
- Rendering of colored emojis is supported by imgui_freetype with FreeType 2.10+.
- You will need to load fonts with the
ImGuiFreeTypeBuilderFlags_LoadColor
flag. - Emojis are frequently encoded in upper Unicode layers (character codes >0x10000) and will need dear imgui compiled with
IMGUI_USE_WCHAR32
. - Not all types of color fonts are supported by FreeType at the moment.
- Stateful Unicode features such as skin tone modifiers are not supported by the text renderer.
io.Fonts->AddFontFromFileTTF("../../../imgui_dev/data/fonts/NotoSans-Regular.ttf", 16.0f);
static ImWchar ranges[] = { 0x1, 0x1FFFF, 0 };
static ImFontConfig cfg;
cfg.OversampleH = cfg.OversampleV = 1;
cfg.MergeMode = true;
cfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor;
io.Fonts->AddFontFromFileTTF("C:\\Windows\\Fonts\\seguiemj.ttf", 16.0f, &cfg, ranges);
Return to Index
Using Custom Glyph Ranges
You can use the ImFontGlyphRangesBuilder
helper to create glyph ranges based on text input. For example: for a game where your script is known, if you can feed your entire script to it and only build the characters the game needs.
ImVector<ImWchar> ranges;
ImFontGlyphRangesBuilder builder;
builder.AddText("Hello world"); // Add a string (here "Hello world" contains 7 unique characters)
builder.AddChar(0x7262); // Add a specific character
builder.AddRanges(io.Fonts->GetGlyphRangesJapanese()); // Add one of the default ranges
builder.BuildRanges(&ranges); // Build the final result (ordered ranges with all the unique characters submitted)
io.Fonts->AddFontFromFileTTF("myfontfile.ttf", size_in_pixels, nullptr, ranges.Data);
io.Fonts->Build(); // Build the atlas while 'ranges' is still in scope and not deleted.
Return to Index
Using Custom Colorful Icons
As an alternative to rendering colorful glyphs using imgui_freetype with ImGuiFreeTypeBuilderFlags_LoadColor
, you may allocate your own space in the texture atlas and write yourself into it. (This is a BETA api, use if you are familiar with dear imgui and with your rendering backend)
- You can use the
ImFontAtlas::AddCustomRect()
andImFontAtlas::AddCustomRectFontGlyph()
api to register rectangles that will be packed into the font atlas texture. Register them before building the atlas, then call Build()`. - You can then use
ImFontAtlas::GetCustomRectByIndex(int)
to query the position/size of your rectangle within the texture, and blit/copy any graphics data of your choice into those rectangles. - This API is beta because it is likely to change in order to support multi-dpi (multiple viewports on multiple monitors with varying DPI scale).
Pseudo-code:
// Add font, then register two custom 13x13 rectangles mapped to glyph 'a' and 'b' of this font
ImFont* font = io.Fonts->AddFontDefault();
int rect_ids[2];
rect_ids[0] = io.Fonts->AddCustomRectFontGlyph(font, 'a', 13, 13, 13+1);
rect_ids[1] = io.Fonts->AddCustomRectFontGlyph(font, 'b', 13, 13, 13+1);
// Build atlas
io.Fonts->Build();
// Retrieve texture in RGBA format
unsigned char* tex_pixels = nullptr;
int tex_width, tex_height;
io.Fonts->GetTexDataAsRGBA32(&tex_pixels, &tex_width, &tex_height);
for (int rect_n = 0; rect_n < IM_ARRAYSIZE(rect_ids); rect_n++)
{
int rect_id = rect_ids[rect_n];
if (const ImFontAtlasCustomRect* rect = io.Fonts->GetCustomRectByIndex(rect_id))
{
// Fill the custom rectangle with red pixels (in reality you would draw/copy your bitmap data here!)
for (int y = 0; y < rect->Height; y++)
{
ImU32* p = (ImU32*)tex_pixels + (rect->Y + y) * tex_width + (rect->X);
for (int x = rect->Width; x > 0; x--)
*p++ = IM_COL32(255, 0, 0, 255);
}
}
}
Return to Index
About Filenames
Please note that many new C/C++ users have issues loading their files because the filename they provide is wrong due to incorrect assumption of what is the current directory.
Two things to watch for:
(1) In C/C++ and most programming languages if you want to use a backslash \
within a string literal, you need to write it double backslash \\
. At it happens, Windows uses backslashes as a path separator, so be mindful.
io.Fonts->AddFontFromFileTTF("MyFiles\MyImage01.jpg", ...); // This is INCORRECT!!
io.Fonts->AddFontFromFileTTF("MyFiles\\MyImage01.jpg", ...); // This is CORRECT
In some situations, you may also use /
path separator under Windows.
(2) Make sure your IDE/debugger settings starts your executable from the right working (current) directory. In Visual Studio you can change your working directory in project Properties > General > Debugging > Working Directory
. People assume that their execution will start from the root folder of the project, where by default it often starts from the folder where object or executable files are stored.
io.Fonts->AddFontFromFileTTF("MyImage01.jpg", ...); // Relative filename depends on your Working Directory when running your program!
io.Fonts->AddFontFromFileTTF("../MyImage01.jpg", ...); // Load from the parent folder of your Working Directory
Return to Index
About UTF-8 Encoding
For non-ASCII characters display, a common user issue is not passing correctly UTF-8 encoded strings.
(1) We provide a function ImGui::DebugTextEncoding(const char* text)
which you can call to verify the content of your UTF-8 strings.
This is a convenient way to confirm that your encoding is correct.
ImGui::SeparatorText("CORRECT");
ImGui::DebugTextEncoding(u8"こんにちは");
ImGui::SeparatorText("INCORRECT");
ImGui::DebugTextEncoding("こんにちは");
You can also find this tool under Metrics/Debuggers->Tools->UTF-8 Encoding viewer
if you want to paste from clipboard, but this won't validate the UTF-8 encoding done by your compiler.
(2) To encode in UTF-8:
There are also compiler-specific ways to enforce UTF-8 encoding by default:
- Visual Studio compiler:
/utf-8
command-line flag. - Visual Studio compiler:
#pragma execution_character_set("utf-8")
inside your code. - Since May 2023 we have changed the Visual Studio projects of all our examples to use
/utf-8
(see commit).
Or, since C++11, you can use the u8"my text"
syntax to encode literal strings as UTF-8. e.g.:
ImGui::Text(u8"hello");
ImGui::Text(u8"こんにちは"); // this will always be encoded as UTF-8
ImGui::Text("こんにちは"); // the encoding of this is depending on compiler settings/flags and may be incorrect.
Since C++20, because the C++ committee hate its users, they decided to change the u8""
syntax to not return const char*
but a new type const char8_t*
which doesn't cast to const char*
.
Because of type usage of u8""
in C++20 is a little more tedious:
ImGui::Text((const char*)u8"こんにちは");
However, you can disable this behavior completely using the compiler option /Zc:char8_t-
for MSVC and -fno-char8_t
for Clang and GCC.
Return to Index
Debug Tools
Metrics/Debugger->Fonts
You can use the Metrics/Debugger
window (available in Demo>Tools
) to browse your fonts and understand what's going on if you have an issue. You can also reach it in Demo->Tools->Style Editor->Fonts
. The same information are also available in the Style Editor under Fonts.
UTF-8 Encoding Viewer**
You can use the UTF-8 Encoding viewer
in Metrics/Debugger
to verify the content of your UTF-8 strings. From C/C++ code, you can call ImGui::DebugTextEncoding("my string");
function to verify that your UTF-8 encoding is correct.
Return to Index
Credits/Licenses For Fonts Included In Repository
Some fonts files are available in the misc/fonts/
folder:
Roboto-Medium.ttf, by Christian Robetson
Apache License 2.0
https://fonts.google.com/specimen/Roboto
Cousine-Regular.ttf, by Steve Matteson
Digitized data copyright (c) 2010 Google Corporation.
Licensed under the SIL Open Font License, Version 1.1
https://fonts.google.com/specimen/Cousine
DroidSans.ttf, by Steve Matteson
Apache License 2.0
https://www.fontsquirrel.com/fonts/droid-sans
ProggyClean.ttf, by Tristan Grimmer
MIT License
(recommended loading setting: Size = 13.0, GlyphOffset.y = +1)
http://www.proggyfonts.net/
ProggyTiny.ttf, by Tristan Grimmer
MIT License
(recommended loading setting: Size = 10.0, GlyphOffset.y = +1)
http://www.proggyfonts.net/
Karla-Regular.ttf, by Jonathan Pinhorn
SIL OPEN FONT LICENSE Version 1.1
Return to Index
Font Links
ICON FONTS
- C/C++ header for icon fonts (#define with code points to use in source code string literals) https://github.com/juliettef/IconFontCppHeaders
- FontAwesome https://fortawesome.github.io/Font-Awesome
- OpenFontIcons https://github.com/traverseda/OpenFontIcons
- Google Icon Fonts https://design.google.com/icons/
- Kenney Icon Font (Game Controller Icons) https://github.com/nicodinh/kenney-icon-font
- IcoMoon - Custom Icon font builder https://icomoon.io/app
REGULAR FONTS
- Google Noto Fonts (worldwide languages) https://www.google.com/get/noto/
- Open Sans Fonts https://fonts.google.com/specimen/Open+Sans
- (Japanese) M+ fonts by Coji Morishita http://mplus-fonts.sourceforge.jp/mplus-outline-fonts/index-en.html
MONOSPACE FONTS
Pixel Perfect:
- Proggy Fonts, by Tristan Grimmer http://www.proggyfonts.net or http://upperboundsinteractive.com/fonts.php
- Sweet16, Sweet16 Mono, by Martin Sedlak (Latin + Supplemental + Extended A) https://github.com/kmar/Sweet16Font (also include an .inl file to use directly in dear imgui.)
Regular:
- Google Noto Mono Fonts https://www.google.com/get/noto/
- Typefaces for source code beautification https://github.com/chrissimpkins/codeface
- Programmation fonts http://s9w.github.io/font_compare/
- Inconsolata http://www.levien.com/type/myfonts/inconsolata.html
- Adobe Source Code Pro: Monospaced font family for ui & coding environments https://github.com/adobe-fonts/source-code-pro
- Monospace/Fixed Width Programmer's Fonts http://www.lowing.org/fonts/
Or use Arial Unicode or other Unicode fonts provided with Windows for full characters coverage (not sure of their licensing).