♻️ Rename classes.

This commit is contained in:
Kolosov Alexandr 2024-03-09 01:48:16 +05:00
parent 074365652d
commit 3b56c7207b
29 changed files with 279 additions and 164 deletions

View File

@ -12,13 +12,12 @@ public class CellsComponentBase : ComponentBase, IComponent
private readonly IEnumerable<string> _cells; private readonly IEnumerable<string> _cells;
public CellsComponentBase(IEnumerable<string> cells) public CellsComponentBase(IEnumerable<string> cells)
{ {
_cells = cells; _cells = cells;
} }
public void Render(AlignmentHorizontal alignmentHorizontal, Size size) public void Render(Horizontal horizontal, Size size)
{ {
var content = new StringBuilder(); var content = new StringBuilder();
foreach (var cell in _cells) foreach (var cell in _cells)
@ -30,7 +29,7 @@ public class CellsComponentBase : ComponentBase, IComponent
// base.Render(content, position, size); // base.Render(content, position, size);
} }
public override Sketch Draw() public override Sketch DrawComponent()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -16,7 +16,7 @@ public class Dashboard : ComponentBase, IComponent
_title = title; _title = title;
} }
public void Render(AlignmentHorizontal alignmentHorizontal, Size size) public void Render(Horizontal horizontal, Size size)
{ {
var dashboardBuilder = new StringBuilder(); var dashboardBuilder = new StringBuilder();
@ -61,7 +61,7 @@ public class Dashboard : ComponentBase, IComponent
dashboardBuilder.Append(Symbols.Angles.RightBottom); dashboardBuilder.Append(Symbols.Angles.RightBottom);
} }
public override Sketch Draw() public override Sketch DrawComponent()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -1,47 +1,33 @@
using TUI.Components.Controls.Statics; using TUI.Components.Controls.Statics;
using TUI.Components.Controls.Statics.Hints; using TUI.Components.Controls.Statics.Hints;
using TUI.Engine.Nodes; using TUI.Engine.Nodes;
using TUI.Engine.Nodes.Attributes;
using TUI.Engine.Nodes.Attributes.Alignments; using TUI.Engine.Nodes.Attributes.Alignments;
using TUI.Engine.Nodes.Attributes.Orientations;
using TUI.Engine.Nodes.Attributes.Resizings;
using TUI.Engine.Nodes.Containers; using TUI.Engine.Nodes.Containers;
using TUI.Engine.Theme; using TUI.Engine.Theme;
namespace TUI.Components.Controls; namespace TUI.Components.Controls;
public abstract class ContainerBase : IContainer
{
public Orientation Orientation => Orientation.Horizontal;
public Resizing ResizingHorizontal => Resizing.Adaptive;
public Resizing ResizingVertical => Resizing.Hug;
public Size Fixed { get; }
public abstract Nodes GetNodes();
}
public class HeaderContainer : ContainerBase, IContainer public class HeaderContainer : ContainerBase, IContainer
{ {
public override Nodes GetNodes() public override Nodes GetNodes()
{ {
var versionHints = new VersionHints() var versionHints = new VersionHints();
.Set(Indentation.Default); versionHints.SetPadding(Indentation.Default);
var tagsHints = new TagHints() var tagsHints = new TagHints();
.Set(Indentation.Default); tagsHints.SetPadding(Indentation.Default);
var appTypeHints = new AppTypeHints() var appTypeHints = new AppTypeHints();
.Set(Indentation.Default); appTypeHints.SetPadding(Indentation.Default);
var hotkeysHints = new HotkeysHint() var hotkeysHints = new HotkeysHint();
.Set(Indentation.Default); hotkeysHints.SetPadding(Indentation.Default);
var logo = new Logo() var logo = new Logo();
.Set(AlignmentHorizontal.Right) logo.SetAlignment(Horizontal.Right);
.Set(left: Indentation.Default, bottom: Indentation.Default, right: Indentation.Default); logo.SetPaddingLeft(Indentation.Default);
logo.SetPaddingBottom(Indentation.Default);
logo.SetPaddingRight(Indentation.Default);
return new Nodes { versionHints, tagsHints, appTypeHints, hotkeysHints, logo }; return new Nodes { versionHints, tagsHints, appTypeHints, hotkeysHints, logo };
} }

View File

@ -24,7 +24,7 @@ public class Tag : ComponentBase
_gitType = gitType; _gitType = gitType;
} }
public void Render(AlignmentHorizontal alignmentHorizontal, Size size) public void Render(Horizontal horizontal, Size size)
{ {
var tagBuilder = new StringBuilder(); var tagBuilder = new StringBuilder();
@ -59,7 +59,7 @@ public class Tag : ComponentBase
_ => Symbols.Git _ => Symbols.Git
}; };
public override Sketch Draw() public override Sketch DrawComponent()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -1,7 +1,6 @@
using TUI.Components.Controls;
using TUI.Engine.Nodes; using TUI.Engine.Nodes;
using TUI.Engine.Nodes.Attributes.Orientations; using TUI.Engine.Nodes.Attributes.Orientations;
using TUI.Engine.Nodes.Attributes.Resizings; using TUI.Engine.Nodes.Attributes.Resizing;
using TUI.Engine.Nodes.Components; using TUI.Engine.Nodes.Components;
using TUI.Engine.Nodes.Containers; using TUI.Engine.Nodes.Containers;

View File

@ -18,12 +18,12 @@ public class DependenciesView : ComponentBase, IComponent
_developmentStack = developmentStack; _developmentStack = developmentStack;
} }
public void Render(AlignmentHorizontal alignmentHorizontal, Size size) public void Render(Horizontal horizontal, Size size)
{ {
var dashboardTitle = _developmentStack.Icon + Symbols.Space + ViewName; var dashboardTitle = _developmentStack.Icon + Symbols.Space + ViewName;
var dashboard = new Dashboard(dashboardTitle); var dashboard = new Dashboard(dashboardTitle);
Add(dashboard); // Add(dashboard);
} }
// private const int TitleWidth = 25; // private const int TitleWidth = 25;
@ -153,7 +153,7 @@ public class DependenciesView : ComponentBase, IComponent
// { // {
// _table.Previous(); // _table.Previous();
// } // }
public override Sketch Draw() public override Sketch DrawComponent()
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

@ -1,3 +1,3 @@
namespace TUI.Engine.Nodes.Attributes.Alignments; namespace TUI.Engine.Nodes.Attributes.Alignments;
public record Alignment(AlignmentHorizontal AlignmentHorizontal, Vertical Vertical); public record Alignment(Horizontal Horizontal, Vertical Vertical);

View File

@ -1,6 +1,6 @@
namespace TUI.Engine.Nodes.Attributes.Alignments; namespace TUI.Engine.Nodes.Attributes.Alignments;
public enum AlignmentHorizontal public enum Horizontal
{ {
Left = 0, Left = 0,
Center = 1, Center = 1,

View File

@ -0,0 +1,10 @@
namespace TUI.Engine.Nodes.Attributes.Alignments;
public interface IAlignable
{
Alignment Alignment { get; }
void SetAlignment(Vertical vertical);
void SetAlignment(Horizontal horizontal);
}

View File

@ -1,8 +0,0 @@
namespace TUI.Engine.Nodes.Attributes.Alignments;
public interface IWithAlignment<out TNode> where TNode : INode
{
public Alignment Alignment { get; }
public TNode Set(AlignmentHorizontal alignmentHorizontal = AlignmentHorizontal.Left, Vertical vertical = Vertical.Top);
}

View File

@ -0,0 +1,14 @@
using TUI.Engine.Theme;
namespace TUI.Engine.Nodes.Attributes.Paddings;
public interface IPaddingable
{
Padding? Padding { get; }
void SetPadding(Level level);
void SetPaddingLeft(Level level);
void SetPaddingTop(Level level);
void SetPaddingBottom(Level level);
void SetPaddingRight(Level level);
}

View File

@ -1,17 +0,0 @@
using TUI.Engine.Theme;
namespace TUI.Engine.Nodes.Attributes.Paddings;
public interface IWithPadding<out TNode> where TNode : INode
{
public Padding? Padding { get; }
public TNode Set(Level padding);
public TNode Set(
Level? left = Level.None,
Level? top = Level.None,
Level? right = Level.None,
Level? bottom = Level.None
);
}

View File

@ -3,10 +3,10 @@ using TUI.Engine.Theme;
namespace TUI.Engine.Nodes.Attributes.Paddings; namespace TUI.Engine.Nodes.Attributes.Paddings;
public record Padding( public record Padding(
Level? Left = Level.None, Level Left = Level.None,
Level? Top = Level.None, Level Top = Level.None,
Level? Right = Level.None, Level Right = Level.None,
Level? Bottom = Level.None Level Bottom = Level.None
) )
{ {
public Padding(Level padding) : this(Left: padding, Top: padding, Right: padding, Bottom: padding) public Padding(Level padding) : this(Left: padding, Top: padding, Right: padding, Bottom: padding)

View File

@ -0,0 +1,14 @@
using TUI.Engine.Nodes.Attributes.Orientations;
namespace TUI.Engine.Nodes.Attributes.Resizing;
public interface IResizable
{
Resizing ResizingHorizontal { get; }
Resizing ResizingVertical { get; }
void SetAdaptive(Orientation orientation);
void SetHug(Orientation orientation);
void SetFixed(Orientation orientation, int value);
}

View File

@ -1,4 +1,4 @@
namespace TUI.Engine.Nodes.Attributes.Resizings; namespace TUI.Engine.Nodes.Attributes.Resizing;
public enum Resizing public enum Resizing
{ {

View File

@ -1,10 +0,0 @@
namespace TUI.Engine.Nodes.Attributes.Resizings;
public interface IWithResizing
{
Resizing ResizingHorizontal { get; }
Resizing ResizingVertical { get; }
Size Fixed { get; }
}

View File

@ -1,21 +1,46 @@
using TUI.Engine.Nodes.Attributes;
using TUI.Engine.Nodes.Attributes.Alignments; using TUI.Engine.Nodes.Attributes.Alignments;
using TUI.Engine.Nodes.Attributes.Paddings; using TUI.Engine.Nodes.Attributes.Paddings;
using TUI.Engine.Nodes.Attributes.Resizing;
using TUI.Engine.Theme; using TUI.Engine.Theme;
namespace TUI.Engine.Nodes.Components; namespace TUI.Engine.Nodes.Components;
public abstract class ComponentBase : List<IComponent>, IComponent
public abstract class ComponentBase : NodeBase, IComponent
{ {
public abstract Sketch Draw(); private Size _sketchSize;
public abstract Sketch DrawComponent();
public Sketch Draw()
{
var sketch = DrawComponent();
_sketchSize = sketch.GetSize();
return sketch;
}
public Resizing ResizingHorizontal { get; }
// protected override Size GetAllowableSize() =>
// new(
// AllowableSize.Width <= _sketchSize.Width ? _sketchSize.Width : AllowableSize.Width,
// AllowableSize.Height <= _sketchSize.Height ? _sketchSize.Height : AllowableSize.Height
// );
#region Alignments #region Alignments
public Alignment Alignment { get; private set; } = new(AlignmentHorizontal.Center, Vertical.Top); public Alignment Alignment { get; private set; } = new(Horizontal.Center, Vertical.Top);
public IComponent Set(AlignmentHorizontal alignmentHorizontal = AlignmentHorizontal.Left, Vertical vertical = Vertical.Top) public void SetAlignment(Vertical vertical)
{ {
Alignment = new Alignment(alignmentHorizontal, vertical); Alignment = Alignment with { Vertical = vertical };
return this; }
public void SetAlignment(Horizontal horizontal)
{
Alignment = Alignment with { Horizontal = horizontal };
} }
#endregion #endregion
@ -24,22 +49,15 @@ public abstract class ComponentBase : List<IComponent>, IComponent
public Padding Padding { get; private set; } = new(Level.None); public Padding Padding { get; private set; } = new(Level.None);
public IComponent Set(Level padding) public void SetPadding(Level level) => Padding = new Padding(level);
{
Padding = new Padding(padding);
return this;
}
public IComponent Set( public void SetPaddingTop(Level level) => Padding = Padding with { Top = level };
Level? left = Level.None,
Level? top = Level.None, public void SetPaddingRight(Level level) => Padding = Padding with { Right = level };
Level? right = Level.None,
Level? bottom = Level.None public void SetPaddingBottom(Level level) => Padding = Padding with { Bottom = level };
)
{ public void SetPaddingLeft(Level level) => Padding = Padding with { Left = level };
Padding = new Padding(left, top, right, bottom);
return this;
}
#endregion #endregion
} }

View File

@ -8,7 +8,7 @@ public abstract class ComponentStaticBase : ComponentBase
protected abstract void RenderWithCache(StringBuilder builder); protected abstract void RenderWithCache(StringBuilder builder);
public override Sketch Draw() public override Sketch DrawComponent()
{ {
if (_cache is not null) if (_cache is not null)
{ {

View File

@ -3,9 +3,7 @@ using TUI.Engine.Nodes.Attributes.Paddings;
namespace TUI.Engine.Nodes.Components; namespace TUI.Engine.Nodes.Components;
public interface IComponent : INode, public interface IComponent : INode, IAlignable, IPaddingable
IWithAlignment<IComponent>,
IWithPadding<IComponent>
{ {
Sketch Draw(); Sketch Draw();
} }

View File

@ -0,0 +1,10 @@
using TUI.Engine.Nodes.Attributes.Orientations;
namespace TUI.Engine.Nodes.Containers;
public abstract class ContainerBase : NodeBase, IContainer
{
public Orientation Orientation => Orientation.Horizontal;
public abstract Nodes GetNodes();
}

View File

@ -7,6 +7,27 @@ namespace TUI.Engine.Nodes.Containers;
public static class ContainerExtension public static class ContainerExtension
{ {
// public static Position GetNextNodePosition(this INode node,
// Orientation orientation,
// Size allowableSize,
// Position currentChildrenPosition)
// {
// var nodeSize = node.GetSize(allowableSize);
//
// return orientation switch
// {
// Orientation.Horizontal => currentChildrenPosition with
// {
// Left = currentChildrenPosition.Left + nodeSize.Width
// },
// Orientation.Vertical => currentChildrenPosition with
// {
// Top = currentChildrenPosition.Top + nodeSize.Height
// },
// _ => throw new ArgumentOutOfRangeException()
// };
// }
public static Size GetSize(this IContainer container, Size allowableSize) public static Size GetSize(this IContainer container, Size allowableSize)
{ {
var nodeCount = container.GetNodes().Count; var nodeCount = container.GetNodes().Count;
@ -27,19 +48,19 @@ public static class ComponentExtensions
Size actualSize) Size actualSize)
{ {
var left = sketchPosition.Left + (int)(component.Padding?.Left ?? 0) + var left = sketchPosition.Left + (int)(component.Padding?.Left ?? 0) +
CompensationLeft(component.Alignment.AlignmentHorizontal, allowableSize, actualSize); CompensationLeft(component.Alignment.Horizontal, allowableSize, actualSize);
var top = sketchPosition.Top + (int)(component.Padding?.Top ?? 0) + var top = sketchPosition.Top + (int)(component.Padding?.Top ?? 0) +
CompensationTop(component.Alignment.Vertical, allowableSize, actualSize); CompensationTop(component.Alignment.Vertical, allowableSize, actualSize);
return new Position(left, top); return new Position(left, top);
} }
private static int CompensationLeft(AlignmentHorizontal componentAlignmentHorizontal, Size defaultSize, private static int CompensationLeft(Horizontal componentHorizontal, Size defaultSize,
Size realSize) => Size realSize) =>
componentAlignmentHorizontal switch componentHorizontal switch
{ {
AlignmentHorizontal.Left => 0, Horizontal.Left => 0,
AlignmentHorizontal.Center => (defaultSize.Width - realSize.Width) / 2, Horizontal.Center => (defaultSize.Width - realSize.Width) / 2,
AlignmentHorizontal.Right => defaultSize.Width - realSize.Width, Horizontal.Right => defaultSize.Width - realSize.Width,
_ => 0 _ => 0
}; };

View File

@ -1,11 +1,9 @@
using TUI.Engine.Nodes.Attributes.Orientations; using TUI.Engine.Nodes.Attributes.Orientations;
using TUI.Engine.Nodes.Attributes.Resizings;
namespace TUI.Engine.Nodes.Containers; namespace TUI.Engine.Nodes.Containers;
public interface IContainer : INode, public interface IContainer : INode,
IWithOrientation, IWithOrientation
IWithResizing
{ {
public Nodes GetNodes(); public Nodes GetNodes();
} }

View File

@ -1,5 +1,7 @@
using TUI.Engine.Nodes.Attributes.Resizing;
namespace TUI.Engine.Nodes; namespace TUI.Engine.Nodes;
public interface INode public interface INode : IResizable
{ {
} }

View File

@ -0,0 +1,64 @@
using TUI.Engine.Nodes.Attributes.Orientations;
using TUI.Engine.Nodes.Attributes.Resizing;
namespace TUI.Engine.Nodes;
public abstract class NodeBase : INode
{
private int _fixedWidth;
private int _fixedHeight;
#region Resizing
public Resizing ResizingHorizontal { get; private set; } = Resizing.Adaptive;
public Resizing ResizingVertical { get; private set; } = Resizing.Hug;
public void SetAdaptive(Orientation orientation)
{
switch (orientation)
{
case Orientation.Horizontal:
ResizingHorizontal = Resizing.Adaptive;
break;
case Orientation.Vertical:
ResizingVertical = Resizing.Adaptive;
break;
default:
throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null);
}
}
public void SetHug(Orientation orientation)
{
switch (orientation)
{
case Orientation.Horizontal:
ResizingHorizontal = Resizing.Hug;
break;
case Orientation.Vertical:
ResizingVertical = Resizing.Hug;
break;
default:
throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null);
}
}
public void SetFixed(Orientation orientation, int value)
{
switch (orientation)
{
case Orientation.Horizontal:
ResizingHorizontal = Resizing.Fixed;
_fixedWidth = value;
break;
case Orientation.Vertical:
ResizingVertical = Resizing.Fixed;
_fixedHeight = value;
break;
default:
throw new ArgumentOutOfRangeException(nameof(orientation), orientation, null);
}
}
#endregion Resizing
}

View File

@ -1,4 +1,3 @@
using System.Diagnostics;
using TUI.Engine.Nodes; using TUI.Engine.Nodes;
using TUI.Engine.Nodes.Attributes; using TUI.Engine.Nodes.Attributes;
using TUI.Engine.Nodes.Attributes.Orientations; using TUI.Engine.Nodes.Attributes.Orientations;
@ -67,4 +66,23 @@ public sealed class ContainerCraftsman : CraftsmanBase, IDrawable<IContainer>
throw new InvalidCastException(); throw new InvalidCastException();
} }
} }
} }
// private int GetWidth() =>
// ResizingHorizontal switch
// {
// Resizing.Fixed => _fixedWidth,
// Resizing.Hug => GetAllowableSize().Width,
// Resizing.Adaptive => GetAllowableSize().Width,
// _ => 0
// };
//
// private int GetHeight() =>
// ResizingVertical switch
// {
// Resizing.Fixed => _fixedHeight,
// Resizing.Hug => GetAllowableSize().Height,
// Resizing.Adaptive => GetAllowableSize().Height,
// _ => 0
// };

View File

@ -1,5 +1,3 @@
using TUI.Engine.Nodes.Attributes;
namespace TUI.Engine.Rendering; namespace TUI.Engine.Rendering;
public interface ICanvas public interface ICanvas

View File

@ -21,9 +21,10 @@ public class DependenciesPage
var nodeCraftsman = new NodeCraftsman(componentCraftsman, containerCraftsman); var nodeCraftsman = new NodeCraftsman(componentCraftsman, containerCraftsman);
var header = new HeaderContainer(); var header = new HeaderContainer();
var copyright = new Copyright() var copyright = new Copyright();
.Set(right: Level.Normal) copyright.SetPaddingRight(Level.Normal);
.Set(AlignmentHorizontal.Right, Vertical.Bottom); copyright.SetAlignment(Horizontal.Right);
copyright.SetAlignment(Vertical.Bottom);
var layout = new DashboardLayout().AddHeader(header).AddFooter(copyright); var layout = new DashboardLayout().AddHeader(header).AddFooter(copyright);
// CommandLine = new CommandLine(); // CommandLine = new CommandLine();

View File

@ -10,16 +10,17 @@ public class ComponentBaseTests
[Fact] [Fact]
public void WhenUseChainingSaveAllChange() public void WhenUseChainingSaveAllChange()
{ {
var component = new Logo() var logo = new Logo();
.Set(Level.Normal) logo.SetPadding(Level.Normal);
.Set(vertical: Vertical.Center, alignmentHorizontal: AlignmentHorizontal.Center); logo.SetAlignment(Vertical.Center);
logo.SetAlignment(Horizontal.Center);
component.Padding.Top.Should().Be(Level.Normal); logo.Padding.Top.Should().Be(Level.Normal);
component.Padding.Left.Should().Be(Level.Normal); logo.Padding.Left.Should().Be(Level.Normal);
component.Padding.Bottom.Should().Be(Level.Normal); logo.Padding.Bottom.Should().Be(Level.Normal);
component.Padding.Right.Should().Be(Level.Normal); logo.Padding.Right.Should().Be(Level.Normal);
component.Alignment.AlignmentHorizontal.Should().Be(AlignmentHorizontal.Center); logo.Alignment.Horizontal.Should().Be(Horizontal.Center);
component.Alignment.Vertical.Should().Be(Vertical.Center); logo.Alignment.Vertical.Should().Be(Vertical.Center);
} }
[Fact] [Fact]
@ -27,7 +28,7 @@ public class ComponentBaseTests
{ {
var component = new Logo(); var component = new Logo();
component.Set(Level.Normal); component.SetPadding(Level.Normal);
component.Padding.Top.Should().Be(Level.Normal); component.Padding.Top.Should().Be(Level.Normal);
component.Padding.Left.Should().Be(Level.Normal); component.Padding.Left.Should().Be(Level.Normal);
@ -43,22 +44,21 @@ public class ComponentBaseTests
{ {
var component = new Logo(); var component = new Logo();
component.Set(vertical: alignment); component.SetAlignment(alignment);
component.Alignment.Vertical.Should().Be(alignment); component.Alignment.Vertical.Should().Be(alignment);
} }
[Theory] [Theory]
[InlineData(AlignmentHorizontal.Left)] [InlineData(Horizontal.Left)]
[InlineData(AlignmentHorizontal.Center)] [InlineData(Horizontal.Center)]
[InlineData(AlignmentHorizontal.Right)] [InlineData(Horizontal.Right)]
public void WhenSetHorizontalAlignSaveAllChange(AlignmentHorizontal alignment) public void WhenSetHorizontalAlignSaveAllChange(Horizontal alignment)
{ {
var component = new Logo(); var component = new Logo();
component.Set(alignmentHorizontal: alignment); component.SetAlignment(alignment);
component.Alignment.AlignmentHorizontal.Should().Be(alignment); component.Alignment.Horizontal.Should().Be(alignment);
} }
} }

View File

@ -2,7 +2,7 @@ using Moq;
using TUI.Engine.Nodes; using TUI.Engine.Nodes;
using TUI.Engine.Nodes.Attributes.Alignments; using TUI.Engine.Nodes.Attributes.Alignments;
using TUI.Engine.Nodes.Attributes.Orientations; using TUI.Engine.Nodes.Attributes.Orientations;
using TUI.Engine.Nodes.Attributes.Resizings; using TUI.Engine.Nodes.Attributes.Resizing;
using TUI.Engine.Nodes.Components; using TUI.Engine.Nodes.Components;
using TUI.Engine.Nodes.Containers; using TUI.Engine.Nodes.Containers;
using TUI.Engine.Rendering; using TUI.Engine.Rendering;
@ -17,7 +17,7 @@ public class NodeCraftsmanTests
{ {
_component = Mock.Of<IComponent>(c => _component = Mock.Of<IComponent>(c =>
c.Draw() == new Sketch("Lorem") && c.Draw() == new Sketch("Lorem") &&
c.Alignment == new Alignment(AlignmentHorizontal.Left, Vertical.Top)); c.Alignment == new Alignment(Horizontal.Left, Vertical.Top));
} }
[Fact] [Fact]
@ -36,14 +36,14 @@ public class NodeCraftsmanTests
} }
[Theory] [Theory]
[InlineData(AlignmentHorizontal.Left, "Lorem", 10, 0)] [InlineData(Horizontal.Left, "Lorem", 10, 0)]
[InlineData(AlignmentHorizontal.Center, "Lorem", 10, 2)] [InlineData(Horizontal.Center, "Lorem", 10, 2)]
[InlineData(AlignmentHorizontal.Center, "Lo", 10, 4)] [InlineData(Horizontal.Center, "Lo", 10, 4)]
[InlineData(AlignmentHorizontal.Center, "Lorem", 9, 2)] [InlineData(Horizontal.Center, "Lorem", 9, 2)]
[InlineData(AlignmentHorizontal.Center, "Lorem", 11, 3)] [InlineData(Horizontal.Center, "Lorem", 11, 3)]
[InlineData(AlignmentHorizontal.Right, "Lorem", 10, 5)] [InlineData(Horizontal.Right, "Lorem", 10, 5)]
[InlineData(AlignmentHorizontal.Right, "Lo", 10, 8)] [InlineData(Horizontal.Right, "Lo", 10, 8)]
public void DrawWithHorizontalAlignment(AlignmentHorizontal alignment, string content, int canvasSize, public void DrawWithHorizontalAlignment(Horizontal alignment, string content, int canvasSize,
int expectedPosition) int expectedPosition)
{ {
var canvas = Mock.Of<ICanvas>(w => w.Width == canvasSize && w.Height == canvasSize); var canvas = Mock.Of<ICanvas>(w => w.Width == canvasSize && w.Height == canvasSize);
@ -79,7 +79,7 @@ public class NodeCraftsmanTests
{ {
var canvas = Mock.Of<ICanvas>(w => w.Width == canvasSize && w.Height == canvasSize); var canvas = Mock.Of<ICanvas>(w => w.Width == canvasSize && w.Height == canvasSize);
var component = Mock.Of<IComponent>(c => c.Draw() == new Sketch(content) && var component = Mock.Of<IComponent>(c => c.Draw() == new Sketch(content) &&
c.Alignment == new Alignment(AlignmentHorizontal.Left, alignment)); c.Alignment == new Alignment(Horizontal.Left, alignment));
var nodes = new Nodes { component }; var nodes = new Nodes { component };
var root = Mock.Of<IContainer>(r => r.GetNodes() == nodes); var root = Mock.Of<IContainer>(r => r.GetNodes() == nodes);
@ -94,21 +94,21 @@ public class NodeCraftsmanTests
} }
[Theory] [Theory]
[InlineData(AlignmentHorizontal.Left, Vertical.Top, 0, 0)] [InlineData(Horizontal.Left, Vertical.Top, 0, 0)]
[InlineData(AlignmentHorizontal.Left, Vertical.Center, 0, 2)] [InlineData(Horizontal.Left, Vertical.Center, 0, 2)]
[InlineData(AlignmentHorizontal.Left, Vertical.Bottom, 0, 4)] [InlineData(Horizontal.Left, Vertical.Bottom, 0, 4)]
[InlineData(AlignmentHorizontal.Center, Vertical.Top, 2, 0)] [InlineData(Horizontal.Center, Vertical.Top, 2, 0)]
[InlineData(AlignmentHorizontal.Center, Vertical.Center, 2, 2)] [InlineData(Horizontal.Center, Vertical.Center, 2, 2)]
[InlineData(AlignmentHorizontal.Center, Vertical.Bottom, 2, 4)] [InlineData(Horizontal.Center, Vertical.Bottom, 2, 4)]
[InlineData(AlignmentHorizontal.Right, Vertical.Top, 4, 0)] [InlineData(Horizontal.Right, Vertical.Top, 4, 0)]
[InlineData(AlignmentHorizontal.Right, Vertical.Center, 4, 2)] [InlineData(Horizontal.Right, Vertical.Center, 4, 2)]
[InlineData(AlignmentHorizontal.Right, Vertical.Bottom, 4, 4)] [InlineData(Horizontal.Right, Vertical.Bottom, 4, 4)]
public void DrawWithAlignment(AlignmentHorizontal alignmentHorizontal, Vertical vertical, int expectedLeft, public void DrawWithAlignment(Horizontal horizontal, Vertical vertical, int expectedLeft,
int expectedTop) int expectedTop)
{ {
var canvas = Mock.Of<ICanvas>(w => w.Width == 6 && w.Height == 5); var canvas = Mock.Of<ICanvas>(w => w.Width == 6 && w.Height == 5);
var component = Mock.Of<IComponent>(c => c.Draw() == new Sketch("VV") && var component = Mock.Of<IComponent>(c => c.Draw() == new Sketch("VV") &&
c.Alignment == new Alignment(alignmentHorizontal, vertical)); c.Alignment == new Alignment(horizontal, vertical));
var nodes = new Nodes { component }; var nodes = new Nodes { component };
var root = Mock.Of<IContainer>(r => r.GetNodes() == nodes); var root = Mock.Of<IContainer>(r => r.GetNodes() == nodes);
@ -157,7 +157,7 @@ public class NodeCraftsmanTests
{ {
var canvas = Mock.Of<ICanvas>(w => w.Width == 10 && w.Height == 1); var canvas = Mock.Of<ICanvas>(w => w.Width == 10 && w.Height == 1);
var nodes = new Nodes { _component, _component }; var nodes = new Nodes { _component, _component };
var container = Mock.Of<IContainer>(g => g.GetNodes() == nodes); var container = Mock.Of<ContainerBase>(g => g.GetNodes() == nodes);
var componentCraftsman = new ComponentCraftsman(canvas); var componentCraftsman = new ComponentCraftsman(canvas);
var containerCraftsman = new ContainerCraftsman(componentCraftsman); var containerCraftsman = new ContainerCraftsman(componentCraftsman);