/// <inheritdoc/> /// <since_tizen> 9 </since_tizen> protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom) { for (int i = 0; i < LayoutChildren.Count; i++) { LayoutItem childLayout = LayoutChildren[i]; if (childLayout != null) { Geometry horizontalGeometry = GetHorizontalLayout(childLayout.Owner); Geometry verticalGeometry = GetVerticalLayout(childLayout.Owner); // MeasureChildWithMargins() is called to assign child's MeasuredWidth/Height to calculate grand children's sizes correctly. // Grand children's positions are calculated correctly only if their sizes are calculated correctly. // MeasureChildWithMargins() should be called before childLayout.Layout() to use childLayout's MeasuredWidth/Height // when the grand children's positions are calculated. // // FIXME: It would be better if MeasureChildWithMargins() are called in OnMeasure() to separate Measure and Layout calculations. // For now, not to call duplicate GetHorizontalLayout() and GetVerticalLayout() in both OnMeasure() and OnLayout(), // MeasureChildWithMargins() is called here. MeasureChildWithMargins(childLayout, new MeasureSpecification(new LayoutLength(horizontalGeometry.Size), MeasureSpecification.ModeType.Exactly), new LayoutLength(0), new MeasureSpecification(new LayoutLength(verticalGeometry.Size), MeasureSpecification.ModeType.Exactly), new LayoutLength(0)); LayoutLength childLeft = new LayoutLength(horizontalGeometry.Position + Padding.Start + childLayout.Margin.Start); LayoutLength childRight = new LayoutLength(horizontalGeometry.Position + horizontalGeometry.Size + Padding.Start - childLayout.Margin.End); LayoutLength childTop = new LayoutLength(verticalGeometry.Position + Padding.Top + childLayout.Margin.Top); LayoutLength childBottom = new LayoutLength(verticalGeometry.Position + verticalGeometry.Size + Padding.Top - childLayout.Margin.Bottom); childLayout.Layout(childLeft, childTop, childRight, childBottom); } } HorizontalRelativeCache.Clear(); VerticalRelativeCache.Clear(); }
/// <inheritdoc/> /// <since_tizen> 9 </since_tizen> protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom) { for (int i = 0; i < LayoutChildren.Count; i++) { LayoutItem childLayout = LayoutChildren[i]; if (childLayout != null) { Geometry horizontalGeometry = GetHorizontalLayout(childLayout.Owner); Geometry verticalGeometry = GetVerticalLayout(childLayout.Owner); LayoutLength childLeft = new LayoutLength(horizontalGeometry.Position + Padding.Start + childLayout.Margin.Start); LayoutLength childRight = new LayoutLength(horizontalGeometry.Position + horizontalGeometry.Size + Padding.Start - childLayout.Margin.End); LayoutLength childTop = new LayoutLength(verticalGeometry.Position + Padding.Top + childLayout.Margin.Top); LayoutLength childBottom = new LayoutLength(verticalGeometry.Position + verticalGeometry.Size + Padding.Top - childLayout.Margin.Bottom); childLayout.Layout(childLeft, childTop, childRight, childBottom); } } HorizontalRelativeCache.Clear(); VerticalRelativeCache.Clear(); }
/// <summary> /// Assign a size and position to each of its children.<br /> /// </summary> /// <param name="changed">This is a new size or position for this layout.</param> /// <param name="left">Left position, relative to parent.</param> /// <param name="top"> Top position, relative to parent.</param> /// <param name="right">Right position, relative to parent.</param> /// <param name="bottom">Bottom position, relative to parent.</param> /// <since_tizen> 6 </since_tizen> protected override void OnLayout(bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom) { // Absolute layout positions it's children at their Actor positions. // Children could overlap or spill outside the parent, as is the nature of absolute positions. for (int i = 0; i < LayoutChildren.Count; i++) { LayoutItem childLayout = LayoutChildren[i]; if (childLayout != null) { LayoutLength childWidth = childLayout.MeasuredWidth.Size; LayoutLength childHeight = childLayout.MeasuredHeight.Size; Position2D childPosition = childLayout.Owner.Position2D; LayoutLength childLeft = new LayoutLength(childPosition.X); LayoutLength childTop = new LayoutLength(childPosition.Y); childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight, true); } } }
/// <summary> /// Assign a size and position to each of its children.<br /> /// </summary> /// <param name="changed">This is a new size or position for this layout.</param> /// <param name="left">Left position, relative to parent.</param> /// <param name="top"> Top position, relative to parent.</param> /// <param name="right">Right position, relative to parent.</param> /// <param name="bottom">Bottom position, relative to parent.</param> /// <since_tizen> 6 </since_tizen> protected override void OnLayout( bool changed, LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom ) { bool isLayoutRtl = Owner.LayoutDirection == ViewLayoutDirectionType.RTL; LayoutLength width = right - left; LayoutLength height = bottom - top; // Call to FlexLayout implementation to calculate layout values for later retrieval. Interop.FlexLayout.FlexLayout_CalculateLayout( swigCPtr, width.AsDecimal(), height.AsDecimal(), isLayoutRtl ); int count = LayoutChildren.Count; for( int childIndex = 0; childIndex < count; childIndex++) { LayoutItem childLayout = LayoutChildren[childIndex]; if( childLayout != null ) { // Get the frame for the child, start, top, end, bottom. Vector4 frame = new Vector4(Interop.FlexLayout.FlexLayout_GetNodeFrame(swigCPtr, childIndex ), true); childLayout.Layout( new LayoutLength(frame.X), new LayoutLength(frame.Y), new LayoutLength(frame.Z), new LayoutLength(frame.W) ); } } }
protected void LayoutForIndependentChild() { int count = LayoutChildren.Count; for (int childIndex = 0; childIndex < count; childIndex++) { LayoutItem childLayout = LayoutChildren[childIndex]; if (childLayout != null) { if (childLayout.Owner.ExcludeLayouting) { LayoutLength childWidth = childLayout.MeasuredWidth.Size; LayoutLength childHeight = childLayout.MeasuredHeight.Size; Position2D childPosition = childLayout.Owner.Position2D; LayoutLength childPositionX = new LayoutLength(childPosition.X); LayoutLength childPositionY = new LayoutLength(childPosition.Y); childLayout.Layout(childPositionX, childPositionY, childPositionX + childWidth, childPositionY + childHeight, true); } } } }
} // LayoutHorizontally private void LayoutVertical(LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom) { LayoutLength childTop = new LayoutLength(Padding.Top); LayoutLength childLeft = new LayoutLength(Padding.Start); // Where end of child should go LayoutLength width = new LayoutLength(right - left); // Space available for child LayoutLength childSpace = new LayoutLength(width - Padding.Start - Padding.End); List <LayoutItem> LinearChildren = IterateLayoutChildren().ToList(); int count = LinearChildren.Count; switch (LinearAlignment) { case Alignment.Bottom: // totalLength contains the padding already childTop = new LayoutLength(Padding.Top + bottom.AsDecimal() - top.AsDecimal() - _totalLength); break; case Alignment.CenterVertical: // FALL THROUGH case Alignment.Center: // totalLength contains the padding already childTop = new LayoutLength(Padding.Top + (bottom.AsDecimal() - top.AsDecimal() - _totalLength) / 2.0f); break; case Alignment.Top: // FALL THROUGH (default) default: // totalLength contains the padding already childTop = new LayoutLength(Padding.Top); break; } for (int i = 0; i < count; i++) { LayoutItem childLayout = LinearChildren[i]; LayoutLength childWidth = childLayout.MeasuredWidth.Size; LayoutLength childHeight = childLayout.MeasuredHeight.Size; Extents childMargin = childLayout.Margin; childTop += childMargin.Top; switch (LinearAlignment) { case Alignment.Begin: default: { childLeft = new LayoutLength(Padding.Start + childMargin.Start); break; } case Alignment.End: { childLeft = new LayoutLength(width - Padding.End - childWidth - childMargin.End); break; } case Alignment.CenterHorizontal: case Alignment.Center: // FALL THROUGH { childLeft = new LayoutLength(Padding.Start + ((childSpace - childWidth).AsDecimal() / 2.0f) + childMargin.Start - childMargin.End); break; } } childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); childTop += childHeight + childMargin.Bottom + ((i < count - 1) ? CellPadding.Height : 0); } } // LayoutVertical
} // MeasureVertical private void LayoutHorizontal(LayoutLength left, LayoutLength top, LayoutLength right, LayoutLength bottom) { bool isLayoutRtl = Owner.LayoutDirection == ViewLayoutDirectionType.RTL; LayoutLength childTop = new LayoutLength(Padding.Top); LayoutLength childLeft = new LayoutLength(Padding.Start); // Where bottom of child should go LayoutLength height = new LayoutLength(bottom - top); // Space available for child LayoutLength childSpace = new LayoutLength(height - Padding.Top - Padding.Bottom); List <LayoutItem> LinearChildren = IterateLayoutChildren().ToList(); int count = LinearChildren.Count; switch (LinearAlignment) { case Alignment.End: // totalLength contains the padding already // In case of RTL map END alignment to the left edge if (isLayoutRtl) { childLeft = new LayoutLength(Padding.Start); } else { childLeft = new LayoutLength(Padding.Start + right.AsDecimal() - left.AsDecimal() - _totalLength); } break; case Alignment.CenterHorizontal: // FALL THROUGH case Alignment.Center: // totalLength contains the padding already childLeft = new LayoutLength(Padding.Start + (right.AsDecimal() - left.AsDecimal() - _totalLength) / 2.0f); break; case Alignment.Begin: // FALL THROUGH (default) default: // totalLength contains the padding already // In case of RTL map BEGIN alignment to the right edge if (isLayoutRtl) { childLeft = new LayoutLength(Padding.Start + right.AsDecimal() - left.AsDecimal() - _totalLength); } else { childLeft = new LayoutLength(Padding.Start); } break; } int start = 0; int dir = 1; // In case of RTL, start drawing from the last child. if (isLayoutRtl) { start = count - 1; dir = -1; } for (int i = 0; i < count; i++) { int childIndex = start + dir * i; // Get a reference to the childLayout at the given index LayoutItem childLayout = LinearChildren[childIndex]; LayoutLength childWidth = childLayout.MeasuredWidth.Size; LayoutLength childHeight = childLayout.MeasuredHeight.Size; Extents childMargin = childLayout.Margin; switch (LinearAlignment) { case Alignment.Bottom: childTop = new LayoutLength(height - Padding.Bottom - childHeight - childMargin.Bottom); break; case Alignment.CenterVertical: case Alignment.Center: // FALLTHROUGH childTop = new LayoutLength(Padding.Top + ((childSpace - childHeight).AsDecimal() / 2.0f) + childMargin.Top - childMargin.Bottom); break; case Alignment.Top: // FALLTHROUGH default default: childTop = new LayoutLength(Padding.Top + childMargin.Top); break; } childLeft += childMargin.Start; childLayout.Layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight); childLeft += childWidth + childMargin.End + ((i < count - 1) ? CellPadding.Width : 0); } } // LayoutHorizontally