public abstract class OptionChooser : UIElement, IFocusable
You can find its source code in OptionChooser.cs
1. WrapperBasedChooser class in WrapperBasedChooser.cs 2. RowChooser class in RowChooser.cs 3. RowTextChooser class in RowTextChooser.cs It is base class for all choosers that are based on wrappers.public abstract class WrapperBasedChooser<TWrapper> : OptionChooser
where TWrapper : Wrapper
You can find its source code in WrapperBasedChooser.cs
1. RowChooser class in RowChooser.cs 2. RowTextChooser class in RowTextChooser.cs It is chooser which options are placed in a row.public class RowChooser : WrapperBasedChooser<Grid>
You can find its source code in RowChooser.cs
1. RowTextChooser class in RowTextChooser.cs To build RowChooser you should use RowChooserBuilder. (Its source code is in RowChooserBuilder.cs)Here is an example:
using Sunnyyssh.ConsoleUI;
var appBuilder = new ApplicationBuilder(new ApplicationSettings()); // App builder init.
// Chooser will be vertical, 30% width and 50% height.
var rowChooserBuilder = new RowChooserBuilder(0.3, 0.5, Orientation.Vertical)
{
BorderKind = BorderKind.None, // Chooser will not have a border.
CanChooseOnlyOne = false // Many options may be chosen.
// KeySet = ..., // You can also specify a key set.
};
// My options.
var redOptionBuilder = new MyOptionBuilder(new Size(1.0, 1.0 / 7), Color.Red);
var darkYellowOptionBuilder = new MyOptionBuilder(new Size(1.0, 1.0 / 7), Color.DarkYellow);
var yellowOptionBuilder = new MyOptionBuilder(new Size(1.0, 1.0 / 7), Color.Yellow);
var greenOptionBuilder = new MyOptionBuilder(new Size(1.0, 1.0 / 7), Color.Green);
var blueOptionBuilder = new MyOptionBuilder(new Size(1.0, 1.0 / 7), Color.Blue);
var darkBlueOptionBuilder = new MyOptionBuilder(new Size(1.0, 1.0 / 7), Color.DarkBlue);
var darkMagentaOptionBuilder = new MyOptionBuilder(new Size(1.0, 1.0 / 7), Color.DarkMagenta);
// Add options to chooser.
rowChooserBuilder.Add(redOptionBuilder)
.Add(darkYellowOptionBuilder)
.Add(yellowOptionBuilder)
.Add(greenOptionBuilder)
.Add(blueOptionBuilder)
.Add(darkBlueOptionBuilder)
.Add(darkMagentaOptionBuilder);
appBuilder
.Add(rowChooserBuilder, 0, 0) // Adds rowChooserBuilder at left and top position.
.Build() // Application builds.
.Run(); // Application runs.
sealed class MyOption : StateOptionElement
{
public Color Color { get; }
protected override DrawState RequestState(bool isChosen, bool isFocused)
{
var text = (isChosen, isFocused) switch
{
(false, false) => "Not chosen, not focused",
(false, true) => "Not chosen, focused",
(true, false) => "Chosen, not focused",
(true, true) => "Chosen, Focused",
};
return new DrawStateBuilder(Width, Height)
.Fill(Color)
.Place(0, 0, text, Color, Color.Default)
.ToDrawState();
}
internal MyOption(int width, int height, Color color) : base(width, height)
{
Color = color;
}
}
sealed class MyOptionBuilder : IUIElementBuilder<MyOption>
{
public Size Size { get; }
public Color Color { get; }
public MyOption Build(UIElementBuildArgs args) => new MyOption(args.Width, args.Height, Color);
UIElement IUIElementBuilder.Build(UIElementBuildArgs args) => Build(args);
public MyOptionBuilder(Size size, Color color)
{
Size = size;
Color = color;
}
}
public sealed class RowTextChooser : RowChooser
You can find its source code in RowTextChooser.cs
To build RowTextChooser you should use RowTextChooserBuilder. (Its source code is in RowTextChooserBuilder.cs)Here is an example:
using Sunnyyssh.ConsoleUI;
var appBuilder = new ApplicationBuilder(new ApplicationSettings()); // App builder init.
// Chooser will be vertical, 30% width and 50% height.
var rowTextChooserBuilder = new RowTextChooserBuilder(0.3, 0.5, Orientation.Vertical)
{
CanChooseOnlyOne = false, // Many options may be chosen.
BorderKind = BorderKind.SingleLine,
BorderColor = Color.Red,
ColorSet = new TextOptionColorSet(Color.DarkGray, Color.White) // Specifies colors of text options.
{
ChosenBackground = Color.DarkBlue,
ChosenFocusedBackground = Color.Blue,
FocusedBackground = Color.Gray,
}
};
// Add text options.
rowTextChooserBuilder.Add("Sunshine")
.Add("Rain")
.Add("Thunderstorm")
.Add("Cloudy");
appBuilder
.Add(rowTextChooserBuilder, 0.3, 0.3) // Adds rowTextChooserBuilder at 30% left and 30% top position.
.Build() // Application builds.
.Run(); // Application runs.