-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineBuilder.cs
More file actions
86 lines (61 loc) · 2.61 KB
/
LineBuilder.cs
File metadata and controls
86 lines (61 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Developed by Bulat Bagaviev (@sunnyyssh).
// This file is licensed to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
namespace Sunnyyssh.ConsoleUI;
public sealed class LineBuilder : IUIElementBuilder<Line>
{
private readonly Size _size;
Size IUIElementBuilder.Size => _size;
public Orientation Orientation { get; }
public int? Length { get; }
public double? LengthRelational { get; }
[MemberNotNullWhen(true, nameof(LengthRelational))]
[MemberNotNullWhen(false, nameof(Length))]
public bool IsLengthRelational { get; }
public Color Color { get; init; } = Color.Default;
public LineKind LineKind { get; init; } = LineKind.Single;
public LineCharSet? CharSet { get; init; }
public OverlappingPriority OverlappingPriority { get; init; } = OverlappingPriority.Medium;
public Line Build(UIElementBuildArgs args)
{
ArgumentNullException.ThrowIfNull(args, nameof(args));
int width = args.Width;
int height = args.Height;
var charSet = CharSet ?? LineCharSets.Of(LineKind);
int length = Orientation == Orientation.Horizontal ? width : height;
var resultLine = new Line(length, Orientation, charSet, OverlappingPriority)
{
Color = Color
};
return resultLine;
}
UIElement IUIElementBuilder.Build(UIElementBuildArgs args) => Build(args);
public LineBuilder(int length, Orientation orientation)
{
if (length <= 0)
throw new ArgumentOutOfRangeException(nameof(length), length, null);
Length = length;
IsLengthRelational = false;
Orientation = orientation;
_size = orientation switch
{
Orientation.Vertical => new Size(1, length),
Orientation.Horizontal => new Size(length, 1),
_ => throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null)
};
}
public LineBuilder(double lengthRelational, Orientation orientation)
{
if (lengthRelational <= 0.0 || lengthRelational >= 1.0)
throw new ArgumentOutOfRangeException(nameof(lengthRelational), lengthRelational, null);
LengthRelational = lengthRelational;
IsLengthRelational = true;
Orientation = orientation;
_size = orientation switch
{
Orientation.Vertical => new Size(1, lengthRelational),
Orientation.Horizontal => new Size(lengthRelational, 1),
_ => throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null)
};
}
}