-
Notifications
You must be signed in to change notification settings - Fork 10
/
Column.cs
59 lines (46 loc) · 1.88 KB
/
Column.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
56
57
58
59
namespace UniMob.UI.Widgets
{
public sealed class Column : MultiChildLayoutWidget
{
public CrossAxisAlignment CrossAxisAlignment { get; set; } = CrossAxisAlignment.Start;
public MainAxisAlignment MainAxisAlignment { get; set; } = MainAxisAlignment.Start;
public AxisSize CrossAxisSize { get; set; } = AxisSize.Min;
public AxisSize MainAxisSize { get; set; } = AxisSize.Min;
public WidgetSize? Size { get; set; }
public override State CreateState() => new ColumnState();
}
internal sealed class ColumnState : MultiChildLayoutState<Column>, IColumnState
{
public override WidgetViewReference View { get; }
= WidgetViewReference.Resource("$$_Column");
public CrossAxisAlignment CrossAxisAlignment => Widget.CrossAxisAlignment;
public MainAxisAlignment MainAxisAlignment => Widget.MainAxisAlignment;
[Atom] public WidgetSize InnerSize => CalculateInnerSize();
public override WidgetSize CalculateSize()
{
if (Widget.Size.HasValue)
{
return Widget.Size.Value;
}
var (minWidth, minHeight, maxWidth, maxHeight) = InnerSize;
if (Widget.CrossAxisSize == AxisSize.Max)
{
maxWidth = float.PositiveInfinity;
}
if (Widget.MainAxisSize == AxisSize.Max)
{
maxHeight = float.PositiveInfinity;
}
return new WidgetSize(minWidth, minHeight, maxWidth, maxHeight);
}
private WidgetSize CalculateInnerSize()
{
var size = default(WidgetSize?);
foreach (var child in Children)
{
size = size.HasValue ? WidgetSize.StackY(size.Value, child.Size) : child.Size;
}
return size.GetValueOrDefault(WidgetSize.Zero);
}
}
}