mirror of
https://github.com/dnwSilver/tld.git
synced 2024-11-25 16:42:07 +00:00
✨ Add min size to component.
This commit is contained in:
parent
0dd105679e
commit
268c25e604
@ -1,3 +1,4 @@
|
|||||||
|
using TUI.Engine.Attributes;
|
||||||
using TUI.Engine.Attributes.Alignments;
|
using TUI.Engine.Attributes.Alignments;
|
||||||
using TUI.Engine.Attributes.Paddings;
|
using TUI.Engine.Attributes.Paddings;
|
||||||
using TUI.Engine.Nodes;
|
using TUI.Engine.Nodes;
|
||||||
@ -7,9 +8,9 @@ namespace TUI.Engine.Components;
|
|||||||
|
|
||||||
public abstract class ComponentBase : NodeBase, IComponent
|
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
|
#region Alignments
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using TUI.Engine.Attributes;
|
||||||
using TUI.Engine.Attributes.Alignments;
|
using TUI.Engine.Attributes.Alignments;
|
||||||
using TUI.Engine.Attributes.Paddings;
|
using TUI.Engine.Attributes.Paddings;
|
||||||
using TUI.Engine.Nodes;
|
using TUI.Engine.Nodes;
|
||||||
@ -6,5 +7,5 @@ namespace TUI.Engine.Components;
|
|||||||
|
|
||||||
public interface IComponent : INode, IWithAlignment, IWithPadding
|
public interface IComponent : INode, IWithAlignment, IWithPadding
|
||||||
{
|
{
|
||||||
internal Sketch MakeSketch();
|
internal Sketch MakeSketch(Size minSize);
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
|
using TUI.Engine.Attributes;
|
||||||
|
|
||||||
namespace TUI.Engine.Components;
|
namespace TUI.Engine.Components;
|
||||||
|
|
||||||
@ -8,7 +9,7 @@ public abstract class StaticComponentBase : ComponentBase
|
|||||||
|
|
||||||
protected abstract void RenderWithCache(StringBuilder builder);
|
protected abstract void RenderWithCache(StringBuilder builder);
|
||||||
|
|
||||||
protected override Sketch DrawComponent()
|
protected override Sketch DrawComponent(Size sketchMinSize)
|
||||||
{
|
{
|
||||||
if (_cache is not null)
|
if (_cache is not null)
|
||||||
{
|
{
|
||||||
|
@ -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();
|
||||||
|
@ -16,7 +16,7 @@ internal sealed class ComponentCraftsman : CraftsmanBase, IDrawable<IComponent>
|
|||||||
|
|
||||||
public Size Draw(IComponent component, Position pencil, Size maxSize)
|
public Size Draw(IComponent component, Position pencil, Size maxSize)
|
||||||
{
|
{
|
||||||
var sketch = component.MakeSketch();
|
var sketch = component.MakeSketch(maxSize);
|
||||||
var sketchSize = sketch.GetSize();
|
var sketchSize = sketch.GetSize();
|
||||||
|
|
||||||
var correctedPencil = component.CorrectContentPosition(pencil, maxSize, sketchSize);
|
var correctedPencil = component.CorrectContentPosition(pencil, maxSize, sketchSize);
|
||||||
|
@ -29,7 +29,7 @@ public class CellsComponentBase : ComponentBase, IComponent
|
|||||||
// base.Render(content, position, size);
|
// base.Render(content, position, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Sketch DrawComponent()
|
protected override Sketch DrawComponent(Size minSize)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using TUI.Engine;
|
using TUI.Engine;
|
||||||
using TUI.Engine.Attributes;
|
using TUI.Engine.Attributes;
|
||||||
using TUI.Engine.Attributes.Alignments;
|
|
||||||
using TUI.Engine.Components;
|
using TUI.Engine.Components;
|
||||||
using TUI.Engine.Theme;
|
using TUI.Engine.Theme;
|
||||||
|
|
||||||
@ -53,16 +52,14 @@ public class Dashboard : ComponentBase, IComponent
|
|||||||
builder.Append(Symbols.LineBreak);
|
builder.Append(Symbols.LineBreak);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Sketch DrawComponent()
|
protected override Sketch DrawComponent(Size minSize)
|
||||||
{
|
{
|
||||||
var builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
|
|
||||||
var size = new Size(40, 5);
|
RenderTopLine(builder, minSize, _title);
|
||||||
|
RenderMiddleLine(builder, minSize);
|
||||||
|
RenderBottomLine(builder, minSize);
|
||||||
|
|
||||||
RenderTopLine(builder, size, _title);
|
return new Sketch(builder.ToString().Main());
|
||||||
RenderMiddleLine(builder, size);
|
|
||||||
RenderBottomLine(builder, size);
|
|
||||||
|
|
||||||
return new Sketch(builder.ToString());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -54,7 +54,7 @@ public class Tag : ComponentBase
|
|||||||
_ => Symbols.Git
|
_ => Symbols.Git
|
||||||
};
|
};
|
||||||
|
|
||||||
protected override Sketch DrawComponent()
|
protected override Sketch DrawComponent(Size minSize)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -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<DependencyDto> 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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
namespace TUI.Domain;
|
|
||||||
|
|
||||||
public record DevelopmentStack(string Name, char Icon);
|
|
@ -1,10 +1,7 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using TUI.Components.Controls;
|
using TUI.Components.Controls;
|
||||||
using TUI.Components.Layouts;
|
using TUI.Components.Layouts;
|
||||||
using TUI.Engine.Attributes.Alignments;
|
|
||||||
using TUI.Engine.Attributes.Orientations;
|
|
||||||
using TUI.Engine.Rendering.Canvas;
|
using TUI.Engine.Rendering.Canvas;
|
||||||
using TUI.Engine.Theme;
|
|
||||||
|
|
||||||
namespace TUI.Pages;
|
namespace TUI.Pages;
|
||||||
|
|
||||||
@ -19,12 +16,10 @@ public class DependenciesPage
|
|||||||
var header = new HeaderContainer();
|
var header = new HeaderContainer();
|
||||||
var copyright = new Copyright();
|
var copyright = new Copyright();
|
||||||
var dashboard = new Dashboard("Dependencies");
|
var dashboard = new Dashboard("Dependencies");
|
||||||
|
|
||||||
var layout = new DashboardLayout();
|
var layout = new DashboardLayout();
|
||||||
layout.AddHeader(header);
|
layout.AddHeader(header);
|
||||||
layout.AddFooter(copyright);
|
layout.AddFooter(copyright);
|
||||||
layout.AddDashboard(dashboard);
|
layout.AddDashboard(dashboard);
|
||||||
|
|
||||||
// CommandLine = new CommandLine();
|
// CommandLine = new CommandLine();
|
||||||
// DependenciesView = new DependenciesView();
|
// DependenciesView = new DependenciesView();
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
using TUI.Engine.Attributes;
|
||||||
using TUI.Engine.Components;
|
using TUI.Engine.Components;
|
||||||
|
|
||||||
namespace TUI.Engine.Tests.Stubs;
|
namespace TUI.Engine.Tests.Stubs;
|
||||||
@ -11,7 +12,7 @@ public class TestComponent : ComponentBase
|
|||||||
_content = content;
|
_content = content;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Sketch DrawComponent()
|
protected override Sketch DrawComponent(Size minSize)
|
||||||
{
|
{
|
||||||
return new Sketch(_content);
|
return new Sketch(_content);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user