mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-01 09:37:03 +02:00
* [Dependency] source generator No more reflection, no more codegen at runtime Also various changes to Roslyn helpers to make this easier to write. Requires all types with dependencies to be partial and not have readonly dependency fields. An analyzer enforces this at warning level, the previous injection strategies have remained in the code *for now* as a fallback. No fallback is available for [field: Dependency] properties, due to a Roslyn bug. Code Fixes exist. We love Roslyn * Apply dependencies generator changes to all code * Release notes * Preprocessor got hands * Handle nullable dependencies These are bad but gotta deal with it. * Apply suggestions from code review Co-authored-by: Moony <moony@hellomouse.net> * Fine, let's not use collection expressions --------- Co-authored-by: Moony <moony@hellomouse.net>
99 lines
3.2 KiB
C#
99 lines
3.2 KiB
C#
using System.Linq;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Robust.Client.Graphics.FontManagement;
|
|
|
|
[GenerateTypedNameReferences]
|
|
internal sealed partial class SystemFontDebugWindow : DefaultWindow
|
|
{
|
|
private static readonly int[] ExampleFontSizes = [8, 12, 16, 24, 36];
|
|
private const string ExampleString = "The quick brown fox jumps over the lazy dog";
|
|
|
|
[Dependency] private ISystemFontManager _systemFontManager = default!;
|
|
|
|
public SystemFontDebugWindow()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
RobustXamlLoader.Load(this);
|
|
|
|
var buttonGroup = new ButtonGroup();
|
|
|
|
foreach (var group in _systemFontManager.SystemFontFaces.GroupBy(k => k.FamilyName).OrderBy(k => k.Key))
|
|
{
|
|
var fonts = group.ToArray();
|
|
SelectorContainer.AddChild(new Selector(this, buttonGroup, group.Key, fonts));
|
|
}
|
|
}
|
|
|
|
private void SelectFontFamily(ISystemFontFace[] fonts)
|
|
{
|
|
FamilyLabel.Text = fonts[0].FamilyName;
|
|
|
|
FaceContainer.RemoveAllChildren();
|
|
|
|
foreach (var font in fonts)
|
|
{
|
|
var exampleContainer = new BoxContainer
|
|
{
|
|
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
|
Margin = new Thickness(8)
|
|
};
|
|
|
|
foreach (var size in ExampleFontSizes)
|
|
{
|
|
var fontInstance = font.Load(size);
|
|
|
|
var richTextLabel = new RichTextLabel
|
|
{
|
|
Stylesheet = new Stylesheet([
|
|
StylesheetHelpers.Element<RichTextLabel>().Prop("font", fontInstance)
|
|
]),
|
|
};
|
|
richTextLabel.SetMessage(FormattedMessage.FromUnformatted(ExampleString));
|
|
exampleContainer.AddChild(richTextLabel);
|
|
}
|
|
|
|
FaceContainer.AddChild(new BoxContainer
|
|
{
|
|
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
|
Children =
|
|
{
|
|
new RichTextLabel
|
|
{
|
|
Text = $"""
|
|
{font.FullName}
|
|
Family: "{font.FamilyName}", face: "{font.FaceName}", PostScript = "{font.PostscriptName}"
|
|
Weight: {font.Weight} ({(int) font.Weight}), slant: {font.Slant} ({(int) font.Slant}), width: {font.Width} ({(int) font.Width})
|
|
""",
|
|
},
|
|
exampleContainer
|
|
},
|
|
Margin = new Thickness(0, 0, 0, 8)
|
|
});
|
|
}
|
|
}
|
|
|
|
private sealed class Selector : Control
|
|
{
|
|
public Selector(SystemFontDebugWindow window, ButtonGroup group, string family, ISystemFontFace[] fonts)
|
|
{
|
|
var button = new Button
|
|
{
|
|
Text = family,
|
|
Group = group,
|
|
ToggleMode = true
|
|
};
|
|
AddChild(button);
|
|
|
|
button.OnPressed += _ => window.SelectFontFamily(fonts);
|
|
}
|
|
}
|
|
}
|