Пример #1
0
 public override void EndLayout(LayoutRequest request, PointF origin, SizeF allocation)
 {
     if (ownsView)
     {
         View.Frame = new RectangleF(origin, allocation);
         base.EndLayout(request, PointF.Empty, allocation);
     }
     else
     {
         base.EndLayout(request, origin, allocation);
     }
 }
Пример #2
0
        public virtual void EndLayout(LayoutRequest request, PointF origin, SizeF allocation)
        {
            var frame = new RectangleF(origin.X + PadLeft, origin.Y + PadBottom,
                                       allocation.Width - PadLeft - PadRight, allocation.Height - PadTop - PadBottom);

            if (allocation.Height > request.Size.Height)
            {
                if (YAlign != LayoutAlign.Fill)
                {
                    frame.Height = request.Size.Height - PadTop - PadBottom;
                    if (YAlign == LayoutAlign.Center)
                    {
                        frame.Y += (allocation.Height - request.Size.Height) / 2;
                    }
                    else if (YAlign == LayoutAlign.End)
                    {
                        frame.Y += (allocation.Height - request.Size.Height);
                    }
                }
            }

            if (allocation.Width > request.Size.Width)
            {
                if (XAlign != LayoutAlign.Fill)
                {
                    frame.Width = request.Size.Width - PadLeft - PadRight;
                    if (XAlign == LayoutAlign.Center)
                    {
                        frame.X += (allocation.Width - request.Size.Width) / 2;
                    }
                    else if (XAlign == LayoutAlign.End)
                    {
                        frame.X += (allocation.Width - request.Size.Width);
                    }
                }
            }

            OnLayoutEnded(frame);
        }
Пример #3
0
        public virtual void EndLayout(LayoutRequest request, PointF origin, SizeF allocation)
        {
            var childRequests = ((ContainerLayoutRequest)request).ChildRequests;

            allocation = new SizeF(allocation.Width - PadLeft - PadRight, allocation.Height - PadBottom - PadTop);
            origin     = new PointF(origin.X + PadLeft, origin.Y + PadBottom);

            var size = request.Size;

            size.Height -= (PadTop + PadBottom);
            size.Width  -= (PadLeft + PadRight);

            int wExpandCount = 0;
            int hExpandCount = 0;
            int visibleCount = 0;

            foreach (var childRequest in childRequests)
            {
                if (childRequest.Visible)
                {
                    visibleCount++;
                }
                else
                {
                    continue;
                }
                if (childRequest.ExpandWidth)
                {
                    wExpandCount++;
                }
                if (childRequest.ExpandHeight)
                {
                    hExpandCount++;
                }
            }

            float wExpand = 0;

            if (allocation.Width > size.Width)
            {
                wExpand = allocation.Width - size.Width;
                if (wExpandCount > 0)
                {
                    wExpand /= wExpandCount;
                }
            }
            float hExpand = 0;

            if (allocation.Height > size.Height)
            {
                hExpand = allocation.Height - size.Height;
                if (hExpandCount > 0)
                {
                    hExpand /= hExpandCount;
                }
            }

            if (Direction == LayoutDirection.Horizontal)
            {
                float pos = PadLeft;
                if (wExpandCount == 0)
                {
                    if (Align == LayoutAlign.End)
                    {
                        pos += wExpand;
                    }
                    else if (Align == LayoutAlign.Center)
                    {
                        pos += wExpand / 2;
                    }
                }
                for (int i = 0; i < childRequests.Count; i++)
                {
                    var child    = children[i];
                    var childReq = childRequests[i];
                    if (!childReq.Visible)
                    {
                        continue;
                    }

                    var childSize = new SizeF(childReq.Size.Width, allocation.Height);
                    if (childReq.ExpandWidth)
                    {
                        childSize.Width += wExpand;
                    }
                    else if (hExpandCount == 0 && Align == LayoutAlign.Fill)
                    {
                        childSize.Width += wExpand / visibleCount;
                    }

                    child.EndLayout(childReq, new PointF(pos, origin.Y), childSize);
                    pos += childSize.Width + Spacing;
                }
            }
            else
            {
                float pos = PadBottom;
                if (hExpandCount == 0)
                {
                    if (Align == LayoutAlign.End)
                    {
                        pos += hExpand;
                    }
                    else if (Align == LayoutAlign.Center)
                    {
                        pos += hExpand / 2;
                    }
                }
                for (int i = 0; i < childRequests.Count; i++)
                {
                    var child    = children[i];
                    var childReq = childRequests[i];
                    if (!childReq.Visible)
                    {
                        continue;
                    }

                    var childSize = new SizeF(allocation.Width, childReq.Size.Height);
                    if (childReq.ExpandHeight)
                    {
                        childSize.Height += hExpand;
                    }
                    else if (hExpandCount == 0 && Align == LayoutAlign.Fill)
                    {
                        childSize.Height += hExpand / visibleCount;
                    }

                    child.EndLayout(childReq, new PointF(origin.X, pos), childSize);
                    pos += childSize.Height + Spacing;
                }
            }
        }