ComponentFactory.Quicksilver.Layout.DockLayout.TargetChildren C# (CSharp) Method

TargetChildren() public method

Calculate target state for each element based on layout algorithm.
public TargetChildren ( string layoutId, MetaPanelBase metaPanel, MetaElementStateDict stateDict, ICollection elements, Size finalSize ) : void
layoutId string Identifier of the layout to be used.
metaPanel MetaPanelBase Reference to owning panel instance.
stateDict MetaElementStateDict Dictionary of per-element state.
elements ICollection Collection of elements to be arranged.
finalSize System.Windows.Size Size that layout should use to arrange child elements.
return void
        public override void TargetChildren(string layoutId,
                                            MetaPanelBase metaPanel,
                                            MetaElementStateDict stateDict,
                                            ICollection elements,
                                            Size finalSize)
        {
            // Only apply if we match the incoming layout identifier
            if (string.IsNullOrEmpty(Id) || Id.Equals(layoutId))
            {
                double x = 0.0;
                double y = 0.0;
                double right = 0.0;
                double bottom = 0.0;

                // If using LastChildFill then the last element takes up all the remainder space
                int lastDockElement = (LastChildFill ? _validCount - 1 : _validCount);

                // Calculate the target rectangle for each element
                int i = 0;
                foreach (UIElement element in elements)
                {
                    // We ignore items being removed
                    if (stateDict[element].Status != MetaElementStatus.Removing)
                    {
                        // Calculate the maximum possible rect for the element
                        Rect newTargetRect = new Rect(x, y,
                                                      Math.Max(0.0, (double)(finalSize.Width - (x + right))),
                                                      Math.Max(0.0, (double)(finalSize.Height - (y + bottom))));

                        if (i < lastDockElement)
                        {
                            // Constrain target rect by the dock edge
                            Size desiredSize = element.DesiredSize;
                            switch (GetDock(element))
                            {
                                case Dock.Left:
                                    x += desiredSize.Width;
                                    newTargetRect.Width = desiredSize.Width;
                                    break;
                                case Dock.Top:
                                    y += desiredSize.Height;
                                    newTargetRect.Height = desiredSize.Height;
                                    break;
                                case Dock.Right:
                                    right += desiredSize.Width;
                                    newTargetRect.X = Math.Max(0.0, (double)(finalSize.Width - right));
                                    newTargetRect.Width = desiredSize.Width;
                                    break;
                                case Dock.Bottom:
                                    bottom += desiredSize.Height;
                                    newTargetRect.Y = Math.Max(0.0, (double)(finalSize.Height - bottom));
                                    newTargetRect.Height = desiredSize.Height;
                                    break;
                            }
                        }

                        // Store the new target rectangle
                        if (!stateDict[element].TargetRect.Equals(newTargetRect))
                        {
                            stateDict[element].TargetChanged = true;
                            stateDict[element].TargetRect = newTargetRect;
                        }

                        i++;
                    }
                }
            }
        }
        #endregion