void ArrangeLine(Size finalSize, double v, UvSize line, int start, int end, bool useItemU, double itemU) { double u; var isHorizontal = Orientation == Orientation.Horizontal; if (orientation == Orientation.Vertical) { switch (VerticalContentAlignment) { case VerticalAlignment.Center: u = (finalSize.Height - line.U) / 2; break; case VerticalAlignment.Bottom: u = finalSize.Height - line.U; break; default: u = 0; break; } } else { switch (HorizontalContentAlignment) { case HorizontalAlignment.Center: u = (finalSize.Width - line.U) / 2; break; case HorizontalAlignment.Right: u = finalSize.Width - line.U; break; default: u = 0; break; } } var children = InternalChildren; for (var i = start; i < end; 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(new Rect( isHorizontal ? u : v, isHorizontal ? v : u, isHorizontal ? layoutSlotU : line.V, isHorizontal ? line.V : layoutSlotU)); u += layoutSlotU; } }
protected override Size MeasureOverride(Size constraint) { var curLineSize = new UvSize(Orientation); var panelSize = new UvSize(Orientation); var uvConstraint = new UvSize(Orientation, constraint.Width, constraint.Height); var itemWidth = ItemWidth; var itemHeight = ItemHeight; var itemWidthSet = !double.IsNaN(itemWidth); var itemHeightSet = !double.IsNaN(itemHeight); var childConstraint = new Size( itemWidthSet ? itemWidth : constraint.Width, itemHeightSet ? itemHeight : constraint.Height); var children = InternalChildren; for (int i = 0, count = children.Count; i < count; i++) { var child = children[i]; if (child == null) continue; //Flow passes its own constrint to children child.Measure(childConstraint); //this is the size of the child in UV space var sz = new UvSize( Orientation, itemWidthSet ? itemWidth : child.DesiredSize.Width, itemHeightSet ? itemHeight : child.DesiredSize.Height); if (curLineSize.U + sz.U > uvConstraint.U) { //need to switch to another line panelSize.U = Math.Max(curLineSize.U, panelSize.U); panelSize.V += curLineSize.V; curLineSize = sz; if (!(sz.U > uvConstraint.U)) continue; //the element is wider then the constrint - give it a separate line panelSize.U = Math.Max(sz.U, panelSize.U); panelSize.V += sz.V; curLineSize = new UvSize(Orientation); } else { //continue to accumulate a line curLineSize.U += sz.U; curLineSize.V = Math.Max(sz.V, curLineSize.V); } } //the last line size, if any should be added panelSize.U = Math.Max(curLineSize.U, panelSize.U); panelSize.V += curLineSize.V; //go from UV space to W/H space return new Size(panelSize.Width, panelSize.Height); }
private void ArrangeLine(double v, double lineV, int start, int end, bool useItemU, double itemU) { double u = 0; var isHorizontal = this.Orientation == Orientation.Horizontal; var children = this.InternalChildren; for (var i = start; i < end; i++) { var child = children[i]; if (child != null) { var childSize = new UvSize(this.Orientation, child.DesiredSize.Width, child.DesiredSize.Height); var layoutSlotU = useItemU ? itemU : childSize.U; child.Arrange(new Rect( isHorizontal ? u : v, isHorizontal ? v : u, isHorizontal ? layoutSlotU : lineV, isHorizontal ? lineV : layoutSlotU)); u += layoutSlotU; } } }
/// <summary> /// /// </summary> /// <param name="finalSize"></param> /// <returns></returns> protected override Size ArrangeOverride(Size finalSize) { var firstInLine = 0; var itemWidth = ItemWidth; var itemHeight = ItemHeight; double accumulatedV = 0; var itemU = (Orientation == Orientation.Horizontal ? itemWidth : itemHeight); var curLineSize = new UvSize(Orientation); var uvFinalSize = new UvSize(Orientation, finalSize.Width, finalSize.Height); var itemWidthSet = !double.IsNaN(itemWidth); var itemHeightSet = !double.IsNaN(itemHeight); var useItemU = (Orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet); var children = InternalChildren; for (int i = 0, count = children.Count; i < count; i++) { var child = children[i]; if (child == null) { continue; } var sz = new UvSize( Orientation, (itemWidthSet ? itemWidth : child.DesiredSize.Width), (itemHeightSet ? itemHeight : child.DesiredSize.Height)); if (curLineSize.U + sz.U > uvFinalSize.U) { //need to switch to another line ArrangeLine(finalSize, accumulatedV, curLineSize, firstInLine, i, useItemU, itemU); accumulatedV += curLineSize.V; curLineSize = sz; if (sz.U > uvFinalSize.U) { //the element is wider then the constraint - give it a separate line //switch to next line which only contain one element ArrangeLine(finalSize, accumulatedV, sz, i, ++i, useItemU, itemU); accumulatedV += sz.V; curLineSize = new UvSize(Orientation); } firstInLine = i; } else { //continue to accumulate a line curLineSize.U += sz.U; curLineSize.V = Math.Max(sz.V, curLineSize.V); } } //arrange the last line, if any if (firstInLine < children.Count) { ArrangeLine(finalSize, accumulatedV, curLineSize, firstInLine, children.Count, useItemU, itemU); } return(finalSize); }
/// <summary> /// /// </summary> /// <param name="constraint"></param> /// <returns></returns> protected override Size MeasureOverride(Size constraint) { var curLineSize = new UvSize(Orientation); var panelSize = new UvSize(Orientation); var uvConstraint = new UvSize(Orientation, constraint.Width, constraint.Height); var itemWidth = ItemWidth; var itemHeight = ItemHeight; var itemWidthSet = !double.IsNaN(itemWidth); var itemHeightSet = !double.IsNaN(itemHeight); var childConstraint = new Size( (itemWidthSet ? itemWidth : constraint.Width), (itemHeightSet ? itemHeight : constraint.Height)); var children = InternalChildren; for (int i = 0, count = children.Count; i < count; i++) { var child = children[i]; if (child == null) { continue; } //Flow passes its own constrint to children child.Measure(childConstraint); //this is the size of the child in UV space var sz = new UvSize( Orientation, (itemWidthSet ? itemWidth : child.DesiredSize.Width), (itemHeightSet ? itemHeight : child.DesiredSize.Height)); if (curLineSize.U + sz.U > uvConstraint.U) { //need to switch to another line panelSize.U = Math.Max(curLineSize.U, panelSize.U); panelSize.V += curLineSize.V; curLineSize = sz; if (!(sz.U > uvConstraint.U)) { continue; } //the element is wider then the constrint - give it a separate line panelSize.U = Math.Max(sz.U, panelSize.U); panelSize.V += sz.V; curLineSize = new UvSize(Orientation); } else { //continue to accumulate a line curLineSize.U += sz.U; curLineSize.V = Math.Max(sz.V, curLineSize.V); } } //the last line size, if any should be added panelSize.U = Math.Max(curLineSize.U, panelSize.U); panelSize.V += curLineSize.V; //go from UV space to W/H space return(new Size(panelSize.Width, panelSize.Height)); }
/// <inheritdoc /> protected override Size ArrangeOverride(Size finalSize) { var parentRibbonGroupBox = UIHelper.GetParent <RibbonGroupBox>(this); var isParentRibbonGroupBoxSharedSizeScope = parentRibbonGroupBox != null && Grid.GetIsSharedSizeScope(parentRibbonGroupBox); var firstInLine = 0; var itemWidth = this.ItemWidth; var itemHeight = this.ItemHeight; double accumulatedV = 0; var itemU = this.Orientation == Orientation.Horizontal ? itemWidth : itemHeight; var curLineSize = new UvSize(this.Orientation); var uvFinalSize = new UvSize(this.Orientation, finalSize.Width, finalSize.Height); var itemWidthSet = !double.IsNaN(itemWidth); var itemHeightSet = !double.IsNaN(itemHeight); var useItemU = this.Orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet; var children = this.InternalChildren; var currentColumn = 1; for (int i = 0, count = children.Count; i < count; i++) { var child = children[i]; if (child is null) { continue; } var sz = new UvSize( this.Orientation, itemWidthSet ? itemWidth : child.DesiredSize.Width, itemHeightSet ? itemHeight : child.DesiredSize.Height); if (DoubleUtil.GreaterThan(curLineSize.U + sz.U, uvFinalSize.U)) //need to switch to another line { this.ArrangeLine(accumulatedV, curLineSize.V, firstInLine, i, useItemU, itemU); accumulatedV += curLineSize.V; curLineSize = sz; if (DoubleUtil.GreaterThan(sz.U, uvFinalSize.U)) //the element is wider then the constraint - give it a separate line { //switch to next line which only contain one element this.ArrangeLine(accumulatedV, sz.V, i, ++i, useItemU, itemU); accumulatedV += sz.V; curLineSize = new UvSize(this.Orientation); } firstInLine = i; ++currentColumn; } else //continue to accumulate a line { curLineSize.U += sz.U; curLineSize.V = Math.Max(sz.V, curLineSize.V); } if (isParentRibbonGroupBoxSharedSizeScope && GetExcludeFromSharedSize(child) == false) { SetSharedSizeGroupName(child, $"SharedSizeGroup_Column_{currentColumn}"); } else { SetSharedSizeGroupName(child, null); } } //arrange the last line, if any if (firstInLine < children.Count) { this.ArrangeLine(accumulatedV, curLineSize.V, firstInLine, children.Count, useItemU, itemU); } return(finalSize); }
// ****************************************************************** /// <summary> /// <see cref="FrameworkElement.MeasureOverride"/> /// </summary> protected override Size MeasureOverride(Size constraint) { var curLineSize = new UvSize(Orientation); var panelSize = new UvSize(Orientation); var uvConstraint = new UvSize(Orientation, constraint.Width, constraint.Height); var itemWidth = ItemWidth; var itemHeight = ItemHeight; var itemWidthSet = !double.IsNaN(itemWidth); var itemHeightSet = !double.IsNaN(itemHeight); var childConstraint = new Size( itemWidthSet ? itemWidth : constraint.Width, itemHeightSet ? itemHeight : constraint.Height); var children = InternalChildren; // EO var currentLineInfo = new LineInfo(); // EO, the way it works it is always like we are on the current line _lineInfos.Clear(); _atLeastOneElementCanHasItsWidthExpanded = false; for (int i = 0, count = children.Count; i < count; i++) { var child = children[i]; if (child == null) { continue; } //Flow passes its own constrint to children child.Measure(childConstraint); //this is the size of the child in UV space var sz = new UvSize( Orientation, (itemWidthSet ? itemWidth : child.DesiredSize.Width), (itemHeightSet ? itemHeight : child.DesiredSize.Height)); if (DoubleGreaterThan(curLineSize.U + sz.U, uvConstraint.U)) //need to switch to another line { // EO currentLineInfo.Size = curLineSize; _lineInfos.Add(currentLineInfo); panelSize.U = Math.Max(curLineSize.U, panelSize.U); panelSize.V += curLineSize.V; curLineSize = sz; // EO currentLineInfo = new LineInfo(); var feChild = child as FrameworkElement; if (GetUseToFill(feChild)) { currentLineInfo.ElementsWithNoWidthSet.Add(feChild); _atLeastOneElementCanHasItsWidthExpanded = true; } if (DoubleGreaterThan(sz.U, uvConstraint.U)) //the element is wider then the constrint - give it a separate line { currentLineInfo = new LineInfo(); panelSize.U = Math.Max(sz.U, panelSize.U); panelSize.V += sz.V; curLineSize = new UvSize(Orientation); } } else //continue to accumulate a line { curLineSize.U += sz.U; curLineSize.V = Math.Max(sz.V, curLineSize.V); // EO var feChild = child as FrameworkElement; if (!GetUseToFill(feChild)) { continue; } currentLineInfo.ElementsWithNoWidthSet.Add(feChild); _atLeastOneElementCanHasItsWidthExpanded = true; } } if (curLineSize.U > 0) { currentLineInfo.Size = curLineSize; _lineInfos.Add(currentLineInfo); } //the last line size, if any should be added panelSize.U = Math.Max(curLineSize.U, panelSize.U); panelSize.V += curLineSize.V; // EO return(_atLeastOneElementCanHasItsWidthExpanded ? new Size(constraint.Width, panelSize.Height) : new Size(panelSize.Width, panelSize.Height)); //go from UV space to W/H space }
private void ArrangeLine(Size finalSize, double v, UvSize line, int start, int end, bool useItemU, double itemU) { double u; var isHorizontal = Orientation == Orientation.Horizontal; if (_orientation == Orientation.Vertical) { switch (VerticalContentAlignment) { case VerticalAlignment.Center: u = (finalSize.Height - line.U) / 2; break; case VerticalAlignment.Bottom: u = finalSize.Height - line.U; break; default: u = 0; break; } } else { switch (HorizontalContentAlignment) { case HorizontalAlignment.Center: u = (finalSize.Width - line.U) / 2; break; case HorizontalAlignment.Right: u = finalSize.Width - line.U; break; default: u = 0; break; } } var children = InternalChildren; for (var i = start; i < end; 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(new Rect( isHorizontal ? u : v, isHorizontal ? v : u, isHorizontal ? layoutSlotU : line.V, isHorizontal ? line.V : layoutSlotU)); u += layoutSlotU; } }
protected override Size ArrangeOverride(Size finalSize) { var firstInLine = 0; var itemWidth = ItemWidth; var itemHeight = ItemHeight; double accumulatedV = 0; var itemU = Orientation == Orientation.Horizontal ? itemWidth : itemHeight; var curLineSize = new UvSize(Orientation); var uvFinalSize = new UvSize(Orientation, finalSize.Width, finalSize.Height); var itemWidthSet = !double.IsNaN(itemWidth); var itemHeightSet = !double.IsNaN(itemHeight); var useItemU = Orientation == Orientation.Horizontal ? itemWidthSet : itemHeightSet; var children = InternalChildren; for (int i = 0, count = children.Count; i < count; i++) { var child = children[i]; if (child == null) continue; var sz = new UvSize( Orientation, itemWidthSet ? itemWidth : child.DesiredSize.Width, itemHeightSet ? itemHeight : child.DesiredSize.Height); if (curLineSize.U + sz.U > uvFinalSize.U) { //need to switch to another line ArrangeLine(finalSize, accumulatedV, curLineSize, firstInLine, i, useItemU, itemU); accumulatedV += curLineSize.V; curLineSize = sz; if (sz.U > uvFinalSize.U) { //the element is wider then the constraint - give it a separate line //switch to next line which only contain one element ArrangeLine(finalSize, accumulatedV, sz, i, ++i, useItemU, itemU); accumulatedV += sz.V; curLineSize = new UvSize(Orientation); } firstInLine = i; } else { //continue to accumulate a line curLineSize.U += sz.U; curLineSize.V = Math.Max(sz.V, curLineSize.V); } } //arrange the last line, if any if (firstInLine < children.Count) { ArrangeLine(finalSize, accumulatedV, curLineSize, firstInLine, children.Count, useItemU, itemU); } return finalSize; }