-
Notifications
You must be signed in to change notification settings - Fork 10
/
ZStack.cs
50 lines (39 loc) · 1.51 KB
/
ZStack.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
namespace UniMob.UI.Widgets
{
public class ZStack : MultiChildLayoutWidget
{
public AxisSize CrossAxisSize { get; set; } = AxisSize.Min;
public AxisSize MainAxisSize { get; set; } = AxisSize.Min;
public Alignment Alignment { get; set; } = Alignment.Center;
public override State CreateState() => new ZStackState();
}
internal class ZStackState : MultiChildLayoutState<ZStack>, IZStackState
{
public override WidgetViewReference View { get; }
= WidgetViewReference.Resource("$$_ZStack");
public Alignment Alignment => Widget.Alignment;
[Atom] public WidgetSize InnerSize => CalculateInnerSize();
public override WidgetSize CalculateSize()
{
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.StackZ(size.Value, child.Size) : child.Size;
}
return size.GetValueOrDefault(WidgetSize.Zero);
}
}
}