public override void Resize(int x, int y) { LastParentSize.X = x; LastParentSize.Y = y; Inited = true; Rect.Resize(x, y); if (Columns == 0 || Rows == 0) { return; // must have at least one of each } PixelSize = Rect.GetPixelSize(); AvalableSize.X = PixelSize.X - (CellPadding * (Columns + 1)); AvalableSize.Y = PixelSize.Y - (CellPadding * (Rows + 1)); CellSize = new Vector2(AvalableSize.X / Columns, AvalableSize.Y / Rows); ColSpanSize = new Vector2(PixelSize.X - (CellPadding * 2), CellSize.Y); if (CellSize.X < 2 || CellSize.Y < 2) { return; // there isn't enough room to do anything } foreach (var child in Children) { GridLayoutInfo info = child.LayoutTag as GridLayoutInfo; if (info == null) { continue; } Vector2 thisCellSize = CellSize; var colInfo = ColSpanRows.Find((i) => i.StartRow == info.Row); if (colInfo != null) { thisCellSize.X = ColSpanSize.X; thisCellSize.Y = (ColSpanSize.Y * colInfo.Lenght) + (CellPadding * (colInfo.Lenght - 1)); } OriginLocation location = child.Rect.AnchorLocation; float itemHeight = thisCellSize.Y; if ((colInfo == null || colInfo.Lenght == 1) && (MaxChildSize > 0 && thisCellSize.Y > MaxChildSize)) // if the cell is larger than one high, they can't clamp it { itemHeight = MaxChildSize; location = OriginTools.GetMiddleAnhcor(location); } // compute where the child's origin needs to be for it's anchor relative to the cell Vector2 childOrigin = GetChildOrigin(GetCellOrigin(info.Row, colInfo != null ? 0 : info.Col, colInfo != null ? colInfo.Lenght : 1), thisCellSize, itemHeight, location); child.Rect.X.RelativeTo = RelativeLoc.Edge.Raw; child.Rect.X.Paramater = childOrigin.X; child.Rect.Y.RelativeTo = RelativeLoc.Edge.Raw; child.Rect.Y.Paramater = childOrigin.Y; child.Rect.Width.Mode = RelativeSize.SizeModes.Raw; child.Rect.Width.Paramater = thisCellSize.X; child.Rect.Height.Mode = RelativeSize.SizeModes.Raw; child.Rect.Height.Paramater = itemHeight; // have the child size itself and it's children to it's new location child.Resize(PixelSize); } }
public override void Resize(int x, int y) { LastParentSize.X = x; LastParentSize.Y = y; Inited = true; Rect.Resize(x, y); var PixelSize = Rect.GetPixelSize(); if (ConstantChildHeights) { float childSize = (PixelSize.Y - (Children.Count * ChildSpacing)) / (Children.Count); if (MaxChildSize > 0 && childSize > MaxChildSize) { childSize = MaxChildSize; } float originY = FirstElementHasSpacing ? ChildSpacing : 0; foreach (var child in Children) { // we adjust each child rect to be raw before we resize them so they fit where we want them to fit. if (TopDown) { child.Rect.Y.Paramater = PixelSize.Y - originY - childSize; } else { child.Rect.Y.Paramater = originY; } child.Rect.Y.RelativeTo = RelativeLoc.Edge.Raw; child.Rect.Height.Paramater = childSize; child.Rect.Height.Mode = RelativeSize.SizeModes.Raw; child.Rect.AnchorLocation = OriginLocation.LowerLeft; child.Resize(PixelSize); originY += childSize + ChildSpacing; } } else { float originY = ChildSpacing; foreach (var child in Children) { // we resize the child to get it's height first child.Resize(PixelSize); float thisHeight = child.Rect.GetPixelSize().Y; if (TopDown) { child.Rect.Y.Paramater = PixelSize.Y - originY - thisHeight; } else { child.Rect.Y.Paramater = originY; } child.Rect.AnchorLocation = OriginTools.GetLowerAnchor(child.Rect.AnchorLocation); // resize the child with the correct origin child.Resize(PixelSize); originY += thisHeight + ChildSpacing; } } }