using System;
using System.Collections.Generic;
namespace AcDream.App.UI.Layout;
///
/// Shared text shaping for retail indicator detail pages. Retail
/// UIElement_Text::SetText reflows newline-delimited strings into the
/// authored field width; acdream's retained text seam carries already-shaped
/// lines, so controllers perform the equivalent shaping before publication.
///
internal static class IndicatorDetailText
{
public static IReadOnlyList Shape(UiText target, string text)
{
ArgumentNullException.ThrowIfNull(target);
text ??= string.Empty;
float maxWidth = Math.Max(1f, target.Width - (2f * target.Padding));
float Measure(string value)
=> target.DatFont?.MeasureWidth(value)
?? target.Font?.MeasureWidth(value)
?? value.Length * 8f;
var lines = new List();
string normalized = text.Replace("\\n", "\n", StringComparison.Ordinal);
foreach (string paragraph in normalized.Split('\n'))
{
if (paragraph.Length == 0)
{
lines.Add(new UiText.Line(string.Empty, target.DefaultColor));
continue;
}
foreach (string line in ChatWindowController.WrapText(paragraph, maxWidth, Measure))
lines.Add(new UiText.Line(line, target.DefaultColor));
}
return lines;
}
}