From 0dd105679ed7dd601e5314d01304a8201cfa7067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=80=20?= =?UTF-8?q?=D0=9A=D0=BE=D0=BB=D0=BE=D1=81=D0=BE=D0=B2?= Date: Sun, 17 Mar 2024 01:31:13 +0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20dashboard=20to=20deps=20page.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ComponentAttribute.cs => ComponentBase.cs} | 21 +++----- ...entAttribute.cs => StaticComponentBase.cs} | 2 +- src/TUI.Engine/Helper.cs | 2 +- ...nentAttribute.cs => CellsComponentBase.cs} | 4 +- src/TUI/Components/Controls/Copyright.cs | 2 +- src/TUI/Components/Controls/Dashboard.cs | 54 +++++++++---------- .../Controls/Statics/Hints/AppTypeHints.cs | 2 +- .../Controls/Statics/Hints/HotkeysHint.cs | 2 +- .../Controls/Statics/Hints/TagHints.cs | 2 +- .../Controls/Statics/Hints/VersionHints.cs | 2 +- src/TUI/Components/Controls/Statics/Logo.cs | 2 +- src/TUI/Components/Controls/Tag.cs | 2 +- src/TUI/Components/Layouts/DashboardLayout.cs | 23 +++++--- src/TUI/Components/Views/DependenciesView.cs | 2 +- src/TUI/Pages/DependenciesPage.cs | 12 ++--- ...ttributeTests.cs => ComponentBaseTests.cs} | 2 +- tests/TUI.Engine.Tests/Stubs/TestComponent.cs | 2 +- 17 files changed, 71 insertions(+), 67 deletions(-) rename src/TUI.Engine/Components/{ComponentAttribute.cs => ComponentBase.cs} (77%) rename src/TUI.Engine/Components/{StaticComponentAttribute.cs => StaticComponentBase.cs} (86%) rename src/TUI/Components/Controls/{CellsComponentAttribute.cs => CellsComponentBase.cs} (84%) rename tests/TUI.Engine.Tests/Components/{ComponentAttributeTests.cs => ComponentBaseTests.cs} (98%) diff --git a/src/TUI.Engine/Components/ComponentAttribute.cs b/src/TUI.Engine/Components/ComponentBase.cs similarity index 77% rename from src/TUI.Engine/Components/ComponentAttribute.cs rename to src/TUI.Engine/Components/ComponentBase.cs index 949c8cc..4dedf09 100644 --- a/src/TUI.Engine/Components/ComponentAttribute.cs +++ b/src/TUI.Engine/Components/ComponentBase.cs @@ -5,7 +5,7 @@ using TUI.Engine.Theme; namespace TUI.Engine.Components; -public abstract class ComponentAttribute : NodeBase, IComponent +public abstract class ComponentBase : NodeBase, IComponent { protected abstract Sketch DrawComponent(); @@ -13,29 +13,22 @@ public abstract class ComponentAttribute : NodeBase, IComponent #region Alignments - internal Alignment Alignment { get; private set; } = new(Defaults.HorizontalAlignment, Defaults.VerticalAlignment); - Alignment IWithAlignment.Alignment => Alignment; - public void SetAlignment(Vertical vertical) - { - Alignment = Alignment with { Vertical = vertical }; - } + internal Alignment Alignment { get; private set; } = new(Defaults.HorizontalAlignment, Defaults.VerticalAlignment); - public void SetAlignment(Horizontal horizontal) - { - Alignment = Alignment with { Horizontal = horizontal }; - } + public void SetAlignment(Vertical vertical) => Alignment = Alignment with { Vertical = vertical }; + + public void SetAlignment(Horizontal horizontal) => Alignment = Alignment with { Horizontal = horizontal }; #endregion #region Paddings - internal Padding Padding { get; private set; } = new(Defaults.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 SetPaddingTop(Level level) => Padding = Padding with { Top = level }; diff --git a/src/TUI.Engine/Components/StaticComponentAttribute.cs b/src/TUI.Engine/Components/StaticComponentBase.cs similarity index 86% rename from src/TUI.Engine/Components/StaticComponentAttribute.cs rename to src/TUI.Engine/Components/StaticComponentBase.cs index 50c4b24..8b5285c 100644 --- a/src/TUI.Engine/Components/StaticComponentAttribute.cs +++ b/src/TUI.Engine/Components/StaticComponentBase.cs @@ -2,7 +2,7 @@ using System.Text; namespace TUI.Engine.Components; -public abstract class StaticComponentAttribute : ComponentAttribute +public abstract class StaticComponentBase : ComponentBase { private Sketch? _cache; diff --git a/src/TUI.Engine/Helper.cs b/src/TUI.Engine/Helper.cs index b63adc9..64e6f36 100644 --- a/src/TUI.Engine/Helper.cs +++ b/src/TUI.Engine/Helper.cs @@ -25,7 +25,7 @@ public static class Helper public static void ShowBackground(Position position, Size size) { - return; + // return; if (!Colors.Any()) { Init(); diff --git a/src/TUI/Components/Controls/CellsComponentAttribute.cs b/src/TUI/Components/Controls/CellsComponentBase.cs similarity index 84% rename from src/TUI/Components/Controls/CellsComponentAttribute.cs rename to src/TUI/Components/Controls/CellsComponentBase.cs index de7f9b5..b1c25b3 100644 --- a/src/TUI/Components/Controls/CellsComponentAttribute.cs +++ b/src/TUI/Components/Controls/CellsComponentBase.cs @@ -6,13 +6,13 @@ using TUI.Engine.Components; namespace TUI.Components.Controls; -public class CellsComponentAttribute : ComponentAttribute, IComponent +public class CellsComponentBase : ComponentBase, IComponent { private const int MaxCellWidth = 10; private readonly IEnumerable _cells; - public CellsComponentAttribute(IEnumerable cells) + public CellsComponentBase(IEnumerable cells) { _cells = cells; } diff --git a/src/TUI/Components/Controls/Copyright.cs b/src/TUI/Components/Controls/Copyright.cs index c7d6e1b..eaf419e 100644 --- a/src/TUI/Components/Controls/Copyright.cs +++ b/src/TUI/Components/Controls/Copyright.cs @@ -5,7 +5,7 @@ using TUI.Engine.Theme; namespace TUI.Components.Controls; -public class Copyright : StaticComponentAttribute +public class Copyright : StaticComponentBase { protected override void RenderWithCache(StringBuilder builder) { diff --git a/src/TUI/Components/Controls/Dashboard.cs b/src/TUI/Components/Controls/Dashboard.cs index b5eae7b..c0ba041 100644 --- a/src/TUI/Components/Controls/Dashboard.cs +++ b/src/TUI/Components/Controls/Dashboard.cs @@ -7,7 +7,7 @@ using TUI.Engine.Theme; namespace TUI.Components.Controls; -public class Dashboard : ComponentAttribute, IComponent +public class Dashboard : ComponentBase, IComponent { private readonly string _title; @@ -16,53 +16,53 @@ public class Dashboard : ComponentAttribute, IComponent _title = title; } - public void Render(Horizontal horizontal, Size size) - { - 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) + private static void RenderTopLine(StringBuilder builder, Size size, string title) { var halfWidth = (size.Width - title.GetWidth() - (int)Indentation.BorderWidth * 2 - (int)Indentation.Default * 2) / 2; - dashboardBuilder.Append(Symbols.Angles.LeftTop); - dashboardBuilder.Append(Symbols.Lines.Horizontal.Repeat(halfWidth)); - dashboardBuilder.AppendFormat("{0}{1}{0}", Symbols.Space.Repeat(Convert.ToInt32(Indentation.Default)), title); - dashboardBuilder.Append(Symbols.Lines.Horizontal.Repeat(halfWidth)); - dashboardBuilder.Append(Symbols.Angles.RightTop); + builder.Append(Symbols.Angles.LeftTop); + builder.Append(Symbols.Lines.Horizontal.Repeat(halfWidth)); + builder.AppendFormat("{0}{1}{0}", Symbols.Space.Repeat(Convert.ToInt32(Indentation.Default)), title); + builder.Append(Symbols.Lines.Horizontal.Repeat(halfWidth)); + 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; while (dashboardHeight > 0) { var bodyWidth = size.Width - (int)Indentation.BorderWidth * 2; - dashboardBuilder.Append(Symbols.Lines.Vertical); - dashboardBuilder.Append(Symbols.Space.Repeat(bodyWidth)); - dashboardBuilder.Append(Symbols.Lines.Vertical); + builder.Append(Symbols.Lines.Vertical); + builder.Append(Symbols.Space.Repeat(bodyWidth)); + builder.Append(Symbols.Lines.Vertical); + builder.Append(Symbols.LineBreak); 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; - dashboardBuilder.Append(Symbols.Angles.LeftBottom); - dashboardBuilder.Append(Symbols.Lines.Horizontal.Repeat(width)); - dashboardBuilder.Append(Symbols.Angles.RightBottom); + builder.Append(Symbols.Angles.LeftBottom); + builder.Append(Symbols.Lines.Horizontal.Repeat(width)); + builder.Append(Symbols.Angles.RightBottom); + builder.Append(Symbols.LineBreak); } 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()); } } \ No newline at end of file diff --git a/src/TUI/Components/Controls/Statics/Hints/AppTypeHints.cs b/src/TUI/Components/Controls/Statics/Hints/AppTypeHints.cs index 381defc..2f7d959 100644 --- a/src/TUI/Components/Controls/Statics/Hints/AppTypeHints.cs +++ b/src/TUI/Components/Controls/Statics/Hints/AppTypeHints.cs @@ -6,7 +6,7 @@ using TUI.UserInterface; namespace TUI.Components.Controls.Statics.Hints; -public class AppTypeHints : StaticComponentAttribute +public class AppTypeHints : StaticComponentBase { private readonly Dictionary _hints = new() { diff --git a/src/TUI/Components/Controls/Statics/Hints/HotkeysHint.cs b/src/TUI/Components/Controls/Statics/Hints/HotkeysHint.cs index 1d780b5..12c80ba 100644 --- a/src/TUI/Components/Controls/Statics/Hints/HotkeysHint.cs +++ b/src/TUI/Components/Controls/Statics/Hints/HotkeysHint.cs @@ -5,7 +5,7 @@ using TUI.Engine.Theme; namespace TUI.Components.Controls.Statics.Hints; -public class HotkeysHint : StaticComponentAttribute +public class HotkeysHint : StaticComponentBase { private readonly Dictionary _hints = new() { diff --git a/src/TUI/Components/Controls/Statics/Hints/TagHints.cs b/src/TUI/Components/Controls/Statics/Hints/TagHints.cs index 75680b7..766f52f 100644 --- a/src/TUI/Components/Controls/Statics/Hints/TagHints.cs +++ b/src/TUI/Components/Controls/Statics/Hints/TagHints.cs @@ -6,7 +6,7 @@ using TUI.UserInterface; namespace TUI.Components.Controls.Statics.Hints; -public class TagHints : StaticComponentAttribute +public class TagHints : StaticComponentBase { private readonly Dictionary _hints = new() { diff --git a/src/TUI/Components/Controls/Statics/Hints/VersionHints.cs b/src/TUI/Components/Controls/Statics/Hints/VersionHints.cs index 4237e18..ee49809 100644 --- a/src/TUI/Components/Controls/Statics/Hints/VersionHints.cs +++ b/src/TUI/Components/Controls/Statics/Hints/VersionHints.cs @@ -5,7 +5,7 @@ using TUI.Engine.Theme; namespace TUI.Components.Controls.Statics.Hints; -public class VersionHints : StaticComponentAttribute +public class VersionHints : StaticComponentBase { private readonly Dictionary _hints = new() { diff --git a/src/TUI/Components/Controls/Statics/Logo.cs b/src/TUI/Components/Controls/Statics/Logo.cs index f63944e..bed96db 100644 --- a/src/TUI/Components/Controls/Statics/Logo.cs +++ b/src/TUI/Components/Controls/Statics/Logo.cs @@ -5,7 +5,7 @@ using TUI.Engine.Theme; namespace TUI.Components.Controls.Statics; -public class Logo : StaticComponentAttribute +public class Logo : StaticComponentBase { protected override void RenderWithCache(StringBuilder builder) { diff --git a/src/TUI/Components/Controls/Tag.cs b/src/TUI/Components/Controls/Tag.cs index 8c8d443..8afe3ce 100644 --- a/src/TUI/Components/Controls/Tag.cs +++ b/src/TUI/Components/Controls/Tag.cs @@ -8,7 +8,7 @@ using TUI.UserInterface; namespace TUI.Components.Controls; -public class Tag : ComponentAttribute +public class Tag : ComponentBase { private IEnumerable _tags; private string _gitType; diff --git a/src/TUI/Components/Layouts/DashboardLayout.cs b/src/TUI/Components/Layouts/DashboardLayout.cs index 0b1ff26..fefa559 100644 --- a/src/TUI/Components/Layouts/DashboardLayout.cs +++ b/src/TUI/Components/Layouts/DashboardLayout.cs @@ -1,7 +1,9 @@ +using TUI.Engine.Attributes.Alignments; using TUI.Engine.Attributes.Orientations; using TUI.Engine.Components; using TUI.Engine.Containers; using TUI.Engine.Nodes; +using TUI.Engine.Theme; namespace TUI.Components.Layouts; @@ -16,23 +18,32 @@ public class DashboardLayout : ContainerBase, IContainer private INode _header; private INode _footer; + private INode _dashboard; public override Nodes GetNodes() => new() { - _header, _footer + _header, _dashboard, _footer }; - public DashboardLayout AddHeader(IContainer header) + public void AddDashboard(IComponent dashboard) { - _header = header; - return this; + _dashboard = dashboard; } - 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; - return this; } public string Render() diff --git a/src/TUI/Components/Views/DependenciesView.cs b/src/TUI/Components/Views/DependenciesView.cs index 5ef6bdd..1e0e934 100644 --- a/src/TUI/Components/Views/DependenciesView.cs +++ b/src/TUI/Components/Views/DependenciesView.cs @@ -7,7 +7,7 @@ using TUI.Engine.Components; namespace TUI.Components.Views; -public class DependenciesView : ComponentAttribute, IComponent +public class DependenciesView : ComponentBase, IComponent { private const string ViewName = "Dependencies"; diff --git a/src/TUI/Pages/DependenciesPage.cs b/src/TUI/Pages/DependenciesPage.cs index ca97f42..6eb8c37 100644 --- a/src/TUI/Pages/DependenciesPage.cs +++ b/src/TUI/Pages/DependenciesPage.cs @@ -17,14 +17,14 @@ public class DependenciesPage ICanvas canvas = new ConsoleCanvas(); var header = new HeaderContainer(); - header.SetFixed(Orientation.Vertical, 6); - var copyright = new Copyright(); - copyright.SetPaddingRight(Level.Normal); - copyright.SetAlignment(Horizontal.Right); - copyright.SetAlignment(Vertical.Bottom); + var dashboard = new Dashboard("Dependencies"); + + var layout = new DashboardLayout(); + layout.AddHeader(header); + layout.AddFooter(copyright); + layout.AddDashboard(dashboard); - var layout = new DashboardLayout().AddHeader(header).AddFooter(copyright); // CommandLine = new CommandLine(); // DependenciesView = new DependenciesView(); diff --git a/tests/TUI.Engine.Tests/Components/ComponentAttributeTests.cs b/tests/TUI.Engine.Tests/Components/ComponentBaseTests.cs similarity index 98% rename from tests/TUI.Engine.Tests/Components/ComponentAttributeTests.cs rename to tests/TUI.Engine.Tests/Components/ComponentBaseTests.cs index 33797d0..5f2c32a 100644 --- a/tests/TUI.Engine.Tests/Components/ComponentAttributeTests.cs +++ b/tests/TUI.Engine.Tests/Components/ComponentBaseTests.cs @@ -6,7 +6,7 @@ using TUI.Engine.Theme; namespace TUI.Engine.Tests.Components; -public class ComponentAttributeTests +public class ComponentBaseTests { [Fact] [Trait("Category", nameof(IComponent))] diff --git a/tests/TUI.Engine.Tests/Stubs/TestComponent.cs b/tests/TUI.Engine.Tests/Stubs/TestComponent.cs index 1d4be6c..069f191 100644 --- a/tests/TUI.Engine.Tests/Stubs/TestComponent.cs +++ b/tests/TUI.Engine.Tests/Stubs/TestComponent.cs @@ -2,7 +2,7 @@ using TUI.Engine.Components; namespace TUI.Engine.Tests.Stubs; -public class TestComponent : ComponentAttribute +public class TestComponent : ComponentBase { private string _content = "Lorem";