19 internal float TotalWidth;
20 public CUIDirection Direction;
21 public float Gap {
get;
set; }
22 public bool ResizeToHostHeight {
get;
set; } =
true;
24 private class CUIComponentSize
28 public CUIComponentSize(
CUIComponent component, Vector2 size)
30 Component = component;
34 private List<CUIComponentSize> Sizes =
new List<CUIComponentSize>();
35 private List<CUIComponentSize> Resizible =
new List<CUIComponentSize>();
37 internal override void Update()
41 Host.InvokeOnLayoutUpdated();
54 if (ResizeToHostHeight)
60 if (c.
Relative.Height.HasValue) h = c.Relative.Height.Value * Host.
Real.Height;
61 if (c.
CrossRelative.Height.HasValue) h = c.CrossRelative.Height.Value * Host.
Real.Width;
64 if (c.RelativeMin.Height.HasValue) h = Math.Max(h, c.RelativeMin.Height.Value * Host.
Real.Height);
65 if (c.AbsoluteMin.Height.HasValue) h = Math.Max(h, c.AbsoluteMin.Height.Value);
67 if (!c.RelativeMin.Height.HasValue && !c.AbsoluteMin.Height.HasValue && c.
ForcedMinSize.Y.HasValue)
72 if (c.RelativeMax.Height.HasValue) h = Math.Min(h, c.RelativeMax.Height.Value * Host.
Real.Height);
73 if (c.AbsoluteMax.Height.HasValue) h = Math.Min(h, c.AbsoluteMax.Height.Value);
76 Vector2 s =
new Vector2(w, h);
83 w = c.Relative.Width.Value * Host.
Real.Width;
84 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"Relative.Width",
"w", w.ToString());
88 w = c.CrossRelative.Width.Value * Host.
Real.Height;
89 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"CrossRelative.Width",
"w", w.ToString());
94 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"Absolute.Width",
"w", w.ToString());
97 if (c.RelativeMin.Width.HasValue)
99 w = Math.Max(w, c.RelativeMin.Width.Value * Host.
Real.Width);
100 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"RelativeMin.Width",
"w", w.ToString());
102 if (c.AbsoluteMin.Width.HasValue)
104 w = Math.Max(w, c.AbsoluteMin.Width.Value);
105 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"AbsoluteMin.Width",
"w", w.ToString());
107 if (!c.RelativeMin.Width.HasValue && !c.AbsoluteMin.Width.HasValue && c.
ForcedMinSize.X.HasValue)
110 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"ForcedMinSize.X",
"w", w.ToString());
113 if (c.RelativeMax.Width.HasValue)
115 w = Math.Min(w, c.RelativeMax.Width.Value * Host.
Real.Width);
116 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"RelativeMax.Width",
"w", w.ToString());
118 if (c.AbsoluteMax.Width.HasValue)
120 w = Math.Min(w, c.AbsoluteMax.Width.Value);
121 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"AbsoluteMax.Width",
"w", w.ToString());
124 s =
new Vector2(w, h);
125 Vector2 okSize = c.AmIOkWithThisSize(s);
126 CUIDebug.Capture(Host, c,
"HorizontalList.Update",
"AmIOkWithThisSize",
"s", okSize.ToString());
130 if (!c.
Fixed) s =
new Vector2(s.X / c.
Scale, s.Y);
135 CUIComponentSize size =
new CUIComponentSize(c, s);
141 TotalWidth += Math.Max(0, Host.Children.Count - 1) * Gap;
143 float dif = Math.Max(0, Host.
Real.Width - TotalWidth);
145 Resizible.ForEach(c =>
147 float available = dif / Resizible.Count;
167 c.Size = c.Component.AmIOkWithThisSize(
new Vector2((
float)Math.Round(available), c.Size.Y));
169 CUIDebug.Capture(Host, c.Component,
"HorizontalList.Update",
"Resizible.ForEach",
"c.Size", c.Size.ToString());
175 if (Direction == CUIDirection.Straight)
178 foreach (CUIComponentSize c
in Sizes)
187 real =
new CUIRect(x, 0, c.Size.X, c.Size.Y);
190 real = offset.Transform(real);
191 real = real.Shift(Host.
Real.Position);
193 c.Component.SetReal(real,
"HorizontalList layout update");
199 if (Direction == CUIDirection.Reverse)
201 float x = Host.
Real.Width;
202 foreach (CUIComponentSize c
in Sizes)
213 real =
new CUIRect(x, 0, c.Size.X, c.Size.Y);
215 real = offset.Transform(real);
216 real = real.Shift(Host.
Real.Position);
218 c.Component.SetReal(real,
"HorizontalList layout update");
228 internal override void ResizeToContent()
235 if (c.
Ghost.X)
continue;
242 if (c.AbsoluteMin.Width.HasValue) w = Math.Max(w, c.AbsoluteMin.Width.Value);
244 if (c.AbsoluteMax.Width.HasValue) w = Math.Min(w, c.AbsoluteMax.Width.Value);
250 tw += Math.Max(0, Host.Children.Count - 1) * Gap;
252 CUIDebug.Capture(
null, Host,
"HorizontalList ResizeToContent",
"tw",
"ForcedMinSize.X", tw.ToString());
261 if (c.
Ghost.Y)
continue;
265 if (c.AbsoluteMin.Height.HasValue) h = Math.Max(h, c.AbsoluteMin.Height.Value);
267 if (c.AbsoluteMax.Height.HasValue) h = Math.Min(h, c.AbsoluteMax.Height.Value);
268 th = Math.Max(th, h);
271 CUIDebug.Capture(
null, Host,
"HorizontalList ResizeToContent",
"th",
"ForcedMinSize.Y", th.ToString());
275 base.ResizeToContent();