-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
FlexLayoutConfig.cs
99 lines (87 loc) · 2.86 KB
/
FlexLayoutConfig.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using Gilzoide.FlexUi.Yoga;
using UnityEngine;
namespace Gilzoide.FlexUi
{
[CreateAssetMenu]
public class FlexLayoutConfig : ScriptableObject
{
[Tooltip("If true, this configuration will be used by FlexLayout nodes that do not have a configuration set explicitly.")]
[SerializeField] private bool _isDefaultConfig = false;
[Tooltip("Yoga will by deafult round final layout positions and dimensions to the nearst point.\n"
+ "'Point Scale Factor' controls the density of the grid used for layout rounding (e.g. to round to the closest display pixel).\n"
+ "Set this to 0 to avoid rounding the layout results.")]
[SerializeField, Min(0)] private float _pointScaleFactor = 1f;
[Tooltip("Configures how Yoga balances W3C conformance vs compatibility with layouts created against earlier versions of Yoga.")]
[SerializeField] private Errata _errata = Errata.None;
[Tooltip("Turn experimental Yoga features on or off")]
[SerializeField] private ExperimentalFeatureFlags _experimentalFeatures = default;
#region Property getters/setters
public float PointScaleFactor
{
get => _pointScaleFactor;
set
{
_pointScaleFactor = value;
_config.SetPointScaleFactor(value);
}
}
public Errata Errata
{
get => _errata;
set
{
_errata = value;
_config.SetErrata(value);
}
}
public ExperimentalFeatureFlags ExperimentalFeatures
{
get => _experimentalFeatures;
set
{
_experimentalFeatures = value;
_config.SetExperimentalFeatures(value);
}
}
#endregion
public YGConfig Config
{
get
{
if (_config.IsNull)
{
if (_isDefaultConfig)
{
_config = YGConfig.GetDefaultConfig();
}
else
{
_config.Instantiate();
}
RefreshConfig();
}
return _config;
}
}
private YGConfig _config;
protected void OnDisable()
{
if (!_config.Equals(YGConfig.GetDefaultConfig()))
{
_config.Dispose();
}
}
protected void RefreshConfig()
{
_config.SetPointScaleFactor(_pointScaleFactor);
_config.SetErrata(_errata);
_config.SetExperimentalFeatures(_experimentalFeatures);
}
#if UNITY_EDITOR
private void OnValidate()
{
RefreshConfig();
}
#endif
}
}