From bd63a9f05698bf6b3baa27b2fb585414c47878b5 Mon Sep 17 00:00:00 2001 From: ocornut Date: Mon, 11 Sep 2023 10:04:18 +0200 Subject: [PATCH] Fonts: 'float size_pixels' passed to AddFontXXX() functions is now rounded to lowest integer. (#3164, #3309, #6800) Note that using io.FontGlobalScale or SetWindowFontScale(), with are legacy-ish, partially supported features, can still lead to unrounded sizes and same issues. --- docs/CHANGELOG.txt | 3 +++ imgui_draw.cpp | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/docs/CHANGELOG.txt b/docs/CHANGELOG.txt index 35a5ec6c..77061f43 100644 --- a/docs/CHANGELOG.txt +++ b/docs/CHANGELOG.txt @@ -53,6 +53,9 @@ Breaking changes: Other changes: +- Fonts: 'float size_pixels' passed to AddFontXXX() functions is now rounded to lowest integer. + This is because our layout/font system currently doesn't fully support non-integer sizes. Until + it does, this has been a common pitfall leading to more or less subtle issues. (#3164, #3309, #6800) - InputTextMultiline: Fixed a crash pressing Down on last empty line of a multiline buffer. (regression from 1.89.2, only happened in some states). (#6783, #6000) - BeginListBox(): Fixed not consuming SetNextWindowXXX data when returning false. diff --git a/imgui_draw.cpp b/imgui_draw.cpp index 126eef0e..1d2e14c3 100644 --- a/imgui_draw.cpp +++ b/imgui_draw.cpp @@ -2850,6 +2850,13 @@ static void ImFontAtlasBuildRenderLinesTexData(ImFontAtlas* atlas) // Note: this is called / shared by both the stb_truetype and the FreeType builder void ImFontAtlasBuildInit(ImFontAtlas* atlas) { + // Round font size + // - We started rounding in 1.90 WIP (18991) as our layout system currently doesn't support non-rounded font size well yet. + // - Note that using io.FontGlobalScale or SetWindowFontScale(), with are legacy-ish, partially supported features, can still lead to unrounded sizes. + // - We may support it better later and remove this rounding. + for (ImFontConfig& cfg : atlas->ConfigData) + cfg.SizePixels = ImFloor(cfg.SizePixels); + // Register texture region for mouse cursors or standard white pixels if (atlas->PackIdMouseCursors < 0) {