-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWrapperBasedChooser.cs
39 lines (31 loc) · 1.3 KB
/
WrapperBasedChooser.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
// Developed by Bulat Bagaviev (@sunnyyssh).
// This file is licensed to you under the MIT license.
namespace Sunnyyssh.ConsoleUI;
public abstract class WrapperBasedChooser<TWrapper> : OptionChooser
where TWrapper : Wrapper
{
protected TWrapper OptionsWrapper { get; }
protected override DrawState CreateDrawState()
{
OptionsWrapper.OnDraw();
return OptionsWrapper.RequestDrawState(DrawOptions.Empty);
}
private void RedrawWrapper(UIElement sender, RedrawElementEventArgs args)
{
Redraw(CreateDrawState());
}
private void SubscribeWrapper(TWrapper wrapper)
{
wrapper.RedrawElement += RedrawWrapper;
}
protected WrapperBasedChooser(int width, int height, TWrapper optionsWrapper,
IReadOnlyList<OptionElement> orderedOptions, OptionChooserKeySet keySet, bool canChooseOnlyOne, OverlappingPriority priority)
: base(width, height, orderedOptions, keySet, canChooseOnlyOne, priority)
{
ArgumentNullException.ThrowIfNull(optionsWrapper, nameof(optionsWrapper));
ArgumentNullException.ThrowIfNull(orderedOptions, nameof(orderedOptions));
ArgumentNullException.ThrowIfNull(keySet, nameof(keySet));
OptionsWrapper = optionsWrapper;
SubscribeWrapper(optionsWrapper);
}
}