Reorganize project structure

This commit is contained in:
Stone_Red
2026-06-19 00:56:46 +02:00
parent 6f58eefb66
commit 95d88f1a8d
84 changed files with 267 additions and 186 deletions
@@ -0,0 +1,95 @@
using RemSox.Shared.UI;
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class Button() : Control("Button")
{
public event EventHandler? OnClick;
public string Text
{
get;
set => SetProperty(nameof(Text), ref field, value);
} = string.Empty;
public Color TextColor
{
get;
set => SetProperty(nameof(TextColor), ref field, value);
} = Color.Black;
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
// Background fill
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawFilledRect,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = BackgroundColor,
["Size"] = Size,
}
};
// Border
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(1),
Type = RenderCommandType.DrawRectBorder,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DarkGray,
["Size"] = Size,
}
};
// Text (centered, falls back to left-aligned if too wide)
if (!string.IsNullOrEmpty(Text))
{
int fontSize = Size.Height - 8;
int charWidth = 8 * fontSize / 14;
int maxChars = Size.Width / charWidth;
string display = Text;
if (display.Length > maxChars && maxChars > 0)
{
display = Text[..maxChars];
}
int textWidth = display.Length * charWidth;
int tx = textWidth >= Size.Width
? Position.X
: Position.X + ((Size.Width - textWidth) / 2);
int ty = Position.Y + (Size.Height / 2) - 8;
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(2),
Type = RenderCommandType.DrawText,
Position = new Point(tx, ty),
Properties = new Dictionary<string, object?>
{
["Color"] = TextColor,
["Content"] = Text,
["FontSize"] = Size.Height - 8,
["MaxWidth"] = Size.Width,
}
};
}
}
public override void HandleMouseEvent(MouseEvent mouseEvent)
{
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
{
OnClick?.Invoke(this, EventArgs.Empty);
}
}
}
@@ -0,0 +1,110 @@
using RemSox.Shared.UI;
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class CheckBox() : Control("CheckBox")
{
public event EventHandler? OnCheckedChanged;
public bool IsChecked
{
get;
set
{
SetProperty(nameof(IsChecked), ref field, value);
OnCheckedChanged?.Invoke(this, EventArgs.Empty);
}
} = false;
public string Text
{
get;
set => SetProperty(nameof(Text), ref field, value);
} = string.Empty;
public Color TextColor
{
get;
set => SetProperty(nameof(TextColor), ref field, value);
} = Color.White;
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
int boxSize = Size.Height;
// Checkbox box background
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawFilledRect,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = BackgroundColor,
["Size"] = new Size(boxSize, boxSize),
}
};
// Checkbox box border
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(1),
Type = RenderCommandType.DrawRectBorder,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DarkGray,
["Size"] = new Size(boxSize, boxSize),
}
};
// Check mark (filled inner rect)
if (IsChecked)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(2),
Type = RenderCommandType.DrawFilledRect,
Position = new Point(Position.X + 3, Position.Y + 3),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.Black,
["Size"] = new Size(boxSize - 6, boxSize - 6),
}
};
}
// Label text
if (!string.IsNullOrEmpty(Text))
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(3),
Type = RenderCommandType.DrawText,
Position = new Point(Position.X + boxSize + 5, Position.Y - 2),
Properties = new Dictionary<string, object?>
{
["Color"] = TextColor,
["Content"] = Text,
["FontSize"] = boxSize,
["MaxWidth"] = Size.Width - boxSize - 5,
}
};
}
}
public override void HandleMouseEvent(MouseEvent mouseEvent)
{
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
{
IsChecked = !IsChecked;
}
}
}
@@ -0,0 +1,22 @@
using RemSox.Shared.UI.GUI.Rendering;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class Panel() : Control("Panel")
{
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawFilledRect,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = BackgroundColor,
["Size"] = Size,
}
};
}
}
@@ -0,0 +1,70 @@
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class ProgressBar() : Control("ProgressBar")
{
public int Value
{
get;
set => SetProperty(nameof(Value), ref field, value);
}
public Color FillColor
{
get;
set => SetProperty(nameof(FillColor), ref field, value);
} = Color.Green;
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
// Background
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawFilledRect,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = BackgroundColor,
["Size"] = Size,
}
};
// Fill
int fillWidth = Size.Width * Math.Clamp(Value, 0, 100) / 100;
if (fillWidth > 0)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(1),
Type = RenderCommandType.DrawFilledRect,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = FillColor,
["Size"] = new Size(fillWidth, Size.Height),
}
};
}
// Border
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(2),
Type = RenderCommandType.DrawRectBorder,
Position = Position,
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DarkGray,
["Size"] = Size,
}
};
}
}
@@ -0,0 +1,105 @@
using RemSox.Shared.UI;
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class RadioButton() : Control("RadioButton")
{
public event EventHandler? OnCheckedChanged;
public bool IsChecked
{
get;
set
{
SetProperty(nameof(IsChecked), ref field, value);
OnCheckedChanged?.Invoke(this, EventArgs.Empty);
}
}
public string Text
{
get;
set => SetProperty(nameof(Text), ref field, value);
} = string.Empty;
public Color TextColor
{
get;
set => SetProperty(nameof(TextColor), ref field, value);
} = Color.White;
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
int diameter = Size.Height;
int radius = diameter / 2;
Point center = new(Position.X + radius, Position.Y + radius);
// Outer circle
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawCircle,
Position = new Point(center.X - radius, center.Y - radius),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DarkGray,
["Radius"] = radius,
}
};
// Inner fill when checked
if (IsChecked)
{
int innerRadius = radius - 3;
if (innerRadius > 0)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(1),
Type = RenderCommandType.DrawFilledCircle,
Position = new Point(center.X - innerRadius, center.Y - innerRadius),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.Black,
["Radius"] = innerRadius,
}
};
}
}
// Label text
if (!string.IsNullOrEmpty(Text))
{
int textX = Position.X + diameter + 5;
int textY = Position.Y + (Size.Height / 2) - 8;
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(2),
Type = RenderCommandType.DrawText,
Position = new Point(textX, textY),
Properties = new Dictionary<string, object?>
{
["Color"] = TextColor,
["Content"] = Text,
["FontSize"] = Size.Height,
["MaxWidth"] = Size.Width - Size.Height - 5,
}
};
}
}
public override void HandleMouseEvent(MouseEvent mouseEvent)
{
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
{
IsChecked = true;
}
}
}
@@ -0,0 +1,143 @@
using RemSox.Shared.UI;
using RemSox.Shared.UI.GUI.Rendering;
using System.Drawing;
namespace RemSox.Kernel.UI.GUI.UIEelements.Controls;
public class Slider() : Control("Slider")
{
public event EventHandler? OnValueChanged;
public int MinValue
{
get;
set => SetProperty(nameof(MinValue), ref field, value);
}
public int MaxValue
{
get;
set => SetProperty(nameof(MaxValue), ref field, value);
} = 100;
public int Value
{
get;
set
{
int clamped = Math.Clamp(value, MinValue, MaxValue);
SetProperty(nameof(Value), ref field, clamped);
if (Value == clamped)
{
OnValueChanged?.Invoke(this, EventArgs.Empty);
}
}
}
public Color ThumbColor
{
get;
set => SetProperty(nameof(ThumbColor), ref field, value);
} = Color.LightGray;
public override IEnumerable<RenderCommand> ToPrimitives(int windowId)
{
int trackHeight = 4;
int trackY = Position.Y + (Size.Height / 2) - (trackHeight / 2);
// Track background
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(0),
Type = RenderCommandType.DrawFilledRect,
Position = new Point(Position.X, trackY),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DimGray,
["Size"] = new Size(Size.Width, trackHeight),
}
};
// Filled portion
int range = MaxValue - MinValue;
int fillWidth = range > 0 ? Size.Width * (Value - MinValue) / range : 0;
if (fillWidth > 0)
{
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(1),
Type = RenderCommandType.DrawFilledRect,
Position = new Point(Position.X, trackY),
Properties = new Dictionary<string, object?>
{
["Color"] = BackgroundColor,
["Size"] = new Size(fillWidth, trackHeight),
}
};
}
// Thumb (centered at the fill edge)
int thumbSize = Size.Height;
int thumbX = fillWidth - (thumbSize / 2);
int thumbY = Position.Y;
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(2),
Type = RenderCommandType.DrawFilledCircle,
Position = new Point(Position.X + thumbX, thumbY),
Properties = new Dictionary<string, object?>
{
["Color"] = ThumbColor,
["Radius"] = thumbSize / 2,
}
};
// Thumb border
yield return new RenderCommand
{
WindowId = windowId,
ElementId = PrimitiveId(3),
Type = RenderCommandType.DrawCircle,
Position = new Point(Position.X + thumbX, thumbY),
Properties = new Dictionary<string, object?>
{
["Color"] = Color.DarkGray,
["Radius"] = thumbSize / 2,
}
};
}
private bool isDragging;
public override void HandleMouseEvent(MouseEvent mouseEvent)
{
if (mouseEvent.Type == MouseEventType.ButtonDown && mouseEvent.Button == MouseButton.Left)
{
isDragging = true;
SetValueFromX(mouseEvent.X);
}
else if (mouseEvent.Type == MouseEventType.Move && isDragging)
{
SetValueFromX(mouseEvent.X);
}
else if (mouseEvent.Type == MouseEventType.ButtonUp && mouseEvent.Button == MouseButton.Left)
{
isDragging = false;
}
}
private void SetValueFromX(int windowX)
{
int localX = windowX - Position.X;
int range = MaxValue - MinValue;
Value = range > 0
? MinValue + (localX * range / Size.Width)
: MinValue;
}
}