-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBorderBuilder.cs
94 lines (67 loc) · 2.97 KB
/
BorderBuilder.cs
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
87
88
89
90
91
92
93
94
// 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 BorderBuilder : IUIElementBuilder<Border>
{
public Size Size { get; }
public BorderCharSet? BorderCharSet { get; }
public BorderKind? BorderKind { get; }
public OverlappingPriority OverlappingPriority { get; init; } = OverlappingPriority.Medium;
public Color Color { get; init; } = Color.Default;
[MemberNotNullWhen(true, nameof(BorderKind))]
[MemberNotNullWhen(false, nameof(BorderCharSet))]
public bool IsOneOfKinds { get; }
public Border Build(UIElementBuildArgs args)
{
ArgumentNullException.ThrowIfNull(args, nameof(args));
int width = args.Width;
int height = args.Height;
var charSet = IsOneOfKinds ? BorderCharSets.Of(BorderKind.Value) : BorderCharSet;
var resultBorder = new CharSetBorder(width, height, charSet, Color, OverlappingPriority);
return resultBorder;
}
UIElement IUIElementBuilder.Build(UIElementBuildArgs args) => Build(args);
public BorderBuilder(int width, int height, BorderKind borderKind)
: this(new Size(width, height), borderKind)
{ }
public BorderBuilder(int width, double heightRelation, BorderKind borderKind)
: this(new Size(width, heightRelation), borderKind)
{ }
public BorderBuilder(double widthRelation, int height, BorderKind borderKind)
: this(new Size(widthRelation, height), borderKind)
{ }
public BorderBuilder(double widthRelation, double heightRelation, BorderKind borderKind)
: this(new Size(widthRelation, heightRelation), borderKind)
{ }
public BorderBuilder(Size size, BorderKind borderKind)
{
ArgumentNullException.ThrowIfNull(size, nameof(size));
if (borderKind == ConsoleUI.BorderKind.None)
{
throw new ArgumentOutOfRangeException(nameof(borderKind), "Border kind can't be None.");
}
Size = size;
BorderKind = borderKind;
IsOneOfKinds = true;
}
public BorderBuilder(int width, int height, BorderCharSet charSet)
: this(new Size(width, height), charSet)
{ }
public BorderBuilder(int width, double heightRelation, BorderCharSet charSet)
: this(new Size(width, heightRelation), charSet)
{ }
public BorderBuilder(double widthRelation, int height, BorderCharSet charSet)
: this(new Size(widthRelation, height), charSet)
{ }
public BorderBuilder(double widthRelation, double heightRelation, BorderCharSet charSet)
: this(new Size(widthRelation, heightRelation), charSet)
{ }
public BorderBuilder(Size size, BorderCharSet borderCharSet)
{
ArgumentNullException.ThrowIfNull(borderCharSet, nameof(borderCharSet));
Size = size;
BorderCharSet = borderCharSet;
IsOneOfKinds = false;
}
}