-
Notifications
You must be signed in to change notification settings - Fork 10
/
GridFlow.cs
62 lines (51 loc) · 2.27 KB
/
GridFlow.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
60
61
62
using UnityEngine;
namespace UniMob.UI.Widgets
{
public class GridFlow : 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 RectPadding Padding { get; set; }
public Vector2 Spacing { get; set; }
public int MaxCrossAxisCount { get; set; } = int.MaxValue;
public float MaxCrossAxisExtent { get; set; } = int.MaxValue;
public GridLayoutDelegate LayoutDelegate { get; set; }
public override State CreateState() => new GridFlowState();
}
internal class GridFlowState : MultiChildLayoutState<GridFlow>, IGridFlowState
{
public override WidgetViewReference View { get; }
= WidgetViewReference.Resource("$$_Grid");
[Atom] public WidgetSize InnerSize => CalculateInnerSize();
public CrossAxisAlignment CrossAxisAlignment => Widget.CrossAxisAlignment;
public MainAxisAlignment MainAxisAlignment => Widget.MainAxisAlignment;
public GridLayoutSettings LayoutSettings => new GridLayoutSettings
{
children = Children,
gridPadding = Widget.Padding,
spacing = Widget.Spacing,
maxLineWidth = Widget.MaxCrossAxisExtent,
maxLineChildNum = Widget.MaxCrossAxisCount,
};
public GridLayoutDelegate LayoutDelegate => Widget.LayoutDelegate ?? GridLayoutUtility.DefaultLayoutDelegate;
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()
{
return GridLayoutUtility.CalculateSize(LayoutSettings, LayoutDelegate);
}
}
}