Push WIP changes before rename.

This commit is contained in:
H. Utku Maden 2024-07-17 23:12:07 +03:00
parent 3b52649ad2
commit 1ee492ccd4
3 changed files with 94 additions and 2 deletions

@ -8,7 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ReFuel.FreeType" Version="0.1.0-rc.3" /> <PackageReference Include="ReFuel.FreeType" Version="0.1.0-rc.4" />
<PackageReference Include="ReFuel.StbImage" Version="2.0.0-rc.3" /> <PackageReference Include="ReFuel.StbImage" Version="2.0.0-rc.3" />
</ItemGroup> </ItemGroup>

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using Quik.CommandMachine; using Quik.CommandMachine;
namespace Quik.Controls namespace Quik.Controls
@ -106,5 +107,19 @@ namespace Quik.Controls
{ {
LayoutValidated?.Invoke(sender, ea); LayoutValidated?.Invoke(sender, ea);
} }
protected void ValidateChildrenLayout()
{
if (this is IEnumerable<Control> enumerable)
{
foreach (Control child in enumerable)
{
if (child.IsLayoutValid)
continue;
child.ValidateLayout();
}
}
}
} }
} }

@ -1,4 +1,7 @@
using System; using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Quik.CommandMachine; using Quik.CommandMachine;
namespace Quik.Controls namespace Quik.Controls
@ -9,15 +12,89 @@ namespace Quik.Controls
public bool AllowWrap { get; set; } public bool AllowWrap { get; set; }
public VerticalAlignment VerticalAlignment { get; set; } public VerticalAlignment VerticalAlignment { get; set; }
public HorizontalAlignment HorizontalAlignment { get; set; } public HorizontalAlignment HorizontalAlignment { get; set; }
public float ItemPadding { get; set; } = 4f;
protected override void ValidateLayout() protected override void ValidateLayout()
{ {
throw new NotImplementedException(); ValidateChildrenLayout();
} }
protected override void ValidateVisual(CommandList cmd) protected override void ValidateVisual(CommandList cmd)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
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,
};
}
}
} }
} }