diff --git a/HellionChat/Ui/StyleEngine/BaselineMath.cs b/HellionChat/Ui/StyleEngine/BaselineMath.cs new file mode 100644 index 0000000..4fdb87b --- /dev/null +++ b/HellionChat/Ui/StyleEngine/BaselineMath.cs @@ -0,0 +1,19 @@ +namespace HellionChat.Ui.StyleEngine; + +// TEST-MIRROR: Ui/BaselineMathTests.cs +// +// ImGui lines items up on a row by their top edge, not their baseline: ItemSize +// only shifts anything when CurrLineTextBaseOffset is non-zero, and that stays at +// zero unless AlignTextToFramePadding ran. So a smaller face beside a larger one +// hangs, flush at the top and floating above the baseline. +// +// The correction is the difference between the two ascents. It is easy to assume +// the display scale is applied twice here and it is not: Dalamud rasterises at +// SizePx * GlobalScale and then divides the metrics straight back down +// (ImGuiHelpers.AdjustGlyphMetrics(1 / scale, ...)), so ImFont.Ascent is a +// logical value. Drawing multiplies it up again -- and so must this. +internal static class BaselineMath +{ + internal static float OffsetFor(float ascentLarge, float ascentSmall, float uiScale) => + MathF.Max(0f, (ascentLarge - ascentSmall) * uiScale); +}