TextBox, PropertyChangeHandler

This commit is contained in:
2023-08-11 21:51:44 +02:00
parent e989a65e81
commit 1fde0df2d6
81 changed files with 1539 additions and 390 deletions

View File

@@ -1,18 +0,0 @@
namespace TerminalUI.Models;
public record Margin(int Left, int Top, int Right, int Bottom)
{
public static implicit operator Margin(int value) => new(value, value, value, value);
public static implicit operator Margin((int Left, int Top, int Right, int Bottom) value) => new(value.Left, value.Top, value.Right, value.Bottom);
public static implicit operator Margin(string s)
{
var parts = s.Split(' ');
return parts.Length switch
{
1 => new Margin(int.Parse(parts[0])),
2 => new Margin(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[0]), int.Parse(parts[1])),
4 => new Margin(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3])),
_ => throw new ArgumentException("Invalid margin format", nameof(s))
};
}
}

View File

@@ -1,3 +1,10 @@
namespace TerminalUI.Models;
using System.Diagnostics;
public record struct Position(int X, int Y);
namespace TerminalUI.Models;
[DebuggerDisplay("X = {X}, Y = {Y}")]
public readonly record struct Position(int X, int Y)
{
public static Position operator +(Position left, Position right) => new(left.X + right.X, left.Y + right.Y);
public static Position operator -(Position left, Position right) => new(left.X - right.X, left.Y - right.Y);
}

View File

@@ -1,18 +1,32 @@
using TerminalUI.ConsoleDrivers;
using System.Diagnostics;
using TerminalUI.Color;
using TerminalUI.ConsoleDrivers;
namespace TerminalUI.Models;
[DebuggerDisplay("RenderId = {RenderId}, ForceRerender = {ForceRerender}, Driver = {ConsoleDriver.GetType().Name}")]
public readonly ref struct RenderContext
{
private static int _renderId = 0;
private static int _renderId;
public readonly int RenderId;
public readonly IConsoleDriver ConsoleDriver;
public readonly bool ForceRerender;
public readonly IColor? Foreground;
public readonly IColor? Background;
public RenderContext(IConsoleDriver consoleDriver)
public RenderContext(
IConsoleDriver consoleDriver,
bool forceRerender,
IColor? foreground,
IColor? background)
{
ConsoleDriver = consoleDriver;
RenderId = _renderId++;
ConsoleDriver = consoleDriver;
ForceRerender = forceRerender;
Foreground = foreground;
Background = background;
}
public static RenderContext Empty => new(null!);
public static RenderContext Empty => new(null!, false, null, null);
}

View File

@@ -1,3 +1,6 @@
namespace TerminalUI.Models;
using System.Diagnostics;
namespace TerminalUI.Models;
[DebuggerDisplay("Width = {Width}, Height = {Height}")]
public readonly record struct Size(int Width, int Height);

View File

@@ -0,0 +1,21 @@
using System.Diagnostics;
namespace TerminalUI.Models;
[DebuggerDisplay("Left = {Left}, Top = {Top}, Right = {Right}, Bottom = {Bottom}")]
public record Thickness(int Left, int Top, int Right, int Bottom)
{
public static implicit operator Thickness(int value) => new(value, value, value, value);
public static implicit operator Thickness((int Left, int Top, int Right, int Bottom) value) => new(value.Left, value.Top, value.Right, value.Bottom);
public static implicit operator Thickness(string s)
{
var parts = s.Split(' ');
return parts.Length switch
{
1 => new Thickness(int.Parse(parts[0])),
2 => new Thickness(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[0]), int.Parse(parts[1])),
4 => new Thickness(int.Parse(parts[0]), int.Parse(parts[1]), int.Parse(parts[2]), int.Parse(parts[3])),
_ => throw new ArgumentException("Invalid margin format", nameof(s))
};
}
}