diff --git a/Quik.Media.Defaults/Quik.Media.Defaults.csproj b/Quik.Media.Defaults/Quik.Media.Defaults.csproj
index a829d98..3704286 100644
--- a/Quik.Media.Defaults/Quik.Media.Defaults.csproj
+++ b/Quik.Media.Defaults/Quik.Media.Defaults.csproj
@@ -8,7 +8,7 @@
-
+
diff --git a/Quik/Controls/Control.cs b/Quik/Controls/Control.cs
index 7df96dd..8ddd65c 100644
--- a/Quik/Controls/Control.cs
+++ b/Quik/Controls/Control.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Generic;
using Quik.CommandMachine;
namespace Quik.Controls
@@ -106,5 +107,19 @@ namespace Quik.Controls
{
LayoutValidated?.Invoke(sender, ea);
}
+
+ protected void ValidateChildrenLayout()
+ {
+ if (this is IEnumerable enumerable)
+ {
+ foreach (Control child in enumerable)
+ {
+ if (child.IsLayoutValid)
+ continue;
+
+ child.ValidateLayout();
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/Quik/Controls/FlowBox.cs b/Quik/Controls/FlowBox.cs
index a73f802..b3a0adc 100644
--- a/Quik/Controls/FlowBox.cs
+++ b/Quik/Controls/FlowBox.cs
@@ -1,4 +1,7 @@
using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
using Quik.CommandMachine;
namespace Quik.Controls
@@ -9,15 +12,89 @@ namespace Quik.Controls
public bool AllowWrap { get; set; }
public VerticalAlignment VerticalAlignment { get; set; }
public HorizontalAlignment HorizontalAlignment { get; set; }
+ public float ItemPadding { get; set; } = 4f;
protected override void ValidateLayout()
{
- throw new NotImplementedException();
+ ValidateChildrenLayout();
}
protected override void ValidateVisual(CommandList cmd)
{
throw new NotImplementedException();
}
+
+ private void FlowHorizontal()
+ {
+ IEnumerator controls = this.GetEnumerator();
+ List row;
+ }
+
+ // Enumerate a row.
+ private bool EnumerateRows(IEnumerator iterator, List row)
+ {
+ float width = 0;
+
+ do
+ {
+ if (width + iterator.Current.Size.X < Size.X)
+ {
+ row.Add(iterator.Current);
+ width += iterator.Current.Size.X + ItemPadding;
+ }
+ else
+ {
+ return true;
+ }
+ } while (iterator.MoveNext());
+
+ return false;
+ }
+
+ // Flows a row of children.
+ private void FlowRow(List line, QVec2 offset, QVec2 size, float packedWidth)
+ {
+ QVec2 pointer = offset;
+
+ pointer.X += hstart();
+
+ foreach (Control child in line)
+ {
+ child.Position = pointer;
+ pointer += new QVec2(child.Size.X + hoffset(child), voffset(child));
+ }
+
+ float hstart()
+ {
+ return HorizontalAlignment switch {
+ HorizontalAlignment.Center => (size.Y - packedWidth) / 2,
+ HorizontalAlignment.Right => size.Y - packedWidth,
+ _ => 0f
+ };
+ }
+
+ float hoffset(Control child)
+ {
+ if (line.Count == 1)
+ return 0;
+ else if (HorizontalAlignment == HorizontalAlignment.Justify)
+ {
+ return ItemPadding + ((size.Y - packedWidth) / (line.Count - 1));
+ }
+ else
+ {
+ return ItemPadding;
+ }
+ }
+
+ float voffset(Control child)
+ {
+ return VerticalAlignment switch {
+ VerticalAlignment.Top => 0f,
+ VerticalAlignment.Bottom => size.Y - child.Size.Y,
+ _ => (size.Y - child.Size.Y) / 2,
+ };
+ }
+ }
}
}
\ No newline at end of file