This repository has been archived on 2022-08-05. You can view files and clone it, but cannot push or open issues or pull requests.
CC-Functions/Commandline/TUI/Button.cs
2020-05-23 15:32:29 +02:00

41 lines
1.2 KiB
C#

using System.Drawing;
using CC_Functions.Misc;
namespace CC_Functions.Commandline.TUI
{
/// <summary>
/// A basic button type
/// </summary>
public class Button : Control
{
/// <summary>
/// The text inside this button
/// </summary>
public string Content;
/// <summary>
/// Creates a new button
/// </summary>
/// <param name="content">The text inside this button</param>
public Button(string content)
{
Content = content;
char[,] tmp = Content.ToNdArray2D();
Size = new Size(tmp.GetLength(0), tmp.GetLength(1));
}
/// <inheritdoc />
public override Pixel[,] Render()
{
char[,] inp = Content.ToNdArray2D();
inp = inp.Resize(Size.Width, Size.Height);
Pixel[,] output = new Pixel[Size.Width, Size.Height];
for (int x = 0; x < Size.Width; x++)
for (int y = 0; y < Size.Height; y++)
output[x, y] = new Pixel(Selected ? ForeColor : BackColor, Selected ? BackColor : ForeColor, inp[x, y]);
return output;
}
/// <inheritdoc />
public override bool Selectable { get; } = true;
}
}