-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.cs
55 lines (43 loc) · 1.78 KB
/
Grid.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Developed by Bulat Bagaviev (@sunnyyssh).
// This file is licensed to you under the MIT license.
using System.Collections.Immutable;
using System.Diagnostics.CodeAnalysis;
namespace Sunnyyssh.ConsoleUI;
/// <summary>
/// <see cref="Wrapper"/> that can place <see cref="UIElement"/> in the specific grid cells.
/// </summary>
public sealed class Grid : CompositionWrapper
{
public LineComposition? Border { get; }
public AbsoluteGridDefinition AbsoluteDefinition { get; }
public GridCellsCollection Cells { get; }
[MemberNotNullWhen(true, nameof(Border))]
public bool HasBorder { get; }
private static ImmutableList<ChildInfo> ResolveCompositionChildren(GridCellsCollection cells, LineComposition? border)
{
var children = cells.Select(cell => cell.ChildInfo);
if (border is not null)
{
children = children.Append(new ChildInfo(border, 0, 0));
}
return children.ToImmutableList();
}
private static ImmutableList<ChildInfo> ResolveChildren(GridCellsCollection cells)
{
return cells
.Select(cell => cell.ChildInfo)
.ToImmutableList();
}
internal Grid(int width, int height, LineComposition? border,
AbsoluteGridDefinition absoluteDefinition, GridCellsCollection cells,
FocusFlowSpecification focusFlowSpecification, OverlappingPriority overlappingPriority)
: base(width, height, ResolveChildren(cells), ResolveCompositionChildren(cells, border),
focusFlowSpecification, overlappingPriority)
{
ArgumentNullException.ThrowIfNull(absoluteDefinition, nameof(absoluteDefinition));
Border = border;
AbsoluteDefinition = absoluteDefinition;
Cells = cells;
HasBorder = border is not null;
}
}