Dashboard/Quik/Controls/FlowBox.cs

100 lines
2.9 KiB
C#
Raw Normal View History

2024-06-09 21:06:13 +02:00
using System;
2024-07-17 22:12:07 +02:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
2024-07-17 22:18:20 +02:00
using Dashboard.CommandMachine;
2024-06-09 21:06:13 +02:00
2024-07-17 22:18:20 +02:00
namespace Dashboard.Controls
2024-06-09 21:06:13 +02:00
{
public class FlowBox : ContainerControl
{
public Direction FlowDirection { get; set; }
public bool AllowWrap { get; set; }
public VerticalAlignment VerticalAlignment { get; set; }
public HorizontalAlignment HorizontalAlignment { get; set; }
2024-07-17 22:12:07 +02:00
public float ItemPadding { get; set; } = 4f;
2024-06-09 21:06:13 +02:00
protected override void ValidateLayout()
{
2024-07-17 22:12:07 +02:00
ValidateChildrenLayout();
2024-06-09 21:06:13 +02:00
}
protected override void ValidateVisual(CommandList cmd)
{
throw new NotImplementedException();
}
2024-07-17 22:12:07 +02:00
private void FlowHorizontal()
{
IEnumerator<Control> controls = this.GetEnumerator();
List<Control> row;
}
// Enumerate a row.
private bool EnumerateRows(IEnumerator<Control> iterator, List<Control> 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<Control> 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,
};
}
}
2024-06-09 21:06:13 +02:00
}
}