20 internal float TotalHeight;
21 public CUIDirection Direction;
23 public float Gap {
get;
set; }
25 public bool ResizeToHostWidth {
get;
set; } =
true;
28 private class CUIComponentSize
32 public CUIComponentSize(
CUIComponent component, Vector2 size)
34 Component = component;
38 private List<CUIComponentSize> Sizes =
new List<CUIComponentSize>();
39 private List<CUIComponentSize> Resizible =
new List<CUIComponentSize>();
41 internal override void Update()
43 Stopwatch sw =
new Stopwatch();
47 Host.InvokeOnLayoutUpdated();
60 if (ResizeToHostWidth)
66 if (c.
Relative.Width.HasValue) w = c.Relative.Width.Value * Host.
Real.Width;
67 if (c.
CrossRelative.Width.HasValue) w = c.CrossRelative.Width.Value * Host.
Real.Height;
70 if (c.RelativeMin.Width.HasValue) w = Math.Max(w, c.RelativeMin.Width.Value * Host.
Real.Width);
71 if (c.AbsoluteMin.Width.HasValue) w = Math.Max(w, c.AbsoluteMin.Width.Value);
73 if (!c.RelativeMin.Width.HasValue && !c.AbsoluteMin.Width.HasValue && c.
ForcedMinSize.X.HasValue)
78 if (c.RelativeMax.Width.HasValue) w = Math.Min(w, c.RelativeMax.Width.Value * Host.
Real.Width);
79 if (c.AbsoluteMax.Width.HasValue) w = Math.Min(w, c.AbsoluteMax.Width.Value);
82 Vector2 s =
new Vector2(w, h);
89 h = c.Relative.Height.Value * Host.
Real.Height;
90 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"Relative.Height",
"h", h.ToString());
94 h = c.CrossRelative.Height.Value * Host.
Real.Width;
95 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"CrossRelative.Height",
"h", h.ToString());
100 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"Absolute.Height",
"h", h.ToString());
103 if (c.RelativeMin.Height.HasValue)
105 h = Math.Max(h, c.RelativeMin.Height.Value * Host.
Real.Height);
106 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"RelativeMin.Height",
"h", h.ToString());
108 if (c.AbsoluteMin.Height.HasValue)
110 h = Math.Max(h, c.AbsoluteMin.Height.Value);
111 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"AbsoluteMin.Height",
"h", h.ToString());
113 if (!c.RelativeMin.Height.HasValue && !c.AbsoluteMin.Height.HasValue && c.
ForcedMinSize.Y.HasValue)
116 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"ForcedMinSize.Y",
"h", h.ToString());
119 if (c.RelativeMax.Height.HasValue)
121 h = Math.Min(h, c.RelativeMax.Height.Value * Host.
Real.Height);
122 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"RelativeMax.Height",
"h", h.ToString());
124 if (c.AbsoluteMax.Height.HasValue)
126 h = Math.Min(h, c.AbsoluteMax.Height.Value);
127 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"AbsoluteMax.Height",
"h", h.ToString());
130 s =
new Vector2(w, h);
131 Vector2 okSize = c.AmIOkWithThisSize(s);
132 CUIDebug.Capture(Host, c,
"VerticalList.Update",
"AmIOkWithThisSize",
"s", okSize.ToString());
136 if (!c.
Fixed) s =
new Vector2(s.X, s.Y / c.
Scale);
141 CUIComponentSize size =
new CUIComponentSize(c, s);
147 TotalHeight += Math.Max(0, Host.Children.Count - 1) * Gap;
152 float dif = Math.Max(0, Host.
Real.Height - TotalHeight);
154 Resizible.ForEach(c =>
156 c.Size = c.Component.AmIOkWithThisSize(
new Vector2(c.Size.X, (
float)Math.Round(dif / Resizible.Count)));
159 CUIDebug.Capture(Host, c.Component,
"VerticalList.Update",
"Resizible.ForEach",
"c.Size", c.Size.ToString());
167 if (Direction == CUIDirection.Straight)
170 foreach (CUIComponentSize c
in Sizes)
175 else real =
new CUIRect(0, y, c.Size.X, c.Size.Y);
177 real = offset.Transform(real);
178 real = real.Shift(Host.
Real.Position);
180 c.Component.SetReal(real,
"VerticalList.Update");
186 if (Direction == CUIDirection.Reverse)
188 float y = Host.
Real.Height;
189 foreach (CUIComponentSize c
in Sizes)
194 else real =
new CUIRect(0, y, c.Size.X, c.Size.Y);
196 real = offset.Transform(real);
197 real = real.Shift(Host.
Real.Position);
199 c.Component.SetReal(real,
"VerticalList.Update");
207 internal override void ResizeToContent()
214 if (c.
Ghost.X)
continue;
218 if (c.AbsoluteMin.Width.HasValue) w = Math.Max(w, c.AbsoluteMin.Width.Value);
220 if (c.AbsoluteMax.Width.HasValue) w = Math.Min(w, c.AbsoluteMax.Width.Value);
222 tw = Math.Max(tw, w);
225 CUIDebug.Capture(
null, Host,
"VerticalList.ResizeToContent",
"tw",
"ForcedMinSize.W", tw.ToString());
234 if (c.
Ghost.Y)
continue;
240 if (c.AbsoluteMin.Height.HasValue) h = Math.Max(h, c.AbsoluteMin.Height.Value);
242 if (c.AbsoluteMax.Height.HasValue) h = Math.Min(h, c.AbsoluteMax.Height.Value);
247 th += Math.Max(0, Host.Children.Count - 1) * Gap;
249 CUIDebug.Capture(
null, Host,
"VerticalList.ResizeToContent",
"th",
"ForcedMinSize.Y", th.ToString());
253 base.ResizeToContent();