private void OrbitViewPanel_ItemArranged(object sender, OrbitViewPanelItemArrangedArgs e)
        {
            if (OrbitsEnabled)
            {
                _orbits.TryGetValue(e.ElementProperties.Element, out Ellipse orbit);

                if (orbit == null)
                {
                    if (_orbitsContainer == null)
                    {
                        _orbitsContainer = (Grid)GetTemplateChild("OrbitGrid");
                        if (_orbitsContainer == null)
                        {
                            return;
                        }
                    }

                    orbit = CreateOrbit();
                    _orbits.Add(e.ElementProperties.Element, orbit);
                    _orbitsContainer.Children.Add(orbit);
                }

                orbit.Height = orbit.Width = e.ElementProperties.DistanceFromCenter * 2;
            }
        }
Exemple #2
0
        /// <summary>
        /// Provides the behavior for the "Arrange" pass of layout
        /// </summary>
        /// <param name="finalSize">The final area within the parent that this object should use to arrange itself and its children</param>
        /// <returns>The actual size that is used after the element is arranged in layout.</returns>
        protected override Size ArrangeOverride(Size finalSize)
        {
            var angle = 2 * Math.PI / Children.Count;

            var minDistance = 80;
            var maxDistance = Math.Max(minDistance, (Math.Min(finalSize.Width, finalSize.Height) - OrbitView.MaxItemSize) / 2);

            var elementsProperties = new List <OrbitViewElementProperties>();

            for (var i = 0; i < Children.Count; i++)
            {
                // UNO TODO
                if (Children.ElementAt(i) is UIElement element)
                {
                    OrbitViewDataItem orbitViewDataItem = null;
                    if (element is FrameworkElement)
                    {
                        orbitViewDataItem = ((FrameworkElement)element).DataContext as OrbitViewDataItem;
                    }

                    var d = orbitViewDataItem != null && orbitViewDataItem.Distance >= 0 ? orbitViewDataItem.Distance : 0.5;
                    d = Math.Min(d, 1d);

                    var distance = (d * (maxDistance - minDistance)) + minDistance;
                    var x        = distance * Math.Cos((angle * i) + (angle / 2));
                    var y        = distance * Math.Sin((angle * i) + (angle / 2));

                    var x_normalized = (finalSize.Width / 2) + x - (element.DesiredSize.Width / 2);
                    var y_normalized = (finalSize.Height / 2) - y - (element.DesiredSize.Height / 2);
                    var point        = new Point(x_normalized, y_normalized);

                    element.Arrange(point.ToRect(element.DesiredSize));

                    var elementProperties = new OrbitViewElementProperties()
                    {
                        XYFromCenter       = new Point(x, y),
                        DistanceFromCenter = distance,
                        Element            = element
                    };
                    elementsProperties.Add(elementProperties);

                    if (ItemArranged != null)
                    {
                        var args = new OrbitViewPanelItemArrangedArgs()
                        {
                            ElementProperties = elementProperties,
                            ItemIndex         = i
                        };
                        ItemArranged.Invoke(this, args);
                    }
                }
            }

            ItemsArranged?.Invoke(this, new OrbitViewPanelItemsArrangedArgs()
            {
                Elements = elementsProperties
            });

            return(finalSize);
        }