-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLine.cs
66 lines (49 loc) · 1.69 KB
/
Line.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
// Developed by Bulat Bagaviev (@sunnyyssh).
// This file is licensed to you under the MIT license.
namespace Sunnyyssh.ConsoleUI;
public sealed class Line : UIElement
{
public Orientation Orientation { get; }
public LineCharSet CharSet { get; }
public Color Color { get; init; } = Color.Default;
public int Length { get; }
protected override DrawState CreateDrawState()
{
var builder = new DrawStateBuilder(Width, Height);
char ch = Orientation == Orientation.Vertical
? CharSet.VerticalLine
: CharSet.HorizontalLine;
builder.Fill(new PixelInfo(ch, Color.Transparent, Color));
return builder.ToDrawState();
}
private static int ResolveWidth(int length, Orientation orientation)
{
if (orientation == Orientation.Vertical)
{
return 1;
}
return length;
}
private static int ResolveHeight(int length, Orientation orientation)
{
if (orientation == Orientation.Horizontal)
{
return 1;
}
return length;
}
internal Line(int length, Orientation orientation, LineKind kind, OverlappingPriority priority)
: this(length, orientation, LineCharSets.Of(kind), priority)
{
}
internal Line(int length, Orientation orientation, LineCharSet charSet, OverlappingPriority priority)
: base(ResolveWidth(length, orientation),
ResolveHeight(length, orientation),
priority)
{
ArgumentNullException.ThrowIfNull(charSet, nameof(charSet));
Length = length;
Orientation = orientation;
CharSet = charSet;
}
}