Exemple #1
0
        private bool SelectBy(int delta)
        {
            var list      = GetSelectableItems();
            var selection = GetSelectedItem();

            if (selection != null)
            {
                var index = list.IndexOf(selection);

                var direction = Math.Sign(delta);
                delta = Math.Abs(delta);
                var             nextIndex         = index;
                var             numVisibleElement = 0;
                ISelectableItem nextElement       = null;
                while (numVisibleElement < delta)
                {
                    nextIndex += direction;
                    if (nextIndex >= list.Count)
                    {
                        return(false);
                    }
                    if (nextIndex < 0)
                    {
                        return(false);
                    }
                    nextElement = list.ElementAt(nextIndex);
                    if (UIUtils.IsElementVisible(nextElement.element))
                    {
                        ++numVisibleElement;
                    }
                }

                PageManager.instance.SetSelected(nextElement.package, nextElement.targetVersion);

                foreach (var scrollView in UIUtils.GetParentsOfType <ScrollView>(nextElement.element))
                {
                    ScrollIfNeeded(scrollView, nextElement.element);
                }
            }

            return(true);
        }
        private void ScrollIfNeeded(ScrollView container = null, VisualElement target = null)
        {
            container = container ?? scrollView;
            target    = target ?? GetSelectedItem()?.element;

            if (container == null || target == null)
            {
                return;
            }

            if (float.IsNaN(target.layout.height))
            {
                EditorApplication.delayCall += () => ScrollIfNeeded(container, target);
                return;
            }

            var scrollViews = UIUtils.GetParentsOfType <ScrollView>(target);

            foreach (var scrollview in scrollViews)
            {
                UIUtils.ScrollIfNeeded(scrollview, target);
            }
        }