From 1355fa06b87809dbfc42eefdfd374031c2b0e9e2 Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Mon, 15 Jun 2026 02:10:20 +0200 Subject: [PATCH] Increase UI element sizes and add maxWidth support to DrawString methods --- Processes/DesktopProcess.cs | 4 ++-- UI/GUI/Rendering/CanvasRenderSource.cs | 4 ++-- Utils/CanvasExtensions.cs | 18 +++++++++++++++--- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Processes/DesktopProcess.cs b/Processes/DesktopProcess.cs index 38bc20f..f53e5b5 100644 --- a/Processes/DesktopProcess.cs +++ b/Processes/DesktopProcess.cs @@ -27,7 +27,7 @@ internal class DesktopProcess() : Process("Desktop Manager") Button button = testWindow.CreateUIElement(b => { b.Position = new System.Drawing.Point(20, 30); - b.Size = new System.Drawing.Size(100, 30); + b.Size = new System.Drawing.Size(200, 30); b.Text = "Click Me"; b.BackgroundColor = System.Drawing.Color.LightBlue; }); @@ -41,7 +41,7 @@ internal class DesktopProcess() : Process("Desktop Manager") CheckBox check = testWindow.CreateUIElement(c => { c.Position = new System.Drawing.Point(20, 80); - c.Size = new System.Drawing.Size(100, 30); + c.Size = new System.Drawing.Size(200, 30); c.Text = "Check Me"; c.IsChecked = true; }); diff --git a/UI/GUI/Rendering/CanvasRenderSource.cs b/UI/GUI/Rendering/CanvasRenderSource.cs index ed9ee13..a50a7c8 100644 --- a/UI/GUI/Rendering/CanvasRenderSource.cs +++ b/UI/GUI/Rendering/CanvasRenderSource.cs @@ -238,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.DrawStringHeight(text, PCScreenFont.DefaultFont, fg, tx, ty, size.Height - 8); + canvas.DrawStringHeight(text, PCScreenFont.DefaultFont, fg, tx, ty, size.Height - 8, size.Width); } } @@ -262,7 +262,7 @@ public sealed class CanvasRenderSource : IRenderSource if (!string.IsNullOrEmpty(text)) { - canvas.DrawStringHeight(text, PCScreenFont.DefaultFont, fg, command.Position.X + boxSize + 5, command.Position.Y - 2, boxSize); + canvas.DrawStringHeight(text, PCScreenFont.DefaultFont, fg, command.Position.X + boxSize + 5, command.Position.Y - 2, boxSize, size.Width); } } } \ No newline at end of file diff --git a/Utils/CanvasExtensions.cs b/Utils/CanvasExtensions.cs index d0503f7..b6500a2 100644 --- a/Utils/CanvasExtensions.cs +++ b/Utils/CanvasExtensions.cs @@ -7,15 +7,22 @@ namespace RemSox.Utils; public static class CanvasExtensions { - public static void DrawStringScale(this Canvas canvas, string str, Font font, Color color, int x, int y, int scale) + public static void DrawStringScale(this Canvas canvas, string str, Font font, Color color, int x, int y, int scale, int maxWidth = int.MaxValue) { int len = str.Length; byte width = font.Width; + int targetWidth = width * scale; + for (int i = 0; i < len; i++) { + if (x + targetWidth > maxWidth) + { + break; + } + canvas.DrawCharScale(str[i], font, color, x, y, scale); - x += width * scale; + x += targetWidth; } } @@ -57,7 +64,7 @@ public static class CanvasExtensions } } - public static void DrawStringHeight(this Canvas canvas, string str, Font font, Color color, int x, int y, int targetHeight) + public static void DrawStringHeight(this Canvas canvas, string str, Font font, Color color, int x, int y, int targetHeight, int maxWidth = int.MaxValue) { byte width = font.Width; byte height = font.Height; @@ -66,6 +73,11 @@ public static class CanvasExtensions for (int i = 0; i < str.Length; i++) { + if (x + targetWidth > maxWidth) + { + break; + } + canvas.DrawCharHeight(str[i], font, color, x, y, targetHeight); x += targetWidth; }