diff --git a/src/TUI.Engine/Components/ComponentBase.cs b/src/TUI.Engine/Components/ComponentBase.cs index 4dedf09..121a059 100644 --- a/src/TUI.Engine/Components/ComponentBase.cs +++ b/src/TUI.Engine/Components/ComponentBase.cs @@ -1,3 +1,4 @@ +using TUI.Engine.Attributes; using TUI.Engine.Attributes.Alignments; using TUI.Engine.Attributes.Paddings; using TUI.Engine.Nodes; @@ -7,9 +8,9 @@ namespace TUI.Engine.Components; public abstract class ComponentBase : NodeBase, IComponent { - protected abstract Sketch DrawComponent(); + protected abstract Sketch DrawComponent(Size minSize); - Sketch IComponent.MakeSketch() => DrawComponent(); + Sketch IComponent.MakeSketch(Size minSize) => DrawComponent(minSize); #region Alignments diff --git a/src/TUI.Engine/Components/IComponent.cs b/src/TUI.Engine/Components/IComponent.cs index b990aca..1beb97f 100644 --- a/src/TUI.Engine/Components/IComponent.cs +++ b/src/TUI.Engine/Components/IComponent.cs @@ -1,3 +1,4 @@ +using TUI.Engine.Attributes; using TUI.Engine.Attributes.Alignments; using TUI.Engine.Attributes.Paddings; using TUI.Engine.Nodes; @@ -6,5 +7,5 @@ namespace TUI.Engine.Components; public interface IComponent : INode, IWithAlignment, IWithPadding { - internal Sketch MakeSketch(); + internal Sketch MakeSketch(Size minSize); } \ No newline at end of file diff --git a/src/TUI.Engine/Components/StaticComponentBase.cs b/src/TUI.Engine/Components/StaticComponentBase.cs index 8b5285c..009d388 100644 --- a/src/TUI.Engine/Components/StaticComponentBase.cs +++ b/src/TUI.Engine/Components/StaticComponentBase.cs @@ -1,4 +1,5 @@ using System.Text; +using TUI.Engine.Attributes; namespace TUI.Engine.Components; @@ -8,7 +9,7 @@ public abstract class StaticComponentBase : ComponentBase protected abstract void RenderWithCache(StringBuilder builder); - protected override Sketch DrawComponent() + protected override Sketch DrawComponent(Size sketchMinSize) { if (_cache is not null) { diff --git a/src/TUI.Engine/Helper.cs b/src/TUI.Engine/Helper.cs index 64e6f36..b63adc9 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.Engine/Rendering/ComponentCraftsman.cs b/src/TUI.Engine/Rendering/ComponentCraftsman.cs index 6d03a26..70f4044 100644 --- a/src/TUI.Engine/Rendering/ComponentCraftsman.cs +++ b/src/TUI.Engine/Rendering/ComponentCraftsman.cs @@ -16,7 +16,7 @@ internal sealed class ComponentCraftsman : CraftsmanBase, IDrawable public Size Draw(IComponent component, Position pencil, Size maxSize) { - var sketch = component.MakeSketch(); + var sketch = component.MakeSketch(maxSize); var sketchSize = sketch.GetSize(); var correctedPencil = component.CorrectContentPosition(pencil, maxSize, sketchSize); diff --git a/src/TUI/Components/Controls/CellsComponentBase.cs b/src/TUI/Components/Controls/CellsComponentBase.cs index b1c25b3..c22e157 100644 --- a/src/TUI/Components/Controls/CellsComponentBase.cs +++ b/src/TUI/Components/Controls/CellsComponentBase.cs @@ -29,7 +29,7 @@ public class CellsComponentBase : ComponentBase, IComponent // base.Render(content, position, size); } - protected override Sketch DrawComponent() + protected override Sketch DrawComponent(Size minSize) { throw new NotImplementedException(); } diff --git a/src/TUI/Components/Controls/Dashboard.cs b/src/TUI/Components/Controls/Dashboard.cs index c0ba041..7e1f75f 100644 --- a/src/TUI/Components/Controls/Dashboard.cs +++ b/src/TUI/Components/Controls/Dashboard.cs @@ -1,7 +1,6 @@ using System.Text; using TUI.Engine; using TUI.Engine.Attributes; -using TUI.Engine.Attributes.Alignments; using TUI.Engine.Components; using TUI.Engine.Theme; @@ -53,16 +52,14 @@ public class Dashboard : ComponentBase, IComponent builder.Append(Symbols.LineBreak); } - protected override Sketch DrawComponent() + protected override Sketch DrawComponent(Size minSize) { var builder = new StringBuilder(); - var size = new Size(40, 5); + RenderTopLine(builder, minSize, _title); + RenderMiddleLine(builder, minSize); + RenderBottomLine(builder, minSize); - RenderTopLine(builder, size, _title); - RenderMiddleLine(builder, size); - RenderBottomLine(builder, size); - - return new Sketch(builder.ToString()); + return new Sketch(builder.ToString().Main()); } } \ No newline at end of file diff --git a/src/TUI/Components/Controls/Tag.cs b/src/TUI/Components/Controls/Tag.cs index 8afe3ce..45d76e7 100644 --- a/src/TUI/Components/Controls/Tag.cs +++ b/src/TUI/Components/Controls/Tag.cs @@ -54,7 +54,7 @@ public class Tag : ComponentBase _ => Symbols.Git }; - protected override Sketch DrawComponent() + protected override Sketch DrawComponent(Size minSize) { throw new NotImplementedException(); } diff --git a/src/TUI/Components/Views/DependenciesView.cs b/src/TUI/Components/Views/DependenciesView.cs deleted file mode 100644 index 1e0e934..0000000 --- a/src/TUI/Components/Views/DependenciesView.cs +++ /dev/null @@ -1,160 +0,0 @@ -using TUI.Components.Controls; -using TUI.Domain; -using TUI.Engine; -using TUI.Engine.Attributes; -using TUI.Engine.Attributes.Alignments; -using TUI.Engine.Components; - -namespace TUI.Components.Views; - -public class DependenciesView : ComponentBase, IComponent -{ - private const string ViewName = "Dependencies"; - - private DevelopmentStack _developmentStack; - - public void Bind(DevelopmentStack developmentStack) - { - _developmentStack = developmentStack; - } - - public void Render(Horizontal horizontal, Size size) - { - var dashboardTitle = _developmentStack.Icon + Symbols.Space + ViewName; - var dashboard = new Dashboard(dashboardTitle); - - // Add(dashboard); - } - - // private const int TitleWidth = 25; - // private const int ColumnWidth = 10; - - // private readonly DashboardControl _dashboard = new(); - - // public bool IsFocused - // { - // get => _dashboard.IsFocused; - // set => _dashboard.IsFocused = value; - // } - - // public void Render(ProjectDto projectDto, ControlPosition position) - // { - // _dashboard.Render(projectDto.Icon + " Dependencies", position); - // var header = projectDto.Dependencies.Select(GetConventionVersion).ToArray(); - // var rows = projectDto.Sources.Select(GetTitle).ToArray(); - // - // var tablePosition = new ControlPosition( - // position.Left + Theme.BorderWidth, - // position.Top + Theme.BorderWidth); - // - // var tableProps = new TableProps(header, rows, TitleWidth, ColumnWidth); - // _table.Render(tableProps, tablePosition); - // - // for (var rowId = 0; rowId < rows.Length; rowId++) - // { - // var actualDependencies = GetDependencies(projectDto.Sources[rowId], projectDto.Dependencies); - // _table.RenderRow(rowId + 1, rows[rowId] + actualDependencies); - // } - // } - - // private static string GetDependencies(SourceDto sourceDto, IEnumerable conventionDependencies) - // { - // try - // { - // var package = DownloadPackage(sourceDto); - // - // return string.Join("", - // conventionDependencies - // .Select(dependency => GetVersion(dependency, package)) - // .Select(RenderCurrentVersion)); - // } - // catch (HttpRequestException exception) - // { - // switch (exception.StatusCode) - // { - // case HttpStatusCode.BadRequest: - // return " Request have errors.".Pastel(Palette.ErrorColor); - // case HttpStatusCode.Forbidden: - // return " Not enough rights.".Pastel(Palette.ErrorColor); - // case HttpStatusCode.NotFound: - // return " Repository or branch master not found.".Pastel(Palette.ErrorColor); - // } - // - // throw; - // } - // catch (Exception exception) - // { - // Debugger.Break(); - // return "󰋔 We tried to send a request but couldn't. Check your configuration.".Pastel(Palette.ErrorColor); - // } - // } - // - // private static string GetVersion(DependencyDto dependency, Package package) - // { - // var currentVersion = package.ParseVersion(dependency.Name); - // - // if (currentVersion == null) return Icons.NotFound; - // - // var conventionVersion = dependency.Version?.ToVersion(); - // return PaintingVersion(currentVersion, conventionVersion); - // } - // - // private static string PaintingVersion(Version current, Version? convention) - // { - // var textVersion = current.ToString(); - // - // if (current > convention) return textVersion.Info(); - // - // if (current < convention) - // return current.Major == convention.Major ? textVersion.Primary() : textVersion.Warning(); - // - // return textVersion.Hint(); - // } - // - // private static string GetConventionVersion(DependencyDto dependencyDto) - // { - // return dependencyDto.Icon.Pastel(dependencyDto.Color) + dependencyDto.Version.Primary(); - // } - // - // private static string RenderCurrentVersion(string version) - // { - // var versionWidth = version.Width(); - // if (versionWidth == 0) return ' '.Repeat(ColumnWidth - 1) + Icons.NotFound.Hint(); - // - // return ' '.Repeat(ColumnWidth - versionWidth) + version; - // } - // - // private static string GetTitle(SourceDto sourceDto) - // { - // var title = ""; - // - // title += RenderPadding(); - // title += RenderTags(sourceDto); - // if (title.Width() + sourceDto.Name.Length + Theme.Padding <= TitleWidth) - // { - // title += sourceDto.Name; - // } - // else - // { - // var maxNameWidth = TitleWidth - title.Width() - Theme.Padding; - // title += $"{sourceDto.Name[..(maxNameWidth - 1)]}{"#".Hint()}"; - // } - // - // title += RenderPadding(); - // return $"{title}{' '.Repeat(TitleWidth - title.Width())}"; - // } - // - // public void Next() - // { - // _table.Next(); - // } - // - // public void Previous() - // { - // _table.Previous(); - // } - protected override Sketch DrawComponent() - { - throw new NotImplementedException(); - } -} \ No newline at end of file diff --git a/src/TUI/Domain/DevelopmentStack.cs b/src/TUI/Domain/DevelopmentStack.cs deleted file mode 100644 index e24631b..0000000 --- a/src/TUI/Domain/DevelopmentStack.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace TUI.Domain; - -public record DevelopmentStack(string Name, char Icon); \ No newline at end of file diff --git a/src/TUI/Pages/DependenciesPage.cs b/src/TUI/Pages/DependenciesPage.cs index 6eb8c37..164d5e1 100644 --- a/src/TUI/Pages/DependenciesPage.cs +++ b/src/TUI/Pages/DependenciesPage.cs @@ -1,10 +1,7 @@ using System.Diagnostics; using TUI.Components.Controls; using TUI.Components.Layouts; -using TUI.Engine.Attributes.Alignments; -using TUI.Engine.Attributes.Orientations; using TUI.Engine.Rendering.Canvas; -using TUI.Engine.Theme; namespace TUI.Pages; @@ -19,12 +16,10 @@ public class DependenciesPage var header = new HeaderContainer(); var copyright = new Copyright(); var dashboard = new Dashboard("Dependencies"); - var layout = new DashboardLayout(); layout.AddHeader(header); layout.AddFooter(copyright); layout.AddDashboard(dashboard); - // CommandLine = new CommandLine(); // DependenciesView = new DependenciesView(); diff --git a/tests/TUI.Engine.Tests/Stubs/TestComponent.cs b/tests/TUI.Engine.Tests/Stubs/TestComponent.cs index 069f191..e574c1f 100644 --- a/tests/TUI.Engine.Tests/Stubs/TestComponent.cs +++ b/tests/TUI.Engine.Tests/Stubs/TestComponent.cs @@ -1,3 +1,4 @@ +using TUI.Engine.Attributes; using TUI.Engine.Components; namespace TUI.Engine.Tests.Stubs; @@ -11,7 +12,7 @@ public class TestComponent : ComponentBase _content = content; } - protected override Sketch DrawComponent() + protected override Sketch DrawComponent(Size minSize) { return new Sketch(_content); }