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 (!full && tmp1 == _last[y, x]) continue;
|
||||||
if (!ReferenceEquals(tmp1, null) && color)
|
if (!ReferenceEquals(tmp1, null) && color)
|
||||||
{
|
{
|
||||||
if (Console.ForegroundColor != tmp1?.ForeColor)
|
if (Console.ForegroundColor != tmp1.ForeColor)
|
||||||
Console.ForegroundColor = tmp1.ForeColor;
|
Console.ForegroundColor = tmp1.ForeColor;
|
||||||
if (Console.BackgroundColor != tmp1?.BackColor)
|
if (Console.BackgroundColor != tmp1.BackColor)
|
||||||
Console.BackgroundColor = tmp1.BackColor;
|
Console.BackgroundColor = tmp1.BackColor;
|
||||||
}
|
}
|
||||||
Console.CursorLeft = x;
|
Console.CursorLeft = x;
|
||||||
|
|
|
@ -8,20 +8,40 @@ namespace CC_Functions.Commandline.TUI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Label : Control
|
public class Label : Control
|
||||||
{
|
{
|
||||||
/// <summary>
|
private string _content;
|
||||||
/// The text inside this label
|
|
||||||
/// </summary>
|
|
||||||
public string Content;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new label
|
/// Creates a new label
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="content">The text inside this label</param>
|
/// <param name="content">The text inside this label</param>
|
||||||
public Label(string content) => Content = content;
|
public Label(string content)
|
||||||
|
{
|
||||||
|
_content = "";
|
||||||
|
Content = content;
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool Selectable { get; } = false;
|
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 />
|
/// <inheritdoc />
|
||||||
public override Pixel[,] Render()
|
public override Pixel[,] Render()
|
||||||
{
|
{
|
||||||
|
@ -32,7 +52,6 @@ namespace CC_Functions.Commandline.TUI
|
||||||
for (int x = 0; x < w; x++)
|
for (int x = 0; x < w; x++)
|
||||||
for (int y = 0; y < h; y++)
|
for (int y = 0; y < h; y++)
|
||||||
output[x, y] = new Pixel(BackColor, ForeColor, inp[x, y]);
|
output[x, y] = new Pixel(BackColor, ForeColor, inp[x, y]);
|
||||||
Size = new Size(w, h);
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,26 @@ namespace CC_Functions.Commandline.TUI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int _wndHeight = Console.WindowHeight;
|
|
||||||
private int _wndWidth = Console.WindowWidth;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The current index of the tab-selected control in an array of selectable controls
|
/// The current index of the tab-selected control in an array of selectable controls
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Creates a screen object. Multiple can be instantiated but drawing one overrides others. Use panels for that
|
/// 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>
|
/// <returns>The new state of the screen</returns>
|
||||||
public new Pixel[,] Render()
|
public new Pixel[,] Render()
|
||||||
{
|
{
|
||||||
|
FixSelection();
|
||||||
Pixel[,] tmp = base.Render();
|
Pixel[,] tmp = base.Render();
|
||||||
DiffDraw.Clear(tmp);
|
DiffDraw.Clear(tmp);
|
||||||
DiffDraw.Draw(Color);
|
DiffDraw.Draw(Color);
|
||||||
|
@ -138,6 +152,8 @@ namespace CC_Functions.Commandline.TUI
|
||||||
}
|
}
|
||||||
if (canRedraw && render)
|
if (canRedraw && render)
|
||||||
Render();
|
Render();
|
||||||
|
else
|
||||||
|
FixSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -170,10 +186,21 @@ namespace CC_Functions.Commandline.TUI
|
||||||
TabPoint--;
|
TabPoint--;
|
||||||
if (TabPoint < 0) TabPoint = selectable.Length - 1;
|
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;
|
foreach (Control control in selectable) control.Selected = false;
|
||||||
selectable[TabPoint].Selected = true;
|
selectable[TabPoint].Selected = true;
|
||||||
TabChanged?.Invoke(this, new EventArgs());
|
TabChanged?.Invoke(this, new EventArgs());
|
||||||
Render();
|
if (draw)
|
||||||
|
Render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue