using System; using System.Collections; using System.Collections.Generic; using System.Linq; using Dashboard.CommandMachine; namespace Dashboard.Controls { public class FlowBox : ContainerControl { public Direction FlowDirection { get; set; } 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() { 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, }; } } } }