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

@ -91,13 +91,7 @@ public ref struct StaticGumpBuilder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtmlPlaceholder(
int x,
int y,
int width,
int height,
ReadOnlySpan<char> slotKey,
bool background = false,
bool scrollbar = false
int x, int y, int width, int height, ReadOnlySpan<char> slotKey, bool background = false, bool scrollbar = false
)
{
var index = _gumpBuilder.AddHtmlPlaceholder(x, y, width, height, background, scrollbar);
@ -106,12 +100,7 @@ public ref struct StaticGumpBuilder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtmlPlaceholder(
int x,
int y,
int width,
int height,
ref RawInterpolatedStringHandler handler,
bool background = false,
int x, int y, int width, int height, ref RawInterpolatedStringHandler handler, bool background = false,
bool scrollbar = false
)
{
@ -121,115 +110,33 @@ public ref struct StaticGumpBuilder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtml(
int x,
int y,
int width,
int height,
ReadOnlySpan<char> text,
bool background = false,
bool scrollbar = false
int x, int y, int width, int height, ReadOnlySpan<char> text, ReadOnlySpan<char> color = default, int size = -1, byte fontStyle = 0,
TextAlignment align = TextAlignment.Left, bool background = false, bool scrollbar = false
)
{
WriteInternalizedString(text);
if (color.Length > 0 || size != -1 || fontStyle != 0 || align != TextAlignment.Left)
{
var arr = STArrayPool<char>.Shared.Rent(Html.BuildCharCount(text, color));
var bytesWritten = Html.Build(text, arr.AsSpan(), color, size, fontStyle, align);
WriteInternalizedString(arr.AsSpan(0, bytesWritten));
STArrayPool<char>.Shared.Return(arr);
}
else
{
WriteInternalizedString(text);
}
_gumpBuilder.AddHtml(x, y, width, height, _stringsCount++, background, scrollbar);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtml(
int x, int y, int width, int height, ref RawInterpolatedStringHandler handler,
bool background = false, bool scrollbar = false
int x, int y, int width, int height, ref RawInterpolatedStringHandler handler, ReadOnlySpan<char> color = default, int size = -1,
byte fontStyle = 0, TextAlignment align = TextAlignment.Left, bool background = false, bool scrollbar = false
)
{
AddHtml(x, y, width, height, handler.Text, background, scrollbar);
handler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtml(
int x,
int y,
int width,
int height,
int color,
ReadOnlySpan<char> text,
bool background = false,
bool scrollbar = false
)
{
var handler = text.Color(color);
AddHtml(x, y, width, height, ref handler, background, scrollbar);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtml(
int x,
int y,
int width,
int height,
int color,
ref RawInterpolatedStringHandler handler,
bool background = false,
bool scrollbar = false
)
{
AddHtml(x, y, width, height, color, handler.Text, background, scrollbar);
handler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtmlCentered(
int x, int y, int width, int height, ReadOnlySpan<char> text, bool background = false, bool scrollbar = false
)
{
var handler = text.Center();
AddHtml(x, y, width, height, ref handler, background, scrollbar);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtmlCentered(
int x,
int y,
int width,
int height,
ref RawInterpolatedStringHandler handler,
bool background = false,
bool scrollbar = false
)
{
var centerHandler = handler.Text.Center();
AddHtml(x, y, width, height, ref centerHandler, background, scrollbar);
handler.Clear();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtmlCentered(
int x,
int y,
int width,
int height,
int color,
ReadOnlySpan<char> text,
bool background = false,
bool scrollbar = false
)
{
var handler = text.Center(color);
AddHtml(x, y, width, height, ref handler, background, scrollbar);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtmlCentered(
int x,
int y,
int width,
int height,
int color,
ref RawInterpolatedStringHandler handler,
bool background = false,
bool scrollbar = false
)
{
AddHtmlCentered(x, y, width, height, color, handler.Text, background, scrollbar);
AddHtml(x, y, width, height, handler.Text, color, size, fontStyle, align, background, scrollbar);
handler.Clear();
}