SeString renderer: fix colors, add link support (#1983)

* Add coloring options

* Add link support

* simplify

* fixes

* Prevent EncodeString from causing crashes

* Fix link range application and add link example

* Fix test widget

* Make DalamudLinkPayload backward compatible

* make it better to use

* make it better to use

* Mark SeString rendering functions experimental via comments

* rename

* Simplify

* Make sestring draw functions take in draw params

* Improvements
This commit is contained in:
srkizer 2024-08-02 02:36:11 +09:00 committed by GitHub
parent 5fdd88b488
commit b6eb18d550
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 2009 additions and 766 deletions

View file

@ -9,6 +9,9 @@ using System.Text.Unicode;
using Dalamud.Configuration.Internal;
using Dalamud.Game.ClientState.Keys;
using Dalamud.Game.Text.SeStringHandling.Payloads;
using Dalamud.Interface.ImGuiSeStringRenderer;
using Dalamud.Interface.ImGuiSeStringRenderer.Internal;
using Dalamud.Interface.ManagedFontAtlas;
using Dalamud.Interface.ManagedFontAtlas.Internals;
using Dalamud.Interface.Utility.Raii;
@ -16,10 +19,6 @@ using Dalamud.Interface.Utility.Raii;
using ImGuiNET;
using ImGuiScene;
using Lumina.Text.ReadOnly;
using SeStringRenderer = Dalamud.Interface.Internal.ImGuiSeStringRenderer.SeStringRenderer;
namespace Dalamud.Interface.Utility;
/// <summary>
@ -181,13 +180,57 @@ public static class ImGuiHelpers
if (ImGui.IsItemClicked()) ImGui.SetClipboardText($"{textCopy}");
}
/// <inheritdoc cref="SeStringRenderer.DrawWrapped(ReadOnlySeStringSpan, float)"/>
/// <summary>Draws a SeString.</summary>
/// <param name="sss">SeString to draw.</param>
/// <param name="wrapWidth">Wrapping width. If a non-positive number is provided, then the remainder of the width
/// will be used.</param>
/// <remarks>This function is experimental. Report any issues to GitHub issues or to Discord #dalamud-dev channel.
/// The function definition is stable; only in the next API version a function may be removed.</remarks>
public static void SeStringWrapped(ReadOnlySpan<byte> sss, float wrapWidth = 0) =>
Service<SeStringRenderer>.Get().DrawWrapped(sss, wrapWidth);
Service<SeStringRenderer>.Get().Draw(sss, new() { WrapWidth = wrapWidth > 0 ? wrapWidth : null });
/// <inheritdoc cref="SeStringRenderer.CompileAndDrawWrapped"/>
/// <summary>Creates and caches a SeString from a text macro representation, and then draws it.</summary>
/// <param name="text">SeString text macro representation.
/// Newline characters will be normalized to <see cref="NewLinePayload"/>.</param>
/// <param name="wrapWidth">Wrapping width. If a non-positive number is provided, then the remainder of the width
/// will be used.</param>
/// <remarks>This function is experimental. Report any issues to GitHub issues or to Discord #dalamud-dev channel.
/// The function definition is stable; only in the next API version a function may be removed.</remarks>
public static void CompileSeStringWrapped(string text, float wrapWidth = 0) =>
Service<SeStringRenderer>.Get().CompileAndDrawWrapped(text, wrapWidth);
Service<SeStringRenderer>.Get().CompileAndDrawWrapped(
text,
new() { WrapWidth = wrapWidth > 0 ? wrapWidth : null });
/// <summary>Draws a SeString.</summary>
/// <param name="sss">SeString to draw.</param>
/// <param name="style">Initial rendering style.</param>
/// <param name="imGuiId">ImGui ID, if link functionality is desired.</param>
/// <param name="buttonFlags">Button flags to use on link interaction.</param>
/// <returns>Interaction result of the rendered text.</returns>
/// <remarks>This function is experimental. Report any issues to GitHub issues or to Discord #dalamud-dev channel.
/// The function definition is stable; only in the next API version a function may be removed.</remarks>
public static SeStringDrawResult SeStringWrapped(
ReadOnlySpan<byte> sss,
in SeStringDrawParams style = default,
ImGuiId imGuiId = default,
ImGuiButtonFlags buttonFlags = ImGuiButtonFlags.MouseButtonDefault) =>
Service<SeStringRenderer>.Get().Draw(sss, style, imGuiId, buttonFlags);
/// <summary>Creates and caches a SeString from a text macro representation, and then draws it.</summary>
/// <param name="text">SeString text macro representation.
/// Newline characters will be normalized to <see cref="NewLinePayload"/>.</param>
/// <param name="style">Initial rendering style.</param>
/// <param name="imGuiId">ImGui ID, if link functionality is desired.</param>
/// <param name="buttonFlags">Button flags to use on link interaction.</param>
/// <returns>Interaction result of the rendered text.</returns>
/// <remarks>This function is experimental. Report any issues to GitHub issues or to Discord #dalamud-dev channel.
/// The function definition is stable; only in the next API version a function may be removed.</remarks>
public static SeStringDrawResult CompileSeStringWrapped(
string text,
in SeStringDrawParams style,
ImGuiId imGuiId = default,
ImGuiButtonFlags buttonFlags = ImGuiButtonFlags.MouseButtonDefault) =>
Service<SeStringRenderer>.Get().CompileAndDrawWrapped(text, style, imGuiId, buttonFlags);
/// <summary>
/// Write unformatted text wrapped.