-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonBuilder.cs
More file actions
117 lines (79 loc) · 3.81 KB
/
ButtonBuilder.cs
File metadata and controls
117 lines (79 loc) · 3.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
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
112
113
114
115
116
117
// Developed by Bulat Bagaviev (@sunnyyssh).
// This file is licensed to you under the MIT license.
using System.Collections.Immutable;
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace Sunnyyssh.ConsoleUI;
public sealed class ButtonBuilder : IUIElementBuilder<Button>
{
#region Properties
private ImmutableList<ConsoleKey> _ignoredKeys = ImmutableList<ConsoleKey>.Empty;
public OverlappingPriority OverlappingPriority { get; set; } = OverlappingPriority.Medium;
public Color NotFocusedBackground { get; set; } = Color.Default;
public Color NotFocusedForeground { get; set; } = Color.Default;
public Color NotFocusedBorderColor { get; set; } = Color.Default;
public Color? FocusedBackground { get; set; }
public Color? FocusedForeground { get; set; }
public Color? FocusedBorderColor { get; set; }
public Color? PressedBackground { get; set; }
public Color? PressedForeground { get; set; }
public Color? PressedBorderColor { get; set; }
public string? Text { get; set; }
public bool LoseFocusAfterPress { get; set; } = false;
public ImmutableList<ConsoleKey>? HandledKeys { get; set; }
public ImmutableList<ConsoleKey> IgnoredKeys
{
get => _ignoredKeys;
set => _ignoredKeys = value ?? throw new ArgumentNullException(nameof(value));
}
public BorderCharSet? BorderCharSet { get; set; }
public BorderKind BorderKind { get; set; } = BorderKind.SingleLine;
public bool ShowPress { get; set; } = true;
public HorizontalAligning TextHorizontalAligning { get; set; } = HorizontalAligning.Center;
public VerticalAligning TextVerticalAligning { get; set; } = VerticalAligning.Center;
public Size Size { get; }
#endregion
public Button Build(UIElementBuildArgs args)
{
int width = args.Width;
int height = args.Height;
var borderCharSet = BorderCharSet ?? (BorderKind == BorderKind.None ? null : BorderCharSets.Of(BorderKind));
var resultInstance = new Button(width, height, Text, HandledKeys, IgnoredKeys, OverlappingPriority)
{
NotFocusedBackground = NotFocusedBackground,
NotFocusedForeground = NotFocusedForeground,
NotFocusedBorderColor = NotFocusedBorderColor,
FocusedBackground = FocusedBackground ?? NotFocusedBackground,
FocusedForeground = FocusedForeground ?? NotFocusedForeground,
FocusedBorderColor = FocusedBorderColor ?? NotFocusedBorderColor,
PressedBackground = PressedBackground ?? FocusedBackground ?? NotFocusedBackground,
PressedForeground = PressedForeground ?? FocusedForeground ?? NotFocusedForeground,
PressedBorderColor = PressedBorderColor ?? FocusedBorderColor ?? NotFocusedBorderColor,
BorderCharSet = borderCharSet,
LoseFocusAfterPress = LoseFocusAfterPress,
ShowPress = ShowPress,
TextHorizontalAligning = TextHorizontalAligning,
TextVerticalAligning = TextVerticalAligning,
};
return resultInstance;
}
UIElement IUIElementBuilder.Build(UIElementBuildArgs args) => Build(args);
#region Constructors
public ButtonBuilder(int width, int height)
: this(new Size(width, height))
{ }
public ButtonBuilder(int width, double heightRelation)
: this(new Size(width, heightRelation))
{ }
public ButtonBuilder(double widthRelation, int height)
: this(new Size(widthRelation, height))
{ }
public ButtonBuilder(double widthRelation, double heightRelation)
: this(new Size(widthRelation, heightRelation))
{ }
public ButtonBuilder(Size size)
{
ArgumentNullException.ThrowIfNull(size, nameof(size));
Size = size;
}
#endregion
}