using System.Collections.Generic;
using System.Linq;
using CC_Functions.Misc;
namespace CC_Functions.Commandline.TUI
{
///
/// A panel containing other components. MUST be inherited for all other controls that contain others
///
public class Panel : Control
{
///
/// Enable to draw a simple border around this control
///
public bool Border = true;
///
/// The controls inside this panel
///
public List Controls = new List();
///
public override bool Selectable { get; } = false;
///
/// Renders the control and all contained controls
///
/// The rendered pixels
public override Pixel[,] Render()
{
Pixel[,] tmp = new Pixel[Size.Height, Size.Width];
tmp.Populate(new Pixel(BackColor, ForeColor, SpecialChars.Empty));
if (Border)
{
for (int i = 0; i < Size.Width; i++) tmp[Size.Height - 1, i] = new Pixel(BackColor, ForeColor, SpecialChars.OneLineSimple.LeftRight);
for (int i = 0; i < Size.Height; i++) tmp[i, Size.Width - 1] = new Pixel(BackColor, ForeColor, SpecialChars.OneLineSimple.UpDown);
tmp[Size.Height - 1, Size.Width - 1] = new Pixel(BackColor, ForeColor, '┘');
}
foreach (Control control in Controls)
if (control.Visible)
{
Pixel[,] render = control.Render();
render.CopyTo(tmp, control.Point);
}
return tmp;
}
///
/// Recursively enumerates all controls
///
/// A list of all controls
public Control[] EnumerateRecursive()
{
List output = Controls.ToList();
int i = 0;
while (i < output.Count)
{
if (output[i] is Panel p) output.AddRange(p.EnumerateRecursive().Where(s => !output.Contains(s)));
i++;
}
return output.ToArray();
}
}
}