Beispiel #1
0
        public void OrderSpinner(Rect position, SidebarPanel panel)
        {
            Ensure.That(nameof(panel)).IsNotNull(panel);

            EditorGUIUtility.AddCursorRect(position, MouseCursor.Arrow);

            var isFirst = displayedPanels.FirstOrDefault() == panel;
            var isLast  = displayedPanels.LastOrDefault() == panel;

            var orderIncrement = -LudiqGUI.Spinner(position, !isFirst, !isLast);

            if (orderIncrement == 0)
            {
                return;
            }

            if (orderIncrement == +1)
            {
                foreach (var otherPanel in displayedPanels)
                {
                    if (otherPanel != panel && otherPanel.order >= panel.order)
                    {
                        panel.order = otherPanel.order;
                        otherPanel.order--;
                        break;
                    }
                }
            }
            else if (orderIncrement == -1)
            {
                foreach (var otherPanel in displayedPanels)
                {
                    if (otherPanel != panel && otherPanel.order <= panel.order)
                    {
                        panel.order = otherPanel.order;
                        otherPanel.order++;
                        break;
                    }
                }
            }

            CacheDisplayedPanels();
        }