From 43732684b31f1dea57a39e4b9937e5ad75dbba82 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Sun, 14 Jun 2026 19:01:52 +0200 Subject: [PATCH] Add FontSize property to Text element and render with DrawStringHeight --- Processes/TerminalProcess.cs | 1 + UI/GUI/Rendering/CanvasRenderSource.cs | 16 ++++++++++------ UI/GUI/UIEelements/Shapes/Text.cs | 6 ++++++ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Processes/TerminalProcess.cs b/Processes/TerminalProcess.cs index 20640ff..0e5bb42 100644 --- a/Processes/TerminalProcess.cs +++ b/Processes/TerminalProcess.cs @@ -170,6 +170,7 @@ public class TerminalProcess() : Process("Terminal") { t.Color = Color.LightGreen; t.Content = ""; + t.FontSize = LineHeight; }); textLines.Add(textElement); } diff --git a/UI/GUI/Rendering/CanvasRenderSource.cs b/UI/GUI/Rendering/CanvasRenderSource.cs index ebd8446..ed9ee13 100644 --- a/UI/GUI/Rendering/CanvasRenderSource.cs +++ b/UI/GUI/Rendering/CanvasRenderSource.cs @@ -1,6 +1,8 @@ using Cosmos.Kernel.System.Graphics; using Cosmos.Kernel.System.Graphics.Fonts; +using RemSox.Utils; + using System.Drawing; namespace RemSox.UI.GUI.Rendering; @@ -174,8 +176,8 @@ public sealed class CanvasRenderSource : IRenderSource canvas.DrawFilledRectangle(Color.FromArgb(32, 32, 32), 0, 0, size.Width, size.Height); canvas.DrawFilledRectangle(title, 0, 0, size.Width, 18); - canvas.DrawString(titleText, PCScreenFont.DefaultFont., Color.White, 4, 2); - canvas.DrawRectangle(border, 0, 0, size.Width, size.Height); + canvas.DrawStringHeight(titleText, PCScreenFont.DefaultFont, Color.White, 4, 2, 18); + canvas.DrawRectangle(border, 0, 0, size.Width, size.Height - 1); } private static void RenderCircle(Canvas canvas, RenderCommand command) @@ -206,10 +208,11 @@ public sealed class CanvasRenderSource : IRenderSource { Color color = Get(command.Properties, "Color", Color.White); string content = Get(command.Properties, "Content", string.Empty); + int fontSize = Get(command.Properties, "FontSize", 12); if (!string.IsNullOrEmpty(content)) { - canvas.DrawString(content, PCScreenFont.DefaultFont, color, command.Position.X, command.Position.Y); + canvas.DrawStringHeight(content, PCScreenFont.DefaultFont, color, command.Position.X, command.Position.Y, fontSize); } } @@ -235,7 +238,7 @@ public sealed class CanvasRenderSource : IRenderSource { int tx = command.Position.X + (size.Width / 2) - (text.Length * 4); int ty = command.Position.Y + (size.Height / 2) - 8; - canvas.DrawString(text, PCScreenFont.DefaultFont, fg, tx, ty); + canvas.DrawStringHeight(text, PCScreenFont.DefaultFont, fg, tx, ty, size.Height - 8); } } @@ -245,8 +248,9 @@ public sealed class CanvasRenderSource : IRenderSource Color fg = Get(command.Properties, "TextColor", Color.White); bool isChecked = Get(command.Properties, "IsChecked", false); string text = Get(command.Properties, "Text", string.Empty); + Size size = Get(command.Properties, "Size", new Size(12, 12)); - const int boxSize = 12; + int boxSize = size.Height; canvas.DrawFilledRectangle(bg, command.Position.X, command.Position.Y, boxSize, boxSize); canvas.DrawRectangle(Color.DarkGray, command.Position.X, command.Position.Y, boxSize, boxSize); @@ -258,7 +262,7 @@ public sealed class CanvasRenderSource : IRenderSource if (!string.IsNullOrEmpty(text)) { - canvas.DrawString(text, PCScreenFont.DefaultFont, fg, command.Position.X + boxSize + 5, command.Position.Y - 2); + canvas.DrawStringHeight(text, PCScreenFont.DefaultFont, fg, command.Position.X + boxSize + 5, command.Position.Y - 2, boxSize); } } } \ No newline at end of file diff --git a/UI/GUI/UIEelements/Shapes/Text.cs b/UI/GUI/UIEelements/Shapes/Text.cs index 9c87ca6..083f8e0 100644 --- a/UI/GUI/UIEelements/Shapes/Text.cs +++ b/UI/GUI/UIEelements/Shapes/Text.cs @@ -15,4 +15,10 @@ public class Text() : UIElement("Text") get; set => SetProperty(nameof(Color), ref field, value); } = Color.White; + + public int FontSize + { + get; + set => SetProperty(nameof(FontSize), ref field, value); + } = 12; }