feat: Adds size/style support to gump builders, optimizes EscapeHtml (#2257)

> [!IMPORTANT]
> **Developer Note**
> THIS IS A BREAKING CHANGE TO THE NEW API GUMP.
> Please give us feedback in [discord ](https://muo.gg/discord) if you have issues, need help, or have ideas for a better API change!

### Summary

* Adds support for size/style to dynamic/static builder.
* Drastically simplifies the dynamic/static builder api for AddHtml.
* Cleans up some legacy gump files.
This commit is contained in:
Kamron Batman 2025-11-23 11:35:31 -08:00 • committed by GitHub
parent ea86d5b2a6
commit 7bd5a853a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 398 additions and 635 deletions

View file

@ -66,78 +66,46 @@ public ref struct GumpStringsBuilder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetHtmlText(
ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler, int color, int size = -1,
byte fontStyle = 0
ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler, ReadOnlySpan<char> color = default, int size = -1,
byte fontStyle = 0, TextAlignment align = TextAlignment.Left
)
{
SetHtmlText(ref slotKeyHandler, handler.Text, color, size, fontStyle);
SetHtmlText(slotKeyHandler.Text, handler.Text, color, size, fontStyle, align);
slotKeyHandler.Clear();
handler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetHtmlText(
ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan<char> value, int color, int size = -1, byte fontStyle = 0
ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan<char> value, ReadOnlySpan<char> color = default, int size = -1, byte fontStyle = 0,
TextAlignment align = TextAlignment.Left
)
{
SetHtmlText(slotKeyHandler.Text, value, color, size, fontStyle);
SetHtmlText(slotKeyHandler.Text, value, color, size, fontStyle, align);
slotKeyHandler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetHtmlText(
ReadOnlySpan<char> slotKey, ref RawInterpolatedStringHandler handler, int color, int size = -1, byte fontStyle = 0
ReadOnlySpan<char> slotKey, ref RawInterpolatedStringHandler handler, ReadOnlySpan<char> color = default, int size = -1, byte fontStyle = 0,
TextAlignment align = TextAlignment.Left
)
{
SetHtmlText(slotKey, handler.Text, color, size, fontStyle);
SetHtmlText(slotKey, handler.Text, color, size, fontStyle, align);
handler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetHtmlText(
ReadOnlySpan<char> slotKey, ReadOnlySpan<char> value, int color, int size = -1, byte fontStyle = 0
ReadOnlySpan<char> slotKey, ReadOnlySpan<char> value, ReadOnlySpan<char> color = default, int size = -1, byte fontStyle = 0,
TextAlignment align = TextAlignment.Left
)
{
var coloredTextHandler = value.Color(color, size, fontStyle);
SetStringSlot(slotKey, ref coloredTextHandler);
}
var arr = STArrayPool<char>.Shared.Rent(Html.BuildCharCount(value, color));
var bytesWritten = Html.Build(value, arr.AsSpan(), color, size, fontStyle, align);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetHtmlTextCentered(
ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler, int color = -1,
int size = -1, byte fontStyle = 0
)
{
SetHtmlTextCentered(ref slotKeyHandler, handler.Text, color, size, fontStyle);
handler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetHtmlTextCentered(
ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan<char> value, int color = -1, int size = -1,
byte fontStyle = 0
)
{
SetHtmlTextCentered(slotKeyHandler.Text, value, color, size, fontStyle);
slotKeyHandler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetHtmlTextCentered(
ReadOnlySpan<char> slotKey, ref RawInterpolatedStringHandler handler, int color = -1, int size = -1,
byte fontStyle = 0
)
{
SetHtmlTextCentered(slotKey, handler.Text, color, size, fontStyle);
handler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetHtmlTextCentered(
ReadOnlySpan<char> slotKey, ReadOnlySpan<char> value, int color = -1, int size = -1, byte fontStyle = 0
)
{
var coloredTextHandler = value.Center(color, size, fontStyle);
SetStringSlot(slotKey, ref coloredTextHandler);
SetStringSlot(slotKey, arr.AsSpan(0, bytesWritten));
STArrayPool<char>.Shared.Return(arr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]