various 'improvements'
This commit is contained in:
@@ -565,19 +565,30 @@ public static class SeStringUtils
|
||||
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 = font ?? UiBuilder.MonoFont,
|
||||
Font = usedFont,
|
||||
Color = 0xFFFFFFFF,
|
||||
WrapWidth = float.MaxValue,
|
||||
TargetDrawList = drawList
|
||||
};
|
||||
|
||||
ImGui.SetCursorScreenPos(position);
|
||||
ImGuiHelpers.SeStringWrapped(seString.Encode(), drawParams);
|
||||
|
||||
var textSize = ImGui.CalcTextSize(seString.TextValue);
|
||||
if (textSize.Y <= 0f)
|
||||
{
|
||||
textSize.Y = usedFont.FontSize;
|
||||
}
|
||||
|
||||
var style = ImGui.GetStyle();
|
||||
var fontHeight = usedFont.FontSize > 0f ? usedFont.FontSize : ImGui.GetFontSize();
|
||||
var frameHeight = fontHeight + 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);
|
||||
ImGui.SetCursorScreenPos(drawPos);
|
||||
ImGuiHelpers.SeStringWrapped(seString.Encode(), drawParams);
|
||||
|
||||
ImGui.SetCursorScreenPos(position);
|
||||
if (id is not null)
|
||||
@@ -591,30 +602,52 @@ public static class SeStringUtils
|
||||
|
||||
try
|
||||
{
|
||||
ImGui.InvisibleButton("##hitbox", textSize);
|
||||
ImGui.InvisibleButton("##hitbox", new Vector2(textSize.X, hitboxHeight));
|
||||
}
|
||||
finally
|
||||
{
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
return textSize;
|
||||
return new Vector2(textSize.X, hitboxHeight);
|
||||
}
|
||||
|
||||
public static Vector2 RenderIconWithHitbox(int iconId, Vector2 position, ImFontPtr? font = null, string? id = null)
|
||||
{
|
||||
var drawList = ImGui.GetWindowDrawList();
|
||||
var usedFont = font ?? UiBuilder.MonoFont;
|
||||
var iconMacro = $"<icon({iconId})>";
|
||||
|
||||
var drawParams = new SeStringDrawParams
|
||||
var measureParams = new SeStringDrawParams
|
||||
{
|
||||
Font = font ?? UiBuilder.MonoFont,
|
||||
Font = usedFont,
|
||||
Color = 0xFFFFFFFF,
|
||||
WrapWidth = float.MaxValue,
|
||||
TargetDrawList = drawList
|
||||
WrapWidth = float.MaxValue
|
||||
};
|
||||
|
||||
var iconMacro = $"<icon({iconId})>";
|
||||
var drawResult = ImGuiHelpers.CompileSeStringWrapped(iconMacro, drawParams);
|
||||
var measureResult = ImGuiHelpers.CompileSeStringWrapped(iconMacro, measureParams);
|
||||
var iconSize = measureResult.Size;
|
||||
if (iconSize.Y <= 0f)
|
||||
{
|
||||
iconSize.Y = usedFont.FontSize > 0f ? usedFont.FontSize : ImGui.GetFontSize();
|
||||
}
|
||||
|
||||
var style = ImGui.GetStyle();
|
||||
var fontHeight = usedFont.FontSize > 0f ? usedFont.FontSize : ImGui.GetFontSize();
|
||||
var frameHeight = fontHeight + style.FramePadding.Y * 2f;
|
||||
var hitboxHeight = MathF.Max(frameHeight, iconSize.Y);
|
||||
var verticalOffset = MathF.Max((hitboxHeight - iconSize.Y) * 0.5f, 0f);
|
||||
|
||||
var drawPos = new Vector2(position.X, position.Y + verticalOffset);
|
||||
var drawParams = new SeStringDrawParams
|
||||
{
|
||||
Font = usedFont,
|
||||
Color = 0xFFFFFFFF,
|
||||
WrapWidth = float.MaxValue,
|
||||
TargetDrawList = drawList,
|
||||
ScreenOffset = drawPos
|
||||
};
|
||||
ImGuiHelpers.CompileSeStringWrapped(iconMacro, drawParams);
|
||||
|
||||
ImGui.SetCursorScreenPos(position);
|
||||
if (id is not null)
|
||||
@@ -628,14 +661,14 @@ public static class SeStringUtils
|
||||
|
||||
try
|
||||
{
|
||||
ImGui.InvisibleButton("##iconHitbox", drawResult.Size);
|
||||
ImGui.InvisibleButton("##iconHitbox", new Vector2(iconSize.X, hitboxHeight));
|
||||
}
|
||||
finally
|
||||
{
|
||||
ImGui.PopID();
|
||||
}
|
||||
|
||||
return drawResult.Size;
|
||||
return new Vector2(iconSize.X, hitboxHeight);
|
||||
}
|
||||
|
||||
#region Internal Payloads
|
||||
|
||||
Reference in New Issue
Block a user