fix: close #1374
This commit is contained in:
1 parent
4206bfd61c
commit
81ddae5f58
9 files changed
+81
-89
No files matched your search
@@ -9,7 +9,7 @@ namespace HandyControl.Controls;
|
||||
public class Col : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty LayoutProperty = DependencyProperty.Register(
|
||||
nameof(Layout), typeof(ColLayout), typeof(Col), new PropertyMetadata(default(ColLayout)));
|
||||
nameof(Layout), typeof(ColLayout), typeof(Col), new FrameworkPropertyMetadata(default(ColLayout), FrameworkPropertyMetadataOptions.AffectsParentMeasure));
|
||||
|
||||
public ColLayout Layout
|
||||
{
|
||||
@@ -18,7 +18,7 @@ public class Col : ContentControl
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty OffsetProperty = DependencyProperty.Register(
|
||||
nameof(Offset), typeof(int), typeof(Col), new PropertyMetadata(ValueBoxes.Int0Box));
|
||||
nameof(Offset), typeof(int), typeof(Col), new FrameworkPropertyMetadata(ValueBoxes.Int0Box, FrameworkPropertyMetadataOptions.AffectsParentMeasure));
|
||||
|
||||
public int Offset
|
||||
{
|
||||
@@ -27,12 +27,12 @@ public class Col : ContentControl
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SpanProperty = DependencyProperty.Register(
|
||||
nameof(Span), typeof(int), typeof(Col), new PropertyMetadata(24), OnSpanValidate);
|
||||
nameof(Span), typeof(int), typeof(Col), new FrameworkPropertyMetadata(ColLayout.ColMaxCellCount, FrameworkPropertyMetadataOptions.AffectsParentMeasure), OnSpanValidate);
|
||||
|
||||
private static bool OnSpanValidate(object value)
|
||||
{
|
||||
var v = (int) value;
|
||||
return v is >= 1 and <= 24;
|
||||
return v is >= 1 and <= ColLayout.ColMaxCellCount;
|
||||
}
|
||||
|
||||
public int Span
|
||||
@@ -42,7 +42,7 @@ public class Col : ContentControl
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsFixedProperty = DependencyProperty.Register(
|
||||
nameof(IsFixed), typeof(bool), typeof(Col), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
nameof(IsFixed), typeof(bool), typeof(Col), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsParentMeasure));
|
||||
|
||||
public bool IsFixed
|
||||
{
|
||||
@@ -52,44 +52,26 @@ public class Col : ContentControl
|
||||
|
||||
internal int GetLayoutCellCount(ColLayoutStatus status)
|
||||
{
|
||||
var result = 0;
|
||||
|
||||
if (Layout != null)
|
||||
if (Layout is not null)
|
||||
{
|
||||
if (!IsFixed)
|
||||
return status switch
|
||||
{
|
||||
switch (status)
|
||||
{
|
||||
case ColLayoutStatus.Xs:
|
||||
result = Layout.Xs;
|
||||
break;
|
||||
case ColLayoutStatus.Sm:
|
||||
result = Layout.Sm;
|
||||
break;
|
||||
case ColLayoutStatus.Md:
|
||||
result = Layout.Md;
|
||||
break;
|
||||
case ColLayoutStatus.Lg:
|
||||
result = Layout.Lg;
|
||||
break;
|
||||
case ColLayoutStatus.Xl:
|
||||
result = Layout.Xl;
|
||||
break;
|
||||
case ColLayoutStatus.Xxl:
|
||||
result = Layout.Xxl;
|
||||
break;
|
||||
case ColLayoutStatus.Auto:
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(status), status, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
result = Span;
|
||||
ColLayoutStatus.Xs => Layout.Xs,
|
||||
ColLayoutStatus.Sm => Layout.Sm,
|
||||
ColLayoutStatus.Md => Layout.Md,
|
||||
ColLayoutStatus.Lg => Layout.Lg,
|
||||
ColLayoutStatus.Xl => Layout.Xl,
|
||||
ColLayoutStatus.Xxl => Layout.Xxl,
|
||||
ColLayoutStatus.Auto => 0,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(status), status, null),
|
||||
};
|
||||
}
|
||||
|
||||
return result;
|
||||
if (IsFixed)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Span;
|
||||
}
|
||||
}
|
||||
@@ -14,12 +14,15 @@ public class Row : Panel
|
||||
|
||||
private double _maxChildDesiredHeight;
|
||||
|
||||
private double _totalAutoWidth;
|
||||
private double _fixedWidth;
|
||||
|
||||
public static readonly DependencyProperty GutterProperty = DependencyProperty.Register(
|
||||
nameof(Gutter), typeof(double), typeof(Row), new PropertyMetadata(ValueBoxes.Double0Box, null, OnGutterCoerce), ValidateHelper.IsInRangeOfPosDoubleIncludeZero);
|
||||
nameof(Gutter), typeof(double), typeof(Row), new FrameworkPropertyMetadata(
|
||||
ValueBoxes.Double0Box, FrameworkPropertyMetadataOptions.AffectsMeasure, null, OnGutterCoerce),
|
||||
ValidateHelper.IsInRangeOfPosDoubleIncludeZero);
|
||||
|
||||
private static object OnGutterCoerce(DependencyObject d, object basevalue) => ValidateHelper.IsInRangeOfPosDoubleIncludeZero(basevalue) ? basevalue : .0;
|
||||
private static object OnGutterCoerce(DependencyObject d, object basevalue) =>
|
||||
ValidateHelper.IsInRangeOfPosDoubleIncludeZero(basevalue) ? basevalue : .0;
|
||||
|
||||
public double Gutter
|
||||
{
|
||||
@@ -29,51 +32,59 @@ public class Row : Panel
|
||||
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
var gutter = Gutter;
|
||||
var totalCellCount = 0;
|
||||
var totalRowCount = 1;
|
||||
var gutterHalf = Gutter / 2;
|
||||
_totalAutoWidth = 0;
|
||||
_fixedWidth = 0;
|
||||
_maxChildDesiredHeight = 0;
|
||||
var cols = InternalChildren.OfType<Col>().ToList();
|
||||
|
||||
foreach (var child in InternalChildren.OfType<Col>())
|
||||
foreach (var child in cols)
|
||||
{
|
||||
child.Margin = new Thickness(gutterHalf);
|
||||
child.Measure(constraint);
|
||||
var childDesiredSize = child.DesiredSize;
|
||||
|
||||
if (_maxChildDesiredHeight < childDesiredSize.Height)
|
||||
{
|
||||
_maxChildDesiredHeight = childDesiredSize.Height;
|
||||
}
|
||||
|
||||
var cellCount = child.GetLayoutCellCount(_layoutStatus);
|
||||
totalCellCount += cellCount;
|
||||
|
||||
if (totalCellCount > ColLayout.ColMaxCellCount)
|
||||
{
|
||||
totalCellCount = cellCount;
|
||||
totalRowCount++;
|
||||
}
|
||||
|
||||
if (cellCount == 0 || child.IsFixed)
|
||||
{
|
||||
_totalAutoWidth += childDesiredSize.Width;
|
||||
child.Measure(constraint);
|
||||
_maxChildDesiredHeight = Math.Max(_maxChildDesiredHeight, child.DesiredSize.Height);
|
||||
_fixedWidth += child.DesiredSize.Width + gutter;
|
||||
}
|
||||
}
|
||||
|
||||
return new Size(0, _maxChildDesiredHeight * totalRowCount - Gutter);
|
||||
var itemWidth = (constraint.Width - _fixedWidth + gutter) / ColLayout.ColMaxCellCount;
|
||||
itemWidth = Math.Max(0, itemWidth);
|
||||
|
||||
foreach (var child in cols)
|
||||
{
|
||||
var cellCount = child.GetLayoutCellCount(_layoutStatus);
|
||||
if (cellCount > 0 && !child.IsFixed)
|
||||
{
|
||||
totalCellCount += cellCount;
|
||||
child.Measure(new Size(cellCount * itemWidth - gutter, constraint.Height));
|
||||
_maxChildDesiredHeight = Math.Max(_maxChildDesiredHeight, child.DesiredSize.Height);
|
||||
|
||||
if (totalCellCount > ColLayout.ColMaxCellCount)
|
||||
{
|
||||
totalCellCount = cellCount;
|
||||
totalRowCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new Size(0, _maxChildDesiredHeight * totalRowCount);
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
var gutter = Gutter;
|
||||
var totalCellCount = 0;
|
||||
var gutterHalf = Gutter / 2;
|
||||
var itemWidth = (finalSize.Width - _totalAutoWidth + Gutter) / ColLayout.ColMaxCellCount;
|
||||
var cols = InternalChildren.OfType<Col>().ToList();
|
||||
var itemWidth = (finalSize.Width - _fixedWidth + gutter) / ColLayout.ColMaxCellCount;
|
||||
itemWidth = Math.Max(0, itemWidth);
|
||||
|
||||
var childBounds = new Rect(-gutterHalf, -gutterHalf, 0, _maxChildDesiredHeight);
|
||||
var childBounds = new Rect(0, 0, 0, _maxChildDesiredHeight);
|
||||
_layoutStatus = ColLayout.GetLayoutStatus(finalSize.Width);
|
||||
|
||||
foreach (var child in InternalChildren.OfType<Col>())
|
||||
foreach (var child in cols)
|
||||
{
|
||||
if (!child.IsVisible)
|
||||
{
|
||||
@@ -83,19 +94,19 @@ public class Row : Panel
|
||||
var cellCount = child.GetLayoutCellCount(_layoutStatus);
|
||||
totalCellCount += cellCount;
|
||||
|
||||
var childWidth = cellCount > 0 ? cellCount * itemWidth : child.DesiredSize.Width;
|
||||
|
||||
var childWidth = (cellCount > 0 && !child.IsFixed) ? cellCount * itemWidth - gutter : child.DesiredSize.Width;
|
||||
childBounds.Width = childWidth;
|
||||
childBounds.X += child.Offset * itemWidth;
|
||||
|
||||
if (totalCellCount > ColLayout.ColMaxCellCount)
|
||||
{
|
||||
childBounds.X = -gutterHalf;
|
||||
childBounds.X = 0;
|
||||
childBounds.Y += _maxChildDesiredHeight;
|
||||
totalCellCount = cellCount;
|
||||
}
|
||||
|
||||
child.Arrange(childBounds);
|
||||
childBounds.X += childWidth;
|
||||
childBounds.X += childWidth + gutter;
|
||||
}
|
||||
|
||||
return finalSize;
|
||||
|
||||
Reference in new issue
Block a user