Increase UI element sizes and add maxWidth support to DrawString methods

This commit is contained in:
Stone_Red
2026-06-15 02:10:20 +02:00
parent 43732684b3
commit 1355fa06b8
3 changed files with 19 additions and 7 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ internal class DesktopProcess() : Process("Desktop Manager")
Button button = testWindow.CreateUIElement<UI.GUI.UIEelements.Controls.Button>(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<UI.GUI.UIEelements.Controls.CheckBox>(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;
});
+2 -2
View File
@@ -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);
}
}
}
+15 -3
View File
@@ -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;
}