This commit is contained in:
NaBian committed 2021-05-29 21:18:54 +08:00
1 parent 28559e2315
commit aa776316cd
2 files changed
+68 -7

No files matched your search

@@ -20,7 +20,7 @@ namespace HandyControlDemo.Tools.Converter
{
if (value is HatchStyle style)
{
return _brushGenerator.GetHatchBrush(style, ResourceHelper.GetResource<Color>(ResourceToken.DarkPrimaryColor), ResourceHelper.GetResource<Color>(ResourceToken.BackgroundColor));
return _brushGenerator.GetHatchBrush(style, ResourceHelper.GetResource<Color>(ResourceToken.DarkPrimaryColor), Colors.Transparent);
}
return Brushes.Transparent;
}
@@ -84,7 +84,7 @@ namespace HandyControl.Controls
return double.IsNaN(v) || v >= 0.0d && !double.IsPositiveInfinity(v);
}
private void ArrangeLine(double v, double lineV, int start, int end, bool useItemU, double itemU, double spacing)
private void ArrangeWrapLine(double v, double lineV, int start, int end, bool useItemU, double itemU, double spacing)
{
double u = 0;
var isHorizontal = _orientation == Orientation.Horizontal;
@@ -104,6 +104,26 @@ namespace HandyControl.Controls
}
}
private void ArrangeLine(double lineV, bool useItemU, double itemU, double spacing)
{
double u = 0;
var isHorizontal = _orientation == Orientation.Horizontal;
var children = InternalChildren;
for (var i = 0; i < children.Count; i++)
{
var child = children[i];
if (child == null) continue;
var childSize = new UVSize(_orientation, child.DesiredSize.Width, child.DesiredSize.Height);
var layoutSlotU = useItemU ? itemU : childSize.U;
child.Arrange(isHorizontal ? new Rect(u, 0, layoutSlotU, lineV) : new Rect(0, u, lineV, layoutSlotU));
u += layoutSlotU + spacing;
}
}
protected override Size MeasureOverride(Size constraint)
{
var curLineSize = new UVSize(_orientation);
@@ -123,6 +143,8 @@ namespace HandyControl.Controls
var children = InternalChildren;
var isFirst = true;
if (childWrapping == VisualWrapping.Wrap)
{
for (int i = 0, count = children.Count; i < count; i++)
{
var child = children[i];
@@ -135,7 +157,7 @@ namespace HandyControl.Controls
itemWidthSet ? itemWidth : child.DesiredSize.Width,
itemHeightSet ? itemHeight : child.DesiredSize.Height);
if (childWrapping == VisualWrapping.Wrap && MathHelper.GreaterThan(curLineSize.U + sz.U + spacing, uvConstraint.U))
if (MathHelper.GreaterThan(curLineSize.U + sz.U + spacing, uvConstraint.U))
{
panelSize.U = Math.Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V + spacing;
@@ -158,6 +180,38 @@ namespace HandyControl.Controls
isFirst = false;
}
}
}
else
{
var layoutSlotSize = constraint;
if (_orientation == Orientation.Horizontal)
{
layoutSlotSize.Width = double.PositiveInfinity;
}
else
{
layoutSlotSize.Height = double.PositiveInfinity;
}
for (int i = 0, count = children.Count; i < count; ++i)
{
var child = children[i];
if (child == null) continue;
child.Measure(layoutSlotSize);
var sz = new UVSize(
_orientation,
itemWidthSet ? itemWidth : child.DesiredSize.Width,
itemHeightSet ? itemHeight : child.DesiredSize.Height);
curLineSize.U += isFirst ? sz.U : sz.U + spacing;
curLineSize.V = Math.Max(sz.V, curLineSize.V);
isFirst = false;
}
}
panelSize.U = Math.Max(curLineSize.U, panelSize.U);
panelSize.V += curLineSize.V;
@@ -183,6 +237,8 @@ namespace HandyControl.Controls
var children = InternalChildren;
var isFirst = true;
if (childWrapping == VisualWrapping.Wrap)
{
for (int i = 0, count = children.Count; i < count; i++)
{
var child = children[i];
@@ -193,16 +249,16 @@ namespace HandyControl.Controls
itemWidthSet ? itemWidth : child.DesiredSize.Width,
itemHeightSet ? itemHeight : child.DesiredSize.Height);
if (childWrapping == VisualWrapping.Wrap && MathHelper.GreaterThan(curLineSize.U + sz.U + spacing, uvFinalSize.U))
if (MathHelper.GreaterThan(curLineSize.U + sz.U + spacing, uvFinalSize.U))
{
ArrangeLine(accumulatedV, curLineSize.V, firstInLine, i, useItemU, itemU, spacing);
ArrangeWrapLine(accumulatedV, curLineSize.V, firstInLine, i, useItemU, itemU, spacing);
accumulatedV += curLineSize.V + spacing;
curLineSize = sz;
if (MathHelper.GreaterThan(sz.U, uvFinalSize.U))
{
ArrangeLine(accumulatedV, sz.V, i, ++i, useItemU, itemU, spacing);
ArrangeWrapLine(accumulatedV, sz.V, i, ++i, useItemU, itemU, spacing);
accumulatedV += sz.V + spacing;
curLineSize = new UVSize(_orientation);
@@ -222,7 +278,12 @@ namespace HandyControl.Controls
if (firstInLine < children.Count)
{
ArrangeLine(accumulatedV, curLineSize.V, firstInLine, children.Count, useItemU, itemU, spacing);
ArrangeWrapLine(accumulatedV, curLineSize.V, firstInLine, children.Count, useItemU, itemU, spacing);
}
}
else
{
ArrangeLine(uvFinalSize.V, useItemU, itemU, spacing);
}
return finalSize;