Code cleanup

This commit is contained in:
Stone_Red
2026-06-16 20:14:15 +02:00
parent f049a43dfd
commit 5265f2b574
7 changed files with 21 additions and 18 deletions
+3 -3
View File
@@ -58,7 +58,7 @@ internal class DesktopProcess() : Process("Desktop Manager")
startButton = taskbar.CreateUIElement<Button>(b =>
{
b.Position = new Point(2, 2);
b.Size = new Size(50, taskbarH - 4);
b.Size = new Size(65, taskbarH - 4);
b.Text = "Start";
b.BackgroundColor = Color.FromArgb(0, 100, 180);
b.TextColor = Color.White;
@@ -158,13 +158,13 @@ internal class DesktopProcess() : Process("Desktop Manager")
// Build lookup of existing tracked windows
Dictionary<int, Button> tracked = [];
foreach (var (winId, btn) in windowButtons)
foreach ((int winId, Button? btn) in windowButtons)
{
tracked[winId] = btn;
}
// Add new buttons and reposition everything in one pass
int btnX = 56;
int btnX = startButton.Size.Width + 6;
windowButtons.Clear();
foreach (Window win in allWindows)
{
+5 -5
View File
@@ -94,9 +94,9 @@ public sealed class CanvasRenderSource : IRenderSource
canvas.Clear(Color.Black);
if (windowPrimitives.TryGetValue(winId, out var primitives))
if (windowPrimitives.TryGetValue(winId, out List<(int ElementId, RenderCommand Command)>? primitives))
{
foreach (var (_, cmd) in primitives)
foreach ((int _, RenderCommand? cmd) in primitives)
{
DrawPrimitive(canvas, cmd);
}
@@ -191,7 +191,7 @@ public sealed class CanvasRenderSource : IRenderSource
private static void UpsertPrimitive(RenderCommand cmd)
{
if (!windowPrimitives.TryGetValue(cmd.WindowId, out var list))
if (!windowPrimitives.TryGetValue(cmd.WindowId, out List<(int ElementId, RenderCommand Command)>? list))
{
list = [];
windowPrimitives[cmd.WindowId] = list;
@@ -212,12 +212,12 @@ public sealed class CanvasRenderSource : IRenderSource
private static void RemovePrimitives(int windowId, int baseElementId)
{
if (!windowPrimitives.TryGetValue(windowId, out var list))
if (!windowPrimitives.TryGetValue(windowId, out List<(int ElementId, RenderCommand Command)>? list))
{
return;
}
list.RemoveAll(p => p.ElementId >= 0
_ = list.RemoveAll(p => p.ElementId >= 0
? (p.ElementId >> UIElement.PrimitiveIdShift) == baseElementId
: p.ElementId == baseElementId);
+9 -3
View File
@@ -168,8 +168,10 @@ public class RenderCommand
// --- Serialization helpers ---
private T GetProp<T>(string key, T fallback) =>
Properties.TryGetValue(key, out object? raw) && raw is T val ? val : fallback;
private T GetProp<T>(string key, T fallback)
{
return Properties.TryGetValue(key, out object? raw) && raw is T val ? val : fallback;
}
private static void WriteVarint(Stream s, int value)
{
@@ -209,7 +211,11 @@ public class RenderCommand
{
byte b = data[offset++];
result |= (uint)(b & 0x7F) << shift;
if ((b & 0x80) == 0) return (int)result;
if ((b & 0x80) == 0)
{
return (int)result;
}
shift += 7;
}
}
-2
View File
@@ -1,7 +1,5 @@
using RemSox.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.UI.GUI.UIEelements.Controls;
public class Panel() : Control("Panel")
-2
View File
@@ -1,7 +1,5 @@
using RemSox.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.UI.GUI.UIEelements.Shapes;
public class Circle() : Shape("Circle")
-2
View File
@@ -1,7 +1,5 @@
using RemSox.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.UI.GUI.UIEelements.Shapes;
public class Pixel() : Shape("Pixel")
+4 -1
View File
@@ -23,5 +23,8 @@ public abstract class UIElement(string type) : ChangedPropertiesTracker
public abstract IEnumerable<RenderCommand> ToPrimitives(int windowId);
/// <summary> Builds a stable primitive ID from element ID and sub-index. </summary>
protected int PrimitiveId(int subIndex) => (Id << PrimitiveIdShift) | subIndex;
protected int PrimitiveId(int subIndex)
{
return (Id << PrimitiveIdShift) | subIndex;
}
}