Slightly hacky fixes (most likely breaks something)
This commit is contained in:
parent
30e27b9a21
commit
7699deb82c
|
@ -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;
|
||||
|
|
|
@ -8,20 +8,40 @@ namespace CC_Functions.Commandline.TUI
|
|||
/// </summary>
|
||||
public class Label : Control
|
||||
{
|
||||
/// <summary>
|
||||
/// The text inside this label
|
||||
/// </summary>
|
||||
public string Content;
|
||||
private string _content;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new label
|
||||
/// </summary>
|
||||
/// <param name="content">The text inside this label</param>
|
||||
public Label(string content) => Content = content;
|
||||
public Label(string content)
|
||||
{
|
||||
_content = "";
|
||||
Content = content;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool Selectable { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// The text inside this label
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,13 +48,26 @@ namespace CC_Functions.Commandline.TUI
|
|||
}
|
||||
}
|
||||
|
||||
private int _wndHeight = Console.WindowHeight;
|
||||
private int _wndWidth = Console.WindowWidth;
|
||||
|
||||
/// <summary>
|
||||
/// The current index of the tab-selected control in an array of selectable controls
|
||||
/// </summary>
|
||||
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;
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
|||
/// <returns>The new state of the screen</returns>
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue