Fixed font size issue on player names.
This commit is contained in:
@@ -122,6 +122,7 @@ public class IdDisplayHandler
|
|||||||
|
|
||||||
if (!string.Equals(_editEntry, pair.UserData.UID, StringComparison.Ordinal))
|
if (!string.Equals(_editEntry, pair.UserData.UID, StringComparison.Ordinal))
|
||||||
{
|
{
|
||||||
|
var targetFontSize = ImGui.GetFontSize();
|
||||||
var font = textIsUid ? UiBuilder.MonoFont : ImGui.GetFont();
|
var font = textIsUid ? UiBuilder.MonoFont : ImGui.GetFont();
|
||||||
var rowWidth = MathF.Max(editBoxWidth.Invoke(), 0f);
|
var rowWidth = MathF.Max(editBoxWidth.Invoke(), 0f);
|
||||||
float rowRightLimit = 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();
|
nameRectMin = ImGui.GetItemRectMin();
|
||||||
nameRectMax = ImGui.GetItemRectMax();
|
nameRectMax = ImGui.GetItemRectMax();
|
||||||
|
|
||||||
|
|||||||
@@ -559,17 +559,11 @@ public static class SeStringUtils
|
|||||||
|
|
||||||
ImGui.Dummy(new Vector2(0f, textSize.Y));
|
ImGui.Dummy(new Vector2(0f, textSize.Y));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector2 RenderSeStringWithHitbox(DalamudSeString seString, Vector2 position, ImFontPtr? font = null, string? id = null)
|
public static Vector2 RenderSeStringWithHitbox(DalamudSeString seString, Vector2 position, ImFontPtr? font = null, string? id = null)
|
||||||
{
|
{
|
||||||
var drawList = ImGui.GetWindowDrawList();
|
var drawList = ImGui.GetWindowDrawList();
|
||||||
var usedFont = font ?? UiBuilder.MonoFont;
|
var usedFont = font ?? UiBuilder.MonoFont;
|
||||||
var drawParams = new SeStringDrawParams
|
|
||||||
{
|
|
||||||
Font = usedFont,
|
|
||||||
Color = 0xFFFFFFFF,
|
|
||||||
WrapWidth = float.MaxValue,
|
|
||||||
TargetDrawList = drawList
|
|
||||||
};
|
|
||||||
|
|
||||||
var textSize = ImGui.CalcTextSize(seString.TextValue);
|
var textSize = ImGui.CalcTextSize(seString.TextValue);
|
||||||
if (textSize.Y <= 0f)
|
if (textSize.Y <= 0f)
|
||||||
@@ -584,11 +578,17 @@ public static class SeStringUtils
|
|||||||
var verticalOffset = MathF.Max((hitboxHeight - textSize.Y) * 0.5f, 0f);
|
var verticalOffset = MathF.Max((hitboxHeight - textSize.Y) * 0.5f, 0f);
|
||||||
|
|
||||||
var drawPos = new Vector2(position.X, position.Y + verticalOffset);
|
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;
|
ImGui.SetCursorScreenPos(drawPos);
|
||||||
drawParams.Font = usedFont;
|
|
||||||
drawParams.FontSize = usedFont.FontSize;
|
|
||||||
|
|
||||||
ImGuiHelpers.SeStringWrapped(seString.Encode(), drawParams);
|
ImGuiHelpers.SeStringWrapped(seString.Encode(), drawParams);
|
||||||
|
|
||||||
@@ -614,6 +614,64 @@ public static class SeStringUtils
|
|||||||
return new Vector2(textSize.X, hitboxHeight);
|
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)
|
public static Vector2 RenderIconWithHitbox(int iconId, Vector2 position, ImFontPtr? font = null, string? id = null)
|
||||||
{
|
{
|
||||||
var drawList = ImGui.GetWindowDrawList();
|
var drawList = ImGui.GetWindowDrawList();
|
||||||
|
|||||||
Reference in New Issue
Block a user