using Content.Client.Stylesheets.Fonts;
using Robust.Client.ResourceManagement;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Reflection;
using Robust.Shared.Sandboxing;
using static Content.Client.Stylesheets.StylesheetHelpers;
namespace Content.Client.Stylesheets;
public abstract partial class BaseStylesheet : IStyleResources
{
[Dependency] protected readonly ISandboxHelper SandboxHelper = default!;
[Dependency] protected readonly IReflectionManager ReflectionManager = default!;
[Dependency] protected internal readonly IResourceCache ResCache = default!;
public Stylesheet Stylesheet { get; init; }
public abstract NotoFontFamilyStack BaseFont { get; }
///
/// Get the style rules for the given font stack, with the provided sizes.
/// Does not set the 'default' font, but does create rules for every combination of font kind and font size.
/// This is intended for font sizes you think will be common/generally useful, for less common usecases prefer specifying the font explicitly.
///
/// The prefix for the style classes, if any.
/// Font stack to use
/// A set of styleclasses and the associated size of font to use.
/// A rules list containing all combinations.
/// Use to get the appropriate styleclass for a font choice.
// god xmldoc refs are long ^^^
// lmao
protected StyleRule[] GetRulesForFont(string? prefix, NotoFontFamilyStack stack, List<(string?, int)> sizes) // TODO: NotoFontFamilyStack is temporary
{
var rules = new List();
foreach (var (name, size) in sizes)
{
foreach (var kind in stack.AvailableKinds)
{
var builder = E().Class(GetFontClass(kind, prefix));
if (name is not null)
builder.Class(name);
builder.Prop(Label.StylePropertyFont, stack.GetFont(size, kind));
rules.Add(builder);
}
}
return rules.ToArray();
}
///
/// Returns the appropriate styleclass for the given font configuration.
///
///
///
///
public static string GetFontClass(FontKind kind, string? prefix = null)
{
var kindStr = kind.ToString().ToLowerInvariant();
return prefix is null ? $"font-{kindStr}" : $"{prefix}-{kindStr}";
}
}