/// <summary> /// <see cref="ILayoutBox"/> rectangle in view coordinates. /// </summary> public static RectangleF Frame(this ILayoutBox box) { return(new RectangleF( box.MarginLeft + box.OuterBounds.Left, box.MarginTop + box.OuterBounds.Top, box.Width, box.Height)); }
private void validateMeasures(ILayoutBox layoutComponent) { // Currently margins and paddings don't support related lengths (Ratios like 1x, 5x). //if (layoutComponent.Margin.HasUnitOf(UnitType.Ratio)) // throw new NotSupportedException("Siblings related lengths are not supported on margins"); //if (layoutComponent.Padding.HasUnitOf(UnitType.Ratio)) // throw new NotSupportedException("Siblings related lengths are not supported on paddings"); }
/// <summary> /// Layout box center in <see cref="ILayoutBox.OuterBounds"/> coordinates in pixels. /// </summary> public static PointF BoundsCenter(this ILayoutBox box) { var frame = box.Bounds(); return(new PointF(frame.Left + frame.Width / 2, frame.Top + frame.Height / 2)); }
/// <summary> /// <see cref="ILayoutBox"/> size /// </summary> public static SizeF Size(this ILayoutBox box) { return(new SizeF(box.Width, box.Height)); }
/// <summary> /// <see cref="ILayoutBox"/> rectangle in <see cref="ILayoutBox.OuterBounds"/> coordinates. /// </summary> public static RectangleF Bounds(this ILayoutBox box) { return(new RectangleF(box.MarginLeft, box.MarginTop, box.Width, box.Height)); }
private LayoutBoxInformation calculateRelativeLayoutBoxes(ILayoutBox layoutComponent, AbsoluteSize clientSize) { RelativeLength width = layoutComponent.Width; RelativeLength height = layoutComponent.Height; var component = (IComponent)layoutComponent; var siblings = component.Parent.Children.Where(x => x != component); var totalSiblingsWidth = siblings.Where(x => x is ILayoutBox).Select(x => ((ILayoutBox)x).Width).Aggregate((total, sibling) => { return(total + sibling); }); var totalSiblingsHeight = siblings.Where(x => x is ILayoutBox).Select(x => ((ILayoutBox)x).Height).Aggregate((total, sibling) => { return(total + sibling); }); var totalWidth = totalSiblingsWidth + width; var totalHeight = totalSiblingsHeight + height; // Does it have related length (Like 1x or 5x)? var hasRelatedWidth = width[UnitType.Ratio] != 0; var hasRelatedHeight = height[UnitType.Ratio] != 0; // Assume siblings related lengths to '0' if this component is 'Fill' if (width == RelativeLength.Infinity) { totalSiblingsWidth -= totalSiblingsWidth[UnitType.Ratio]; } if (height == RelativeLength.Infinity) { totalSiblingsHeight -= totalSiblingsHeight[UnitType.Ratio]; } // Assume the length as 'Fill' if this component have related length but siblings don't. if (hasRelatedWidth && totalSiblingsWidth[UnitType.Ratio] == 0) { width = RelativeLength.Infinity; } if (hasRelatedHeight && totalSiblingsHeight[UnitType.Ratio] == 0) { height = RelativeLength.Infinity; } // Assume the length as 'content length' if this component is 'Shrink' and at least one of the siblings has related or fill length. if (width == RelativeLength.NaN && (totalSiblingsWidth[UnitType.Ratio] != 0 || totalSiblingsWidth == RelativeLength.Infinity)) { width = calculateContentWidth(layoutComponent); } if (height == RelativeLength.NaN && (totalSiblingsHeight[UnitType.Ratio] != 0 || totalSiblingsHeight == RelativeLength.Infinity)) { height = calculateContentHeight(layoutComponent); } // Calculate size var absoluteWidth = calculateLength(width, totalWidth, clientSize.Width); var absoluteHeight = calculateLength(height, totalHeight, clientSize.Height); // Calculate margins (based on parent client area) var marginTop = calculateLength(layoutComponent.Margin.Top, clientSize.Height); var marginRight = calculateLength(layoutComponent.Margin.Right, clientSize.Width); var marginBottom = calculateLength(layoutComponent.Margin.Bottom, clientSize.Height); var marginLeft = calculateLength(layoutComponent.Margin.Left, clientSize.Width); // Calculate paddings (based on self client area) var paddingTop = calculateLength(layoutComponent.Padding.Top, absoluteHeight); var paddingRight = calculateLength(layoutComponent.Padding.Right, absoluteWidth); var paddingBottom = calculateLength(layoutComponent.Padding.Bottom, absoluteHeight); var paddingLeft = calculateLength(layoutComponent.Padding.Left, absoluteWidth); return(new LayoutBoxInformation() { AbsoluteMarginBox = new AbsoluteRectangle( 0, 0, absoluteWidth + marginLeft + marginRight, absoluteHeight + marginTop + marginBottom ), AbsoluteBox = new AbsoluteRectangle( marginLeft, marginTop, absoluteWidth, absoluteHeight ), AbsolutePaddingBox = new AbsoluteRectangle( marginLeft + paddingLeft, marginTop + paddingTop, absoluteWidth - paddingLeft - paddingRight, absoluteHeight - paddingTop - paddingBottom ), LayoutDirection = layoutComponent.LayoutDirection }); }
private RelativeLength calculateContentWidth(ILayoutBox layoutComponent) { return(RelativeLength.Zero); }
/// <summary> /// Place this box above provided reference layout box. Reference is in view coordinate system. /// </summary> public static T Above <T>(this T box, ILayoutBox reference, float dx = 0) where T : ILayoutBox { return(box.Above(reference.Frame(), dx)); }
/// <summary> /// Place this box below provided reference layout box. Reference is in view coordinate system. /// </summary> public static T Below <T>(this T box, ILayoutBox reference, float dx = 0) where T : ILayoutBox { return(box.Below(reference.Frame(), dx)); }
/// <summary> /// Build <see cref="IViewLayoutBox"/>. /// </summary> /// <param name="v">View geometry (usually cross platform View wrapper)</param> /// <param name="outerBounds">Optional outer bounds to override this builder <see cref="OuterBounds"/>.</param> public IViewLayoutBox View(PlatformView v, ILayoutBox outerBounds) { return(View(v, outerBounds.Frame())); }
/// <summary> /// Builds box with specified outerBounds, padding and units. /// </summary> /// <returns>The box.</returns> /// <param name="outerBounds">Outer bounds.</param> public ILayoutBox Box(ILayoutBox outerBounds) { return(Box(outerBounds.Frame())); }
public LayoutBoxInformation GetLayoutBoxInformation(ILayoutBox component) { return(layoutBoxes[component]); }