diff --git a/Commandline/TUI/DiffDraw.cs b/Commandline/TUI/DiffDraw.cs index aa8e71c..bd5fa54 100644 --- a/Commandline/TUI/DiffDraw.cs +++ b/Commandline/TUI/DiffDraw.cs @@ -44,9 +44,9 @@ namespace CC_Functions.Commandline.TUI if (!full && tmp1 == _last[y, x]) continue; if (!ReferenceEquals(tmp1, null) && color) { - if (Console.ForegroundColor != tmp1?.ForeColor) + if (Console.ForegroundColor != tmp1.ForeColor) Console.ForegroundColor = tmp1.ForeColor; - if (Console.BackgroundColor != tmp1?.BackColor) + if (Console.BackgroundColor != tmp1.BackColor) Console.BackgroundColor = tmp1.BackColor; } Console.CursorLeft = x; diff --git a/Commandline/TUI/Label.cs b/Commandline/TUI/Label.cs index d6e65ad..2f441ba 100644 --- a/Commandline/TUI/Label.cs +++ b/Commandline/TUI/Label.cs @@ -8,20 +8,40 @@ namespace CC_Functions.Commandline.TUI /// public class Label : Control { - /// - /// The text inside this label - /// - public string Content; + private string _content; /// /// Creates a new label /// /// The text inside this label - public Label(string content) => Content = content; + public Label(string content) + { + _content = ""; + Content = content; + } /// public override bool Selectable { get; } = false; + /// + /// The text inside this label + /// + public string Content + { + get => _content; + set + { + if (_content != value) + { + _content = value; + char[,] inp = Content.ToNdArray2D(); + int w = inp.GetLength(1); + int h = inp.GetLength(0); + Size = new Size(w, h); + } + } + } + /// public override Pixel[,] Render() { @@ -32,7 +52,6 @@ namespace CC_Functions.Commandline.TUI for (int x = 0; x < w; x++) for (int y = 0; y < h; y++) output[x, y] = new Pixel(BackColor, ForeColor, inp[x, y]); - Size = new Size(w, h); return output; } } diff --git a/Commandline/TUI/Screen.cs b/Commandline/TUI/Screen.cs index 1ff8abd..40ae61f 100644 --- a/Commandline/TUI/Screen.cs +++ b/Commandline/TUI/Screen.cs @@ -48,13 +48,26 @@ namespace CC_Functions.Commandline.TUI } } - private int _wndHeight = Console.WindowHeight; - private int _wndWidth = Console.WindowWidth; - /// /// The current index of the tab-selected control in an array of selectable controls /// - public int TabPoint; + public int TabPoint + { + get => _tabPoint; + set + { + if (_tabPoint != value) + { + _tabPoint = value; + + } + } + } + + private int _wndHeight = Console.WindowHeight; + private int _wndWidth = Console.WindowWidth; + + private int _tabPoint; /// /// Creates a screen object. Multiple can be instantiated but drawing one overrides others. Use panels for that @@ -87,6 +100,7 @@ namespace CC_Functions.Commandline.TUI /// The new state of the screen public new Pixel[,] Render() { + FixSelection(); Pixel[,] tmp = base.Render(); DiffDraw.Clear(tmp); DiffDraw.Draw(Color); @@ -138,6 +152,8 @@ namespace CC_Functions.Commandline.TUI } if (canRedraw && render) Render(); + else + FixSelection(); } /// @@ -170,10 +186,21 @@ namespace CC_Functions.Commandline.TUI TabPoint--; if (TabPoint < 0) TabPoint = selectable.Length - 1; } + FixSelection(true); + } + } + + private void FixSelection(bool draw = false) + { + Control[] controls = EnumerateRecursive(); + Control[] selectable = controls.Where(s => s.Selectable).ToArray(); + if (selectable.Any()) + { foreach (Control control in selectable) control.Selected = false; selectable[TabPoint].Selected = true; TabChanged?.Invoke(this, new EventArgs()); - Render(); + if (draw) + Render(); } }