wTechnoo / ConsoleButtons

Clickable buttons for console!
23 stars 0 forks source link

Console Buttons

project-image

Clickable UI for C# Console

Buttons, checkboxes, sliders and more!

⚠️ Warning

Console buttons will only work when launched through the built .EXE on RELEASE mode

✔️ Changes (24/12/21)

1. Removed Colorful.Console dependency

2. Added proper WriteLine and Clear that works as expected (default Console.WriteLine wasn't producing proper results)

3. Renamed some of the scripts

❔ To be worked on

1. Adding a way to the user to use their own/downloaded console packages (such as Colorful.Console or any other color package)

📌Package

Download the package through nugget or build it yourself!

⌨️ Example Usage

static void Main(string[] args)
{
    UIManager manager = new UIManager();

    //Button constructor that auto detects the COLLIDER WIDTH based on how many characters there are on the text.
    Button button = new Button("Sign Up", 0, 0);
    button.OnHoverOver += () => { button.WriteWithColor(ConsoleColor.Gray); };
    button.OnHoverStop += () => { button.WriteWithNoColor(); };
    button.OnClick += () => { button.WriteWithColor(ConsoleColor.Red); Thread.Sleep(50); };
    button.OnHold += () => { button.WriteWithColor(ConsoleColor.Red); };

    //Checkbox constructor order (text string, marked checkbox char, is initialized as checked, collide with text, X and Y)
    CheckBox checkBox = new CheckBox("Checkbox", 'X', false, true, 0, 0);
    checkBox.OnHoverOver += () => { checkBox.WriteWithColor(ConsoleColor.Gray); };
    checkBox.OnHoverStop += () => { checkBox.WriteWithNoColor(); };
    checkBox.OnClick += () => { checkBox.WriteWithColor(ConsoleColor.Cyan); Thread.Sleep(50); };
    checkBox.OnHold += () => { checkBox.WriteWithColor(ConsoleColor.Red); };

    //Slider constructor order (initial value, max value, slider size, convert to int, filled char, unfilled char, X and Y)
    Slider slider = new Slider(0, 10, 10, false, '█', ' ', 5,5);
    slider.OnHoverOver += () => { slider.WriteWithColor(ConsoleColor.Gray); };
    slider.OnHoverStop += () => { slider.WriteWithNoColor(); };
    slider.OnHold += () => { slider.WriteWithColor(ConsoleColor.Red); Console.Write(slider.Value, ConsoleColor.Aqua); };

    manager.AddToComponents(button);
    manager.AddToComponents(checkBox);
    manager.AddToComponents(slider);

    while (true)
    {
        manager.Update();
    }

    Console.ReadKey();
}