Skip to content

Latest commit

 

History

History
48 lines (39 loc) · 1.78 KB

Button.doc.md

File metadata and controls

48 lines (39 loc) · 1.78 KB

Button

public sealed class Button : UIElement, IFocusable

You can find its source code in Button.cs

Building

To build `Button` you should use `ButtonBuilder`. (Its source code is in ButtonBuilder.cs)
```csharp public sealed class ButtonBuilder : IUIElementBuilder ```

Here is an example:

using System.Collections.Immutable;
using Sunnyyssh.ConsoleUI;

var appBuilder = new ApplicationBuilder(new ApplicationSettings()); // App builder init.

// Button will be 20*20 pixels.
var buttonBuilder = new ButtonBuilder(20, 4) // Creating builder.
{
    NotFocusedBackground = Color.DarkRed, // The background will be red.
    NotFocusedForeground = Color.White, // The foreground will be white.
    ShowPress = true, // If it's pressed it will show it by changing its color. (Specified below).
    PressedBackground = Color.Blue, // Specifies background when it is pressed.
    PressedBorderColor = Color.DarkYellow, // Specifies foreground when it is pressed.
    Text = "Press me!!!", // Text of the button.
    LoseFocusAfterPress = true, // Specifies that button should lose focus when it's pressed.
    HandledKeys = ImmutableList.Create(ConsoleKey.Enter), // Keys detected as pressed.
    BorderKind = BorderKind.DoubleLine, // Border will be double-lined.
    TextHorizontalAligning = HorizontalAligning.Right, // Text aligns to the right.
    TextVerticalAligning = VerticalAligning.Top // Text aligns to the top.
};
    
appBuilder
    .Add(buttonBuilder, 0.5, 0.5) // Adds buttonBuilder at the relational center position.
    .Build() // Application builds.
    .Run(); // Application runs.

It runs to this: