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 { /// /// The controls inside this panel /// public List Controls = new List(); /// /// 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)); foreach (Control control in Controls) { if (control.Visible) { Pixel[,] render = control.Render(); render.CopyTo(tmp, control.Point); } } return tmp; } /// public override bool Selectable { get; } = false; /// /// 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(); } } }