Skip to content

Commit

Permalink
Add Fill type of Ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcginnes committed Dec 1, 2016
1 parent 05a3cbf commit b70fab0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/AutoGrid/StackPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected override Size MeasureOverride(Size constraint)
double accumulatedHeight = 0;

var isHorizontal = Orientation == Orientation.Horizontal;
var totalMarginToAdd = CalculateTotalMarginToAdd(children, isHorizontal, MarginBetweenChildren);
var totalMarginToAdd = CalculateTotalMarginToAdd(children, MarginBetweenChildren);

for (int i = 0; i < children.Count; i++)
{
Expand Down Expand Up @@ -123,16 +123,16 @@ protected override Size ArrangeOverride(Size arrangeSize)
var isHorizontal = Orientation == Orientation.Horizontal;
var marginBetweenChildren = MarginBetweenChildren;

var totalMarginToAdd = CalculateTotalMarginToAdd(children, isHorizontal, marginBetweenChildren);
var totalMarginToAdd = CalculateTotalMarginToAdd(children, marginBetweenChildren);

double allAutoSizedSum = 0.0;
int countOfFillTypes = 0;
foreach (var child in children.OfType<UIElement>())
{
var fillType = GetFill(child);
if (fillType == StackPanelFill.Fill)
if (fillType != StackPanelFill.Auto)
{
if (child.Visibility != Visibility.Collapsed)
if (child.Visibility != Visibility.Collapsed && fillType != StackPanelFill.Ignored)
countOfFillTypes += 1;
}
else
Expand All @@ -152,10 +152,10 @@ protected override Size ArrangeOverride(Size arrangeSize)
UIElement child = children[i];
if (child == null) { continue; }
Size childDesiredSize = child.DesiredSize;
var isCollapsed = child.Visibility == Visibility.Collapsed;
var fillType = GetFill(child);
var isCollapsed = child.Visibility == Visibility.Collapsed || fillType == StackPanelFill.Ignored;
var isLastChild = i == totalChildrenCount - 1;
var marginToAdd = isLastChild || isCollapsed ? 0 : marginBetweenChildren;
var fillType = GetFill(child);

Rect rcChild = new Rect(
accumulatedLeft,
Expand All @@ -182,11 +182,11 @@ protected override Size ArrangeOverride(Size arrangeSize)
return arrangeSize;
}

static double CalculateTotalMarginToAdd(UIElementCollection children, bool isHorizontal, double marginBetweenChildren)
static double CalculateTotalMarginToAdd(UIElementCollection children, double marginBetweenChildren)
{
var visibleChildrenCount = children
.OfType<UIElement>()
.Count(x => x.Visibility != Visibility.Collapsed);
.Count(x => x.Visibility != Visibility.Collapsed && GetFill(x) != StackPanelFill.Ignored);
var marginMultiplier = Math.Max(visibleChildrenCount - 1, 0);
var totalMarginToAdd = marginBetweenChildren * marginMultiplier;
return totalMarginToAdd;
Expand Down Expand Up @@ -240,6 +240,6 @@ public static StackPanelFill GetFill(DependencyObject element)

public enum StackPanelFill
{
Auto, Fill
Auto, Fill, Ignored
}
}

0 comments on commit b70fab0

Please sign in to comment.