-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextBoxBuilder.cs
111 lines (79 loc) · 3.29 KB
/
TextBoxBuilder.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Developed by Bulat Bagaviev (@sunnyyssh).
// This file is licensed to you under the MIT license.
namespace Sunnyyssh.ConsoleUI;
public sealed class TextBoxBuilder : IUIElementBuilder<TextBox>
{
#region Colors.
private readonly Color? _focusedBackground;
private readonly Color? _focusedForeground;
private readonly Color? _focusedBorderColor;
public Color NotFocusedBackground { get; init; } = Color.Default;
public Color NotFocusedForeground { get; init; } = Color.Default;
public Color NotFocusedBorderColor { get; init; } = Color.Default;
public Color FocusedBackground
{
get => _focusedBackground ?? NotFocusedBackground;
init => _focusedBackground = value;
}
public Color FocusedForeground
{
get => _focusedForeground ?? NotFocusedForeground;
init => _focusedForeground = value;
}
public Color FocusedBorderColor
{
get => _focusedBorderColor ?? NotFocusedBorderColor;
init => _focusedBorderColor = value;
}
#endregion
public Size Size { get; }
public string? StartingText { get; init; } = null;
public BorderKind BorderKind { get; init; } = BorderKind.SingleLine;
public OverlappingPriority OverlappingPriority { get; init; } = OverlappingPriority.Medium;
public bool ShowPressedChars { get; init; } = true;
public bool WordWrap { get; init; } = true;
public bool UserEditable { get; init; } = true;
public HorizontalAligning TextHorizontalAligning { get; init; } = HorizontalAligning.Left;
public VerticalAligning TextVerticalAligning { get; init; } = VerticalAligning.Top;
public TextBox Build(UIElementBuildArgs args)
{
ArgumentNullException.ThrowIfNull(args, nameof(args));
int width = args.Width;
int height = args.Height;
var resultTextBox = new TextBox(width, height, OverlappingPriority)
{
BorderKind = BorderKind,
WordWrap = WordWrap,
TextHorizontalAligning = TextHorizontalAligning,
TextVerticalAligning = TextVerticalAligning,
FocusedBackground = FocusedBackground,
FocusedBorderColor = FocusedBorderColor,
FocusedForeground = FocusedForeground,
NotFocusedBackground = NotFocusedBackground,
NotFocusedBorderColor = NotFocusedBorderColor,
NotFocusedForeground = NotFocusedForeground,
ShowPressedChars = ShowPressedChars,
UserEditable = UserEditable,
Text = StartingText,
};
return resultTextBox;
}
UIElement IUIElementBuilder.Build(UIElementBuildArgs args) => Build(args);
public TextBoxBuilder(int width, int height)
: this(new Size(width, height))
{ }
public TextBoxBuilder(int width, double heightRelation)
: this(new Size(width, heightRelation))
{ }
public TextBoxBuilder(double widthRelation, int height)
: this(new Size(widthRelation, height))
{ }
public TextBoxBuilder(double widthRelation, double heightRelation)
: this(new Size(widthRelation, heightRelation))
{ }
public TextBoxBuilder(Size size)
{
ArgumentNullException.ThrowIfNull(size, nameof(size));
Size = size;
}
}