ComponentFactory.Quicksilver.Layout.RadialLayout.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)
        {
            if (_count > 0)
            {
                // Each child is an equal angle around the radius
                double angleCurrent = StartAngle;
                double diff = (EndAngle - StartAngle);
                double angleDelta = diff / ((diff == (double)360) ? _count : _count - 1);

                // Calculate the radius separately for each dimension
                double radiusX = (finalSize.Width - _maxLength * 2) / 2;
                double radiusY = (finalSize.Height - _maxLength * 2) / 2;

                // Do we force into being a circle?
                if (Circle)
                {
                    // Always reduce to using the smallest direction
                    radiusX = Math.Min(radiusX, radiusY);
                    radiusY = radiusX;
                }

                // Rotate around the center point
                Point center = new Point(finalSize.Width / 2, finalSize.Height / 2);

                // Calculate the target rectangle for each element
                foreach (UIElement element in elements)
                {
                    // We ignore items being removed
                    if (stateDict[element].Status != MetaElementStatus.Removing)
                    {
                        // We ignore items that are collapsed
                        if (element.Visibility != Visibility.Collapsed)
                        {
                            // Rotate around the center point using the accumulated angle
                            double childX = center.X + Math.Cos(2 * Math.PI * angleCurrent / 360) * radiusX;
                            double childY = center.Y + Math.Sin(2 * Math.PI * angleCurrent / 360) * radiusY;
                            angleCurrent += angleDelta;

                            // Position the element at
                            Size desiredSize = element.DesiredSize;
                            Rect newTargetRect = new Rect(childX - desiredSize.Width / 2,
                                                          childY - desiredSize.Height / 2,
                                                          desiredSize.Width,
                                                          desiredSize.Height);

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