-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLineCompositionBuilder.cs
More file actions
57 lines (41 loc) · 1.81 KB
/
LineCompositionBuilder.cs
File metadata and controls
57 lines (41 loc) · 1.81 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
// Developed by Bulat Bagaviev (@sunnyyssh).
// This file is licensed to you under the MIT license.
namespace Sunnyyssh.ConsoleUI;
public sealed class LineCompositionBuilder : IUIElementBuilder<LineComposition>
{
private readonly List<LineChild> _lines = new();
public Color Color { get; init; } = Color.Default;
public LineKind LineKind { get; init; } = LineKind.Single;
public LineCharSet? LineCharSet { get; init; }
public OverlappingPriority OverlappingPriority { get; init; } = OverlappingPriority.Medium;
public Size Size { get; }
public LineCompositionBuilder Add(int length, Orientation orientation, int left, int top)
{
if (length <= 0)
throw new ArgumentOutOfRangeException(nameof(length), length, null);
if (left < 0)
throw new ArgumentOutOfRangeException(nameof(left), left, null);
if (top < 0)
throw new ArgumentOutOfRangeException(nameof(top), top, null);
_lines.Add(new LineChild(length, orientation, left, top));
return this;
}
public LineComposition Build(UIElementBuildArgs args)
{
int width = args.Width;
int height = args.Height;
var charSet = LineCharSet ?? LineCharSets.Of(LineKind);
var result = new LineComposition(width, height, _lines.ToArray(), charSet, OverlappingPriority)
{
Color = Color,
};
return result;
}
UIElement IUIElementBuilder.Build(UIElementBuildArgs args) => Build(args);
// There are no no ability to make line composition with relational size in order to ease it.
// What's more, It's used in cases when width and height are already known.
public LineCompositionBuilder(int width, int height)
{
Size = new Size(width, height);
}
}