35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
using PlotLine.Models;
|
|
|
|
namespace PlotLine.ViewModels;
|
|
|
|
public static class CharacterCardLayout
|
|
{
|
|
// Tune here: names use a larger heading font; description whitespace collapses
|
|
// in HTML. Avatars, age badges and actions are bounded, so do not affect span.
|
|
public const int TwoColumnThreshold = 300;
|
|
public const int ThreeColumnThreshold = 650;
|
|
|
|
public static int ColumnSpan(Character character)
|
|
{
|
|
var score = DisplayedLength(character.DefaultDescription) + 2 * DisplayedLength(character.CharacterName);
|
|
return score >= ThreeColumnThreshold ? 3 : score >= TwoColumnThreshold ? 2 : 1;
|
|
}
|
|
|
|
private static int DisplayedLength(string? text)
|
|
{
|
|
var length = 0;
|
|
var pendingSpace = false;
|
|
foreach (var character in text ?? string.Empty)
|
|
{
|
|
if (char.IsWhiteSpace(character))
|
|
{
|
|
pendingSpace = length > 0;
|
|
continue;
|
|
}
|
|
length += pendingSpace ? 2 : 1;
|
|
pendingSpace = false;
|
|
}
|
|
return length;
|
|
}
|
|
}
|