Exemple #1
0
        /// <summary>
        /// Perform a layout of the elements.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override void Layout(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // During disposal the view control will not longer exist
            if (_viewControl != null)
            {
                // Ensure context has the correct control
                using (CorrectContextControl ccc = new CorrectContextControl(context, _viewControl))
                {
                    // We take on all the available display area
                    ClientRectangle = context.DisplayRectangle;

                    // Are we allowed to layout child controls?
                    if (!context.ViewManager.DoNotLayoutControls)
                    {
                        // Do we have a control to position?
                        if (_viewControl != null)
                        {
                            // Size and position the child control
                            _viewControl.SetBounds(ClientLocation.X, ClientLocation.Y, ClientWidth, ClientHeight);

                            // Ensure the visible/enabled states are up to date
                            _viewControl.Visible = Visible;
                            _viewControl.Enabled = Enabled;

                            // A layout means something might have changed, so better redraw it
                            _viewControl.Invalidate();
                        }
                    }

                    // Adjust the view location to be at the top left of the child control
                    context.DisplayRectangle = new Rectangle(LayoutOffset, ClientSize);

                    // Do we have a child view to layout?
                    if (_viewChild != null)
                    {
                        // Layout the child view
                        _viewChild.Layout(context);
                    }

                    // Put back the original display value now we have finished
                    context.DisplayRectangle = ClientRectangle;
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Perform a layout of the elements.
 /// </summary>
 /// <param name="context">Layout context.</param>
 public override void Layout(ViewLayoutContext context)
 {
     _child.Layout(context);
 }
Exemple #3
0
        /// <summary>
        /// Perform a layout of the elements.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override void Layout(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

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

            ClientRectangle = original;

            // Layout each child
            int offset = 0;
            int space  = (_orientation == Orientation.Vertical ? ClientHeight : ClientWidth);

            for (int i = 0; i < Count; i++)
            {
                ViewBase child = this[i];

                // Find length of this item
                int length;

                // If this is the last item then it takes the remaining space
                if (i == (Count - 1))
                {
                    length = space;
                }
                else
                {
                    // Give this item an equal portion of the remainder
                    length = space / (Count - i);
                }

                // Ask child for it's own preferred size
                Size childPreferred = child.GetPreferredSize(context);

                // Size child to our relevant dimension
                if (_orientation == Orientation.Vertical)
                {
                    context.DisplayRectangle = new Rectangle(ClientRectangle.X,
                                                             ClientRectangle.Y + offset,
                                                             childPreferred.Width,
                                                             length);
                }
                else
                {
                    context.DisplayRectangle = new Rectangle(ClientRectangle.X + offset,
                                                             ClientRectangle.Y,
                                                             length,
                                                             ClientRectangle.Height);
                }

                // Ask the child to layout
                child.Layout(context);

                // Adjust running values
                offset += length;
                space  -= length;
            }

            // Put back the original display value now we have finished
            context.DisplayRectangle = original;
        }