]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Monospace Support for Rich Text (#33830)
authorSouthbridge <7013162+southbridge-fur@users.noreply.github.com>
Fri, 13 Dec 2024 14:24:34 +0000 (09:24 -0500)
committerGitHub <noreply@github.com>
Fri, 13 Dec 2024 14:24:34 +0000 (15:24 +0100)
* Initial Commit

* Moved all this to SS14 on it's own

* Added prototype validation

Content.Client/Paper/UI/PaperWindow.xaml.cs
Content.Client/UserInterface/RichText/MonoTag.cs [new file with mode: 0644]

index 3522aabc66a7da9e3d9bd619937e0b9c8db2157d..9086145f83fced41a17089613b585280c1f283a0 100644 (file)
@@ -9,6 +9,7 @@ using Robust.Client.UserInterface.Controls;
 using Robust.Client.UserInterface.XAML;
 using Robust.Shared.Utility;
 using Robust.Client.UserInterface.RichText;
+using Content.Client.UserInterface.RichText;
 using Robust.Shared.Input;
 
 namespace Content.Client.Paper.UI
@@ -43,7 +44,8 @@ namespace Content.Client.Paper.UI
             typeof(BulletTag),
             typeof(ColorTag),
             typeof(HeadingTag),
-            typeof(ItalicTag)
+            typeof(ItalicTag),
+            typeof(MonoTag)
         };
 
         public event Action<string>? OnSaved;
diff --git a/Content.Client/UserInterface/RichText/MonoTag.cs b/Content.Client/UserInterface/RichText/MonoTag.cs
new file mode 100644 (file)
index 0000000..aee41c3
--- /dev/null
@@ -0,0 +1,34 @@
+using System.Linq;
+using Robust.Client.ResourceManagement;
+using Robust.Client.UserInterface.RichText;
+using Robust.Shared.IoC;
+using Robust.Shared.Prototypes;
+using Robust.Shared.Utility;
+
+namespace Content.Client.UserInterface.RichText;
+
+/// <summary>
+/// Sets the font to a monospaced variant
+/// </summary>
+public sealed class MonoTag : IMarkupTag
+{
+    [ValidatePrototypeId<FontPrototype>] public const string MonoFont = "Monospace";
+
+    [Dependency] private readonly IResourceCache _resourceCache = default!;
+    [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
+
+    public string Name => "mono";
+
+    /// <inheritdoc/>
+    public void PushDrawContext(MarkupNode node, MarkupDrawingContext context)
+    {
+        var font = FontTag.CreateFont(context.Font, node, _resourceCache, _prototypeManager, MonoFont);
+        context.Font.Push(font);
+    }
+
+    /// <inheritdoc/>
+    public void PopDrawContext(MarkupNode node, MarkupDrawingContext context)
+    {
+        context.Font.Pop();
+    }
+}