Add dashboard to deps page.

This commit is contained in:
Kolosov Alexandr 2024-03-17 01:31:13 +05:00
parent 91555925b6
commit 0dd105679e
17 changed files with 71 additions and 67 deletions

View File

@ -5,7 +5,7 @@ using TUI.Engine.Theme;
namespace TUI.Engine.Components; namespace TUI.Engine.Components;
public abstract class ComponentAttribute : NodeBase, IComponent public abstract class ComponentBase : NodeBase, IComponent
{ {
protected abstract Sketch DrawComponent(); protected abstract Sketch DrawComponent();
@ -13,29 +13,22 @@ public abstract class ComponentAttribute : NodeBase, IComponent
#region Alignments #region Alignments
internal Alignment Alignment { get; private set; } = new(Defaults.HorizontalAlignment, Defaults.VerticalAlignment);
Alignment IWithAlignment.Alignment => Alignment; Alignment IWithAlignment.Alignment => Alignment;
public void SetAlignment(Vertical vertical) internal Alignment Alignment { get; private set; } = new(Defaults.HorizontalAlignment, Defaults.VerticalAlignment);
{
Alignment = Alignment with { Vertical = vertical };
}
public void SetAlignment(Horizontal horizontal) public void SetAlignment(Vertical vertical) => Alignment = Alignment with { Vertical = vertical };
{
Alignment = Alignment with { Horizontal = horizontal }; public void SetAlignment(Horizontal horizontal) => Alignment = Alignment with { Horizontal = horizontal };
}
#endregion #endregion
#region Paddings #region Paddings
internal Padding Padding { get; private set; } = new(Defaults.Padding);
Padding IWithPadding.Padding => Padding; Padding IWithPadding.Padding => Padding;
internal Padding Padding { get; private set; } = new(Defaults.Padding);
public void SetPadding(Level level) => Padding = new Padding(level); public void SetPadding(Level level) => Padding = new Padding(level);
public void SetPaddingTop(Level level) => Padding = Padding with { Top = level }; public void SetPaddingTop(Level level) => Padding = Padding with { Top = level };

View File

@ -2,7 +2,7 @@ using System.Text;
namespace TUI.Engine.Components; namespace TUI.Engine.Components;
public abstract class StaticComponentAttribute : ComponentAttribute public abstract class StaticComponentBase : ComponentBase
{ {
private Sketch? _cache; private Sketch? _cache;

View File

@ -25,7 +25,7 @@ public static class Helper
public static void ShowBackground(Position position, Size size) public static void ShowBackground(Position position, Size size)
{ {
return; // return;
if (!Colors.Any()) if (!Colors.Any())
{ {
Init(); Init();

View File

@ -6,13 +6,13 @@ using TUI.Engine.Components;
namespace TUI.Components.Controls; namespace TUI.Components.Controls;
public class CellsComponentAttribute : ComponentAttribute, IComponent public class CellsComponentBase : ComponentBase, IComponent
{ {
private const int MaxCellWidth = 10; private const int MaxCellWidth = 10;
private readonly IEnumerable<string> _cells; private readonly IEnumerable<string> _cells;
public CellsComponentAttribute(IEnumerable<string> cells) public CellsComponentBase(IEnumerable<string> cells)
{ {
_cells = cells; _cells = cells;
} }

View File

@ -5,7 +5,7 @@ using TUI.Engine.Theme;
namespace TUI.Components.Controls; namespace TUI.Components.Controls;
public class Copyright : StaticComponentAttribute public class Copyright : StaticComponentBase
{ {
protected override void RenderWithCache(StringBuilder builder) protected override void RenderWithCache(StringBuilder builder)
{ {

View File

@ -7,7 +7,7 @@ using TUI.Engine.Theme;
namespace TUI.Components.Controls; namespace TUI.Components.Controls;
public class Dashboard : ComponentAttribute, IComponent public class Dashboard : ComponentBase, IComponent
{ {
private readonly string _title; private readonly string _title;
@ -16,53 +16,53 @@ public class Dashboard : ComponentAttribute, IComponent
_title = title; _title = title;
} }
public void Render(Horizontal horizontal, Size size) private static void RenderTopLine(StringBuilder builder, Size size, string title)
{
var dashboardBuilder = new StringBuilder();
RenderTopLine(dashboardBuilder, size, _title);
RenderMiddleLine(dashboardBuilder, size);
RenderBottomLine(dashboardBuilder, size);
// base.Render(dashboardBuilder, position, size);
}
private static void RenderTopLine(StringBuilder dashboardBuilder, Size size, string title)
{ {
var halfWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 - var halfWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 -
(int)Indentation.Default * 2) / 2; (int)Indentation.Default * 2) / 2;
dashboardBuilder.Append(Symbols.Angles.LeftTop); builder.Append(Symbols.Angles.LeftTop);
dashboardBuilder.Append(Symbols.Lines.Horizontal.Repeat(halfWidth)); builder.Append(Symbols.Lines.Horizontal.Repeat(halfWidth));
dashboardBuilder.AppendFormat("{0}{1}{0}", Symbols.Space.Repeat(Convert.ToInt32(Indentation.Default)), title); builder.AppendFormat("{0}{1}{0}", Symbols.Space.Repeat(Convert.ToInt32(Indentation.Default)), title);
dashboardBuilder.Append(Symbols.Lines.Horizontal.Repeat(halfWidth)); builder.Append(Symbols.Lines.Horizontal.Repeat(halfWidth));
dashboardBuilder.Append(Symbols.Angles.RightTop); builder.Append(Symbols.Angles.RightTop);
builder.Append(Symbols.LineBreak);
} }
private static void RenderMiddleLine(StringBuilder dashboardBuilder, Size size) private static void RenderMiddleLine(StringBuilder builder, Size size)
{ {
var dashboardHeight = size.Height - (int)Indentation.BorderWidth * 2; var dashboardHeight = size.Height - (int)Indentation.BorderWidth * 2;
while (dashboardHeight > 0) while (dashboardHeight > 0)
{ {
var bodyWidth = size.Width - (int)Indentation.BorderWidth * 2; var bodyWidth = size.Width - (int)Indentation.BorderWidth * 2;
dashboardBuilder.Append(Symbols.Lines.Vertical); builder.Append(Symbols.Lines.Vertical);
dashboardBuilder.Append(Symbols.Space.Repeat(bodyWidth)); builder.Append(Symbols.Space.Repeat(bodyWidth));
dashboardBuilder.Append(Symbols.Lines.Vertical); builder.Append(Symbols.Lines.Vertical);
builder.Append(Symbols.LineBreak);
dashboardHeight--; dashboardHeight--;
} }
} }
private static void RenderBottomLine(StringBuilder dashboardBuilder, Size size) private static void RenderBottomLine(StringBuilder builder, Size size)
{ {
var width = size.Width - (int)Indentation.BorderWidth * 2; var width = size.Width - (int)Indentation.BorderWidth * 2;
dashboardBuilder.Append(Symbols.Angles.LeftBottom); builder.Append(Symbols.Angles.LeftBottom);
dashboardBuilder.Append(Symbols.Lines.Horizontal.Repeat(width)); builder.Append(Symbols.Lines.Horizontal.Repeat(width));
dashboardBuilder.Append(Symbols.Angles.RightBottom); builder.Append(Symbols.Angles.RightBottom);
builder.Append(Symbols.LineBreak);
} }
protected override Sketch DrawComponent() protected override Sketch DrawComponent()
{ {
throw new NotImplementedException(); var builder = new StringBuilder();
var size = new Size(40, 5);
RenderTopLine(builder, size, _title);
RenderMiddleLine(builder, size);
RenderBottomLine(builder, size);
return new Sketch(builder.ToString());
} }
} }

View File

@ -6,7 +6,7 @@ using TUI.UserInterface;
namespace TUI.Components.Controls.Statics.Hints; namespace TUI.Components.Controls.Statics.Hints;
public class AppTypeHints : StaticComponentAttribute public class AppTypeHints : StaticComponentBase
{ {
private readonly Dictionary<string, string> _hints = new() private readonly Dictionary<string, string> _hints = new()
{ {

View File

@ -5,7 +5,7 @@ using TUI.Engine.Theme;
namespace TUI.Components.Controls.Statics.Hints; namespace TUI.Components.Controls.Statics.Hints;
public class HotkeysHint : StaticComponentAttribute public class HotkeysHint : StaticComponentBase
{ {
private readonly Dictionary<string, string> _hints = new() private readonly Dictionary<string, string> _hints = new()
{ {

View File

@ -6,7 +6,7 @@ using TUI.UserInterface;
namespace TUI.Components.Controls.Statics.Hints; namespace TUI.Components.Controls.Statics.Hints;
public class TagHints : StaticComponentAttribute public class TagHints : StaticComponentBase
{ {
private readonly Dictionary<string, string> _hints = new() private readonly Dictionary<string, string> _hints = new()
{ {

View File

@ -5,7 +5,7 @@ using TUI.Engine.Theme;
namespace TUI.Components.Controls.Statics.Hints; namespace TUI.Components.Controls.Statics.Hints;
public class VersionHints : StaticComponentAttribute public class VersionHints : StaticComponentBase
{ {
private readonly Dictionary<string, string> _hints = new() private readonly Dictionary<string, string> _hints = new()
{ {

View File

@ -5,7 +5,7 @@ using TUI.Engine.Theme;
namespace TUI.Components.Controls.Statics; namespace TUI.Components.Controls.Statics;
public class Logo : StaticComponentAttribute public class Logo : StaticComponentBase
{ {
protected override void RenderWithCache(StringBuilder builder) protected override void RenderWithCache(StringBuilder builder)
{ {

View File

@ -8,7 +8,7 @@ using TUI.UserInterface;
namespace TUI.Components.Controls; namespace TUI.Components.Controls;
public class Tag : ComponentAttribute public class Tag : ComponentBase
{ {
private IEnumerable<string> _tags; private IEnumerable<string> _tags;
private string _gitType; private string _gitType;

View File

@ -1,7 +1,9 @@
using TUI.Engine.Attributes.Alignments;
using TUI.Engine.Attributes.Orientations; using TUI.Engine.Attributes.Orientations;
using TUI.Engine.Components; using TUI.Engine.Components;
using TUI.Engine.Containers; using TUI.Engine.Containers;
using TUI.Engine.Nodes; using TUI.Engine.Nodes;
using TUI.Engine.Theme;
namespace TUI.Components.Layouts; namespace TUI.Components.Layouts;
@ -16,23 +18,32 @@ public class DashboardLayout : ContainerBase, IContainer
private INode _header; private INode _header;
private INode _footer; private INode _footer;
private INode _dashboard;
public override Nodes GetNodes() => public override Nodes GetNodes() =>
new() new()
{ {
_header, _footer _header, _dashboard, _footer
}; };
public DashboardLayout AddHeader(IContainer header) public void AddDashboard(IComponent dashboard)
{ {
_header = header; _dashboard = dashboard;
return this;
} }
public DashboardLayout AddFooter(IComponent footer) public void AddHeader(IContainer header)
{ {
header.SetFixed(Orientation.Vertical, 6);
_header = header;
}
public void AddFooter(IComponent footer)
{
footer.SetFixed(Orientation.Vertical, 1);
footer.SetPaddingRight(Level.Normal);
footer.SetAlignment(Horizontal.Right);
footer.SetAlignment(Vertical.Bottom);
_footer = footer; _footer = footer;
return this;
} }
public string Render() public string Render()

View File

@ -7,7 +7,7 @@ using TUI.Engine.Components;
namespace TUI.Components.Views; namespace TUI.Components.Views;
public class DependenciesView : ComponentAttribute, IComponent public class DependenciesView : ComponentBase, IComponent
{ {
private const string ViewName = "Dependencies"; private const string ViewName = "Dependencies";

View File

@ -17,14 +17,14 @@ public class DependenciesPage
ICanvas canvas = new ConsoleCanvas(); ICanvas canvas = new ConsoleCanvas();
var header = new HeaderContainer(); var header = new HeaderContainer();
header.SetFixed(Orientation.Vertical, 6);
var copyright = new Copyright(); var copyright = new Copyright();
copyright.SetPaddingRight(Level.Normal); var dashboard = new Dashboard("Dependencies");
copyright.SetAlignment(Horizontal.Right);
copyright.SetAlignment(Vertical.Bottom); var layout = new DashboardLayout();
layout.AddHeader(header);
layout.AddFooter(copyright);
layout.AddDashboard(dashboard);
var layout = new DashboardLayout().AddHeader(header).AddFooter(copyright);
// CommandLine = new CommandLine(); // CommandLine = new CommandLine();
// DependenciesView = new DependenciesView(); // DependenciesView = new DependenciesView();

View File

@ -6,7 +6,7 @@ using TUI.Engine.Theme;
namespace TUI.Engine.Tests.Components; namespace TUI.Engine.Tests.Components;
public class ComponentAttributeTests public class ComponentBaseTests
{ {
[Fact] [Fact]
[Trait("Category", nameof(IComponent))] [Trait("Category", nameof(IComponent))]

View File

@ -2,7 +2,7 @@ using TUI.Engine.Components;
namespace TUI.Engine.Tests.Stubs; namespace TUI.Engine.Tests.Stubs;
public class TestComponent : ComponentAttribute public class TestComponent : ComponentBase
{ {
private string _content = "Lorem"; private string _content = "Lorem";