From 234fe5d3606a9506a7abeaa51e44470769c18df9 Mon Sep 17 00:00:00 2001 From: cake Date: Fri, 19 Dec 2025 19:20:41 +0100 Subject: [PATCH] Fixed font size issue on player names. --- LightlessSync/UI/Handlers/IdDisplayHandler.cs | 3 +- LightlessSync/Utils/SeStringUtils.cs | 80 ++++++++++++++++--- 2 files changed, 71 insertions(+), 12 deletions(-) diff --git a/LightlessSync/UI/Handlers/IdDisplayHandler.cs b/LightlessSync/UI/Handlers/IdDisplayHandler.cs index b31b145..74a6571 100644 --- a/LightlessSync/UI/Handlers/IdDisplayHandler.cs +++ b/LightlessSync/UI/Handlers/IdDisplayHandler.cs @@ -122,6 +122,7 @@ public class IdDisplayHandler if (!string.Equals(_editEntry, pair.UserData.UID, StringComparison.Ordinal)) { + var targetFontSize = ImGui.GetFontSize(); var font = textIsUid ? UiBuilder.MonoFont : ImGui.GetFont(); var rowWidth = MathF.Max(editBoxWidth.Invoke(), 0f); float rowRightLimit = 0f; @@ -183,7 +184,7 @@ public class IdDisplayHandler } } - SeStringUtils.RenderSeStringWithHitbox(seString, rowStart, font, pair.UserData.UID); + SeStringUtils.RenderSeStringWithHitbox(seString, rowStart, targetFontSize, font, pair.UserData.UID); nameRectMin = ImGui.GetItemRectMin(); nameRectMax = ImGui.GetItemRectMax(); diff --git a/LightlessSync/Utils/SeStringUtils.cs b/LightlessSync/Utils/SeStringUtils.cs index 810cbe7..2188d91 100644 --- a/LightlessSync/Utils/SeStringUtils.cs +++ b/LightlessSync/Utils/SeStringUtils.cs @@ -559,17 +559,11 @@ public static class SeStringUtils ImGui.Dummy(new Vector2(0f, textSize.Y)); } + public static Vector2 RenderSeStringWithHitbox(DalamudSeString seString, Vector2 position, ImFontPtr? font = null, string? id = null) { var drawList = ImGui.GetWindowDrawList(); var usedFont = font ?? UiBuilder.MonoFont; - var drawParams = new SeStringDrawParams - { - Font = usedFont, - Color = 0xFFFFFFFF, - WrapWidth = float.MaxValue, - TargetDrawList = drawList - }; var textSize = ImGui.CalcTextSize(seString.TextValue); if (textSize.Y <= 0f) @@ -584,11 +578,17 @@ public static class SeStringUtils var verticalOffset = MathF.Max((hitboxHeight - textSize.Y) * 0.5f, 0f); var drawPos = new Vector2(position.X, position.Y + verticalOffset); - ImGui.SetCursorScreenPos(drawPos); + var drawParams = new SeStringDrawParams + { + FontSize = usedFont.FontSize, + ScreenOffset = drawPos, + Font = usedFont, + Color = 0xFFFFFFFF, + WrapWidth = float.MaxValue, + TargetDrawList = drawList + }; - drawParams.ScreenOffset = drawPos; - drawParams.Font = usedFont; - drawParams.FontSize = usedFont.FontSize; + ImGui.SetCursorScreenPos(drawPos); ImGuiHelpers.SeStringWrapped(seString.Encode(), drawParams); @@ -614,6 +614,64 @@ public static class SeStringUtils return new Vector2(textSize.X, hitboxHeight); } + public static Vector2 RenderSeStringWithHitbox(DalamudSeString seString, Vector2 position, float? targetFontSize, ImFontPtr? font = null, string? id = null) + { + var drawList = ImGui.GetWindowDrawList(); + var usedFont = font ?? ImGui.GetFont(); + + ImGui.PushFont(usedFont); + Vector2 rawSize; + float usedEffectiveSize; + try + { + usedEffectiveSize = ImGui.GetFontSize(); + rawSize = ImGui.CalcTextSize(seString.TextValue); + } + finally + { + ImGui.PopFont(); + } + + var desiredSize = targetFontSize ?? usedEffectiveSize; + var scale = usedEffectiveSize > 0 ? (desiredSize / usedEffectiveSize) : 1f; + + var textSize = rawSize * scale; + + var style = ImGui.GetStyle(); + var frameHeight = desiredSize + style.FramePadding.Y * 2f; + var hitboxHeight = MathF.Max(frameHeight, textSize.Y); + var verticalOffset = MathF.Max((hitboxHeight - textSize.Y) * 0.5f, 0f); + + var drawPos = new Vector2(position.X, position.Y + verticalOffset); + + var drawParams = new SeStringDrawParams + { + TargetDrawList = drawList, + ScreenOffset = drawPos, + Font = usedFont, + FontSize = desiredSize, + Color = 0xFFFFFFFF, + WrapWidth = float.MaxValue, + }; + + ImGui.SetCursorScreenPos(drawPos); + ImGuiHelpers.SeStringWrapped(seString.Encode(), drawParams); + + ImGui.SetCursorScreenPos(position); + ImGui.PushID(id ?? Interlocked.Increment(ref _seStringHitboxCounter).ToString()); + + try + { + ImGui.InvisibleButton("##hitbox", new Vector2(textSize.X, hitboxHeight)); + } + finally + { + ImGui.PopID(); + } + + return new Vector2(textSize.X, hitboxHeight); + } + public static Vector2 RenderIconWithHitbox(int iconId, Vector2 position, ImFontPtr? font = null, string? id = null) { var drawList = ImGui.GetWindowDrawList();