Files
HellionChat/HellionChat/Ui/StyleEngine/Metrics.cs
T
JonKazama-Hellion 5b738e6885 chore: comments say what the code does, not which task produced it
A comment that reads "MUST stay in lockstep with TryGetActiveCrossfade (K8)"
helps nobody outside the plan that used to have a K8 in it, and the plans are
not in this repo. Same for "Spec FR-4", "plan §B.2", "Sub-Task 4.4" and the
F/R/M/A/S round codes scattered through the style engine and the self-tests.

Personal names go too. "tester feedback from Jin (v1.4.7)" and "Flo decision
2026-06-15" carry the reason fine without naming anyone -- the version and the
reason are the parts a reader can act on, and a public repo should not need a
cast list to be read.

The rule applied throughout: keep the why, drop the reference. Version numbers
stay, since those resolve through the changelog. 77 files.

ChunkUtil also carried 281 lines of commented-out code -- an older ToChunks
variant and two helpers with no callers, inherited and never removed. Deleted;
git remembers them.
2026-08-19 21:50:31 +02:00

114 lines
5.2 KiB
C#

using Dalamud.Bindings.ImGui;
using Dalamud.Interface.Utility;
using HellionChat.Util;
namespace HellionChat.Ui.StyleEngine;
// Layout values, authored at 100% display scaling. Draw code reads the scaled
// properties; the Raw constants exist only for the few places that must store or
// compare an unscaled value (Sidebar.GetWidth, the width slider bounds).
//
// Deliberately NOT part of ThemeLayout: that record is serialised into theme
// JSON, and layout customisation is deliberately out of scope.
internal static class Metrics
{
// --- Sidebar ---
internal const float SidebarIconOnlyWidthRaw = 38f;
internal const float SidebarMinWidthRaw = 40f;
internal const float SidebarMaxWidthRaw = 300f;
internal const float SidebarRowHeightRaw = 32f;
internal const float SidebarPopOutHitWidthRaw = 22f;
internal const float SidebarGreetedHitWidthRaw = 22f;
internal const float SidebarHitSlackRaw = 4f;
internal const float SidebarMinDrawWidthRaw = 2f;
internal const float SidebarUnreadRadiusRaw = 4f;
internal const float SidebarGlyphInsetRaw = 4f;
// --- Input bar ---
internal const float InputBarHeightRaw = 32f;
// Two ghost buttons since v1.14.0 -- symbols and the more-menu. Everything
// else moved into the menu, and the hundred-odd pixels went back to the
// input field.
internal const float InputQuickButtonsReserveRaw = 62f;
// --- Honorific header ---
internal const float HonorificHeightRaw = 30f;
internal const float HonorificInsetRaw = 8f;
internal const float HonorificBracketGapRaw = 6f;
// --- Top tab bar ---
internal const float TopTabUnreadInsetRaw = 4f;
internal const float TopTabPaddingXRaw = 10f;
internal const float TopTabUnderlineRaw = 2f;
// --- Status bar ---
internal const float StatusBorderThicknessRaw = 1f;
internal const float StatusTopSpacerRaw = 2f;
// --- Message list ---
internal const float MessageDummyWidthRaw = 10f;
private static float _cachedScale = 1f;
private static int _cachedFrame = -1;
// GlobalScale resolves to ImGui.GetIO().FontGlobalScale, which the Dalamud
// settings slider moves on every frame while it is dragged. Pinning it once
// per frame keeps a CalcSize and its matching Draw on the same value, and
// saves three native calls per access.
internal static float Scale
{
get
{
var frame = ImGui.GetFrameCount();
if (frame == _cachedFrame)
return _cachedScale;
// Safe variant: GlobalScale throws while the interface manager is
// still coming up, and Metrics reaches more call sites than it did.
_cachedScale = ImGuiHelpers.GlobalScaleSafe;
_cachedFrame = frame;
return _cachedScale;
}
}
internal static float SidebarIconOnlyWidth => MetricsMath.Scale(SidebarIconOnlyWidthRaw, Scale);
internal static float SidebarRowHeight => MetricsMath.Scale(SidebarRowHeightRaw, Scale);
internal static float SidebarPopOutHitWidth =>
MetricsMath.Scale(SidebarPopOutHitWidthRaw, Scale);
internal static float SidebarGreetedHitWidth =>
MetricsMath.Scale(SidebarGreetedHitWidthRaw, Scale);
internal static float SidebarHitSlack => MetricsMath.Scale(SidebarHitSlackRaw, Scale);
internal static float SidebarMinDrawWidth => MetricsMath.Scale(SidebarMinDrawWidthRaw, Scale);
internal static float SidebarUnreadRadius => MetricsMath.Scale(SidebarUnreadRadiusRaw, Scale);
internal static float SidebarGlyphInset => MetricsMath.Scale(SidebarGlyphInsetRaw, Scale);
internal static float InputBarHeight => MetricsMath.Scale(InputBarHeightRaw, Scale);
internal static float InputQuickButtonsReserve =>
MetricsMath.Scale(InputQuickButtonsReserveRaw, Scale);
internal static float HonorificHeight => MetricsMath.Scale(HonorificHeightRaw, Scale);
internal static float HonorificInset => MetricsMath.Scale(HonorificInsetRaw, Scale);
internal static float HonorificBracketGap => MetricsMath.Scale(HonorificBracketGapRaw, Scale);
internal static float TopTabUnreadInset => MetricsMath.Scale(TopTabUnreadInsetRaw, Scale);
internal static float TopTabPaddingX => MetricsMath.Scale(TopTabPaddingXRaw, Scale);
internal static float TopTabUnderline => MetricsMath.Scale(TopTabUnderlineRaw, Scale);
// Measured, not scaled: the tab has to fit the text, and the font comes from
// Config.FontSizeV2 which display scaling does not feed into.
internal static float TopTabHeight => ImGui.GetTextLineHeight() + MathF.Round(10f * Scale);
internal static float StatusBorderThickness =>
MetricsMath.Scale(StatusBorderThicknessRaw, Scale);
internal static float StatusTopSpacer => MathF.Round(StatusTopSpacerRaw * Scale);
internal static float MessageDummyWidth => MetricsMath.Scale(MessageDummyWidthRaw, Scale);
// Text-dependent heights are measured, never scaled: the font is built from
// Config.FontSizeV2, which GlobalScale does not feed into. StatusBar.Height
// has done it this way since 1.8.x.
internal static float CenterY(float rowHeight) =>
MetricsMath.CenterY(rowHeight, ImGui.GetTextLineHeight());
}