mirror of
https://github.com/dnwSilver/tld.git
synced 2024-11-25 16:42:07 +00:00
✨ Add dashboard to deps page.
This commit is contained in:
parent
91555925b6
commit
0dd105679e
@ -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 };
|
@ -2,7 +2,7 @@ using System.Text;
|
||||
|
||||
namespace TUI.Engine.Components;
|
||||
|
||||
public abstract class StaticComponentAttribute : ComponentAttribute
|
||||
public abstract class StaticComponentBase : ComponentBase
|
||||
{
|
||||
private Sketch? _cache;
|
||||
|
@ -25,7 +25,7 @@ public static class Helper
|
||||
|
||||
public static void ShowBackground(Position position, Size size)
|
||||
{
|
||||
return;
|
||||
// return;
|
||||
if (!Colors.Any())
|
||||
{
|
||||
Init();
|
||||
|
@ -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<string> _cells;
|
||||
|
||||
public CellsComponentAttribute(IEnumerable<string> cells)
|
||||
public CellsComponentBase(IEnumerable<string> cells)
|
||||
{
|
||||
_cells = cells;
|
||||
}
|
@ -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)
|
||||
{
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using TUI.UserInterface;
|
||||
|
||||
namespace TUI.Components.Controls.Statics.Hints;
|
||||
|
||||
public class AppTypeHints : StaticComponentAttribute
|
||||
public class AppTypeHints : StaticComponentBase
|
||||
{
|
||||
private readonly Dictionary<string, string> _hints = new()
|
||||
{
|
||||
|
@ -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<string, string> _hints = new()
|
||||
{
|
||||
|
@ -6,7 +6,7 @@ using TUI.UserInterface;
|
||||
|
||||
namespace TUI.Components.Controls.Statics.Hints;
|
||||
|
||||
public class TagHints : StaticComponentAttribute
|
||||
public class TagHints : StaticComponentBase
|
||||
{
|
||||
private readonly Dictionary<string, string> _hints = new()
|
||||
{
|
||||
|
@ -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<string, string> _hints = new()
|
||||
{
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -8,7 +8,7 @@ using TUI.UserInterface;
|
||||
|
||||
namespace TUI.Components.Controls;
|
||||
|
||||
public class Tag : ComponentAttribute
|
||||
public class Tag : ComponentBase
|
||||
{
|
||||
private IEnumerable<string> _tags;
|
||||
private string _gitType;
|
||||
|
@ -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()
|
||||
|
@ -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";
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -6,7 +6,7 @@ using TUI.Engine.Theme;
|
||||
|
||||
namespace TUI.Engine.Tests.Components;
|
||||
|
||||
public class ComponentAttributeTests
|
||||
public class ComponentBaseTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", nameof(IComponent))]
|
@ -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";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user