More fixes

This commit is contained in:
2026-01-17 05:22:37 +00:00
parent f62d4aa5f2
commit 7d2ac327a3
58 changed files with 754 additions and 666 deletions

View File

@@ -88,34 +88,36 @@ public class SkiaFlexLayout : SkiaLayoutView
public static FlexAlignSelf GetAlignSelf(SkiaView view) => (FlexAlignSelf)view.GetValue(AlignSelfProperty);
public static void SetAlignSelf(SkiaView view, FlexAlignSelf value) => view.SetValue(AlignSelfProperty, value);
protected override SKSize MeasureOverride(SKSize availableSize)
protected override Size MeasureOverride(Size availableSize)
{
bool isRow = Direction == FlexDirection.Row || Direction == FlexDirection.RowReverse;
float totalMain = 0f;
float maxCross = 0f;
var sizeAvailable = new Size(availableSize.Width, availableSize.Height);
foreach (var child in Children)
{
if (!child.IsVisible)
continue;
var childSize = child.Measure(availableSize);
var childSize = child.Measure(sizeAvailable);
if (isRow)
{
totalMain += childSize.Width;
maxCross = Math.Max(maxCross, childSize.Height);
totalMain += (float)childSize.Width;
maxCross = Math.Max(maxCross, (float)childSize.Height);
}
else
{
totalMain += childSize.Height;
maxCross = Math.Max(maxCross, childSize.Width);
totalMain += (float)childSize.Height;
maxCross = Math.Max(maxCross, (float)childSize.Width);
}
}
return isRow ? new SKSize(totalMain, maxCross) : new SKSize(maxCross, totalMain);
return isRow ? new Size(totalMain, maxCross) : new Size(maxCross, totalMain);
}
protected override SKRect ArrangeOverride(SKRect bounds)
protected override Rect ArrangeOverride(Rect bounds)
{
if (Children.Count == 0)
return bounds;
@@ -127,10 +129,10 @@ public class SkiaFlexLayout : SkiaLayoutView
if (orderedChildren.Count == 0)
return bounds;
float mainSize = isRow ? bounds.Width : bounds.Height;
float crossSize = isRow ? bounds.Height : bounds.Width;
float mainSize = isRow ? (float)bounds.Width : (float)bounds.Height;
float crossSize = isRow ? (float)bounds.Height : (float)bounds.Width;
var childInfos = new List<(SkiaView child, SKSize size, float grow, float shrink)>();
var childInfos = new List<(SkiaView child, Size size, float grow, float shrink)>();
float totalBasis = 0f;
float totalGrow = 0f;
float totalShrink = 0f;
@@ -141,21 +143,21 @@ public class SkiaFlexLayout : SkiaLayoutView
float grow = GetGrow(child);
float shrink = GetShrink(child);
SKSize size;
Size size;
if (basis.IsAuto)
{
size = child.Measure(new SKSize(bounds.Width, bounds.Height));
size = child.Measure(new Size(bounds.Width, bounds.Height));
}
else
{
float length = basis.Length;
size = isRow
? child.Measure(new SKSize(length, bounds.Height))
: child.Measure(new SKSize(bounds.Width, length));
? child.Measure(new Size(length, bounds.Height))
: child.Measure(new Size(bounds.Width, length));
}
childInfos.Add((child, size, grow, shrink));
totalBasis += isRow ? size.Width : size.Height;
totalBasis += isRow ? (float)size.Width : (float)size.Height;
totalGrow += grow;
totalShrink += shrink;
}
@@ -165,8 +167,8 @@ public class SkiaFlexLayout : SkiaLayoutView
var resolvedSizes = new List<(SkiaView child, float mainSize, float crossSize)>();
foreach (var (child, size, grow, shrink) in childInfos)
{
float childMainSize = isRow ? size.Width : size.Height;
float childCrossSize = isRow ? size.Height : size.Width;
float childMainSize = isRow ? (float)size.Width : (float)size.Height;
float childCrossSize = isRow ? (float)size.Height : (float)size.Width;
if (freeSpace > 0f && totalGrow > 0f)
{
@@ -183,7 +185,7 @@ public class SkiaFlexLayout : SkiaLayoutView
float usedSpace = resolvedSizes.Sum(s => s.mainSize);
float remainingSpace = Math.Max(0f, mainSize - usedSpace);
float position = isRow ? bounds.Left : bounds.Top;
float position = isRow ? (float)bounds.Left : (float)bounds.Top;
float spacing = 0f;
switch (JustifyContent)
@@ -221,13 +223,13 @@ public class SkiaFlexLayout : SkiaLayoutView
var alignSelf = GetAlignSelf(child);
var effectiveAlign = alignSelf == FlexAlignSelf.Auto ? AlignItems : (FlexAlignItems)alignSelf;
float crossPos = isRow ? bounds.Top : bounds.Left;
float crossPos = isRow ? (float)bounds.Top : (float)bounds.Left;
float finalCrossSize = childCrossSize;
switch (effectiveAlign)
{
case FlexAlignItems.End:
crossPos = (isRow ? bounds.Bottom : bounds.Right) - finalCrossSize;
crossPos = (isRow ? (float)bounds.Bottom : (float)bounds.Right) - finalCrossSize;
break;
case FlexAlignItems.Center:
crossPos += (crossSize - finalCrossSize) / 2f;
@@ -237,14 +239,14 @@ public class SkiaFlexLayout : SkiaLayoutView
break;
}
SKRect childBounds;
Rect childBounds;
if (isRow)
{
childBounds = new SKRect(position, crossPos, position + childMainSize, crossPos + finalCrossSize);
childBounds = new Rect(position, crossPos, childMainSize, finalCrossSize);
}
else
{
childBounds = new SKRect(crossPos, position, crossPos + finalCrossSize, position + childMainSize);
childBounds = new Rect(crossPos, position, finalCrossSize, childMainSize);
}
child.Arrange(childBounds);