Exemplo n.º 1
0
 /// <summary>
 /// Initialize a new instance of the ViewBase class.
 /// </summary>
 protected ViewDecorator(ViewBase child)
 {
     Debug.Assert(child != null);
     _child        = child;
     _child.Parent = this;
 }
        /// <summary>
        /// Perform a layout of the elements.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override void Layout(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // We take on all the available display area
            ClientRectangle = context.DisplayRectangle;

            // Maximum space available for the next child
            Rectangle childRectangle = ClientRectangle;

            // Find the last visible child
            ViewBase lastVisible = null;

            foreach (ViewBase child in Reverse())
            {
                if (child.Visible)
                {
                    lastVisible = child;
                    break;
                }
            }

            // Position each entry, with last entry filling remaining of space
            foreach (ViewBase child in this)
            {
                if (child.Visible)
                {
                    // Provide the total space currently available
                    context.DisplayRectangle = childRectangle;

                    // Get the preferred size of the child
                    Size childSize = child.GetPreferredSize(context);

                    if (Horizontal)
                    {
                        // Ask child to fill the available height
                        childSize.Height = childRectangle.Height;

                        if ((child == lastVisible) && FillLastChild)
                        {
                            // This child takes all remainder width
                            childSize.Width = childRectangle.Width;
                        }
                        else
                        {
                            // Reduce remainder space to exclude this child
                            childRectangle.X     += childSize.Width;
                            childRectangle.Width -= childSize.Width;
                        }
                    }
                    else
                    {
                        // Ask child to fill the available width
                        childSize.Width = childRectangle.Width;

                        if ((child == lastVisible) && FillLastChild)
                        {
                            // This child takes all remainder height
                            childSize.Height = childRectangle.Height;
                        }
                        else
                        {
                            // Reduce remainder space to exclude this child
                            childRectangle.Y      += childSize.Height;
                            childRectangle.Height -= childSize.Height;
                        }
                    }

                    // Use the update child size as the actual space for layout
                    context.DisplayRectangle = new Rectangle(context.DisplayRectangle.Location, childSize);

                    // Layout child in the provided space
                    child.Layout(context);
                }
            }

            // Put back the original display value now we have finished
            context.DisplayRectangle = ClientRectangle;
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initialize a new instance of the ViewBase class.
 /// </summary>
 public ViewDecoratorFixedSize(ViewBase child, Size fixedSize)
     : base(child)
 {
     FixedSize = fixedSize;
 }