Ejemplo n.º 1
0
        /// <summary>
        /// Calculated selected indicies of new items .
        /// </summary>
        /// <returns>The selected indicies.</returns>
        /// <param name="newItems">New items.</param>
        List <int> NewSelectedIndicies(ObservableList <string> newItems)
        {
            var selected_indicies = new List <int>();

            if (newItems.Count == 0)
            {
                return(selected_indicies);
            }

            //duplicated items should not be selected more than at start
            var new_items_copy = new List <string>(newItems);

            var selected_items = SelectedIndicies.ConvertAll(x => DataSource[x]);

            selected_items = selected_items.Where(x => {
                var is_valid_item = newItems.Contains(x);
                if (is_valid_item)
                {
                    new_items_copy.Remove(x);
                }
                return(is_valid_item);
            }).ToList();

            newItems.ForEach((item, index) => {
                if (selected_items.Contains(item))
                {
                    selected_items.Remove(item);
                    selected_indicies.Add(index);
                }
            });

            return(selected_indicies);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the items.
        /// </summary>
        /// <param name="newItems">New items.</param>
        void SetNewItems(ObservableList <string> newItems)
        {
            DataSource.OnChange -= UpdateItems;

            if (Sort && SortFunc != null)
            {
                newItems.BeginUpdate();

                var sorted = SortFunc(newItems).ToArray();

                newItems.Clear();
                newItems.AddRange(sorted);

                newItems.EndUpdate();
            }

            SilentDeselect(SelectedIndicies);
            var new_selected_indicies = SelectedItemsCache.ConvertAll <int>(newItems.IndexOf);

            new_selected_indicies.RemoveAll(IndexNotFound);

            dataSource = newItems;

            SilentSelect(new_selected_indicies);
            SelectedItemsCache = SelectedIndicies.ConvertAll <string>(GetDataItem);

            UpdateView();

            DataSource.OnChange += UpdateItems;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Moves the selected indicies down.
        /// </summary>
        /// <param name="index">Index.</param>
        /// <param name="range">Range.</param>
        void MoveSelectedIndiciesDown(int index, int range)
        {
            var start           = index + 1;
            var end             = start + range;
            var remove_indicies = SelectedIndicies.Where(x => start <= x && x <= end).ToList();
            var add_indicies    = remove_indicies.Convert(x => x + range);

            SilentDeselect(remove_indicies);
            SilentSelect(add_indicies);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Start this instance.
        /// </summary>
        public override void Start()
        {
            if (isStartedListView)
            {
                return;
            }
            isStartedListView = true;

            base.Start();
            base.Items = new List <ListViewItem>();

            SelectedItemsCache = SelectedIndicies.Convert <int, string>(GetDataItem);

            DestroyGameObjects = false;

            if (DefaultItem == null)
            {
                throw new NullReferenceException("DefaultItem is null. Set component of type ImageAdvanced to DefaultItem.");
            }
            DefaultItem.gameObject.SetActive(true);
            if (DefaultItem.GetComponentInChildren <Text>() == null)
            {
                throw new MissingComponentException("DefaultItem don't have child with 'Text' component. Add child with 'Text' component to DefaultItem.");
            }

            if (CanOptimize())
            {
                ScrollRect = scrollRect;

                var scrollRectTransform = scrollRect.transform as RectTransform;
                scrollHeight = scrollRectTransform.rect.height;
                scrollWidth  = scrollRectTransform.rect.width;

                layout = Container.GetComponent <LayoutGroup>();
                if (layout is EasyLayout.EasyLayout)
                {
                    LayoutBridge = new EasyLayoutBridge(layout as EasyLayout.EasyLayout, DefaultItem.transform as RectTransform);
                    LayoutBridge.IsHorizontal = IsHorizontal();
                }
                else if (layout is HorizontalOrVerticalLayoutGroup)
                {
                    LayoutBridge = new StandardLayoutBridge(layout as HorizontalOrVerticalLayoutGroup, DefaultItem.transform as RectTransform);
                }

                CalculateItemSize();
                CalculateMaxVisibleItems();
            }

            DefaultItem.gameObject.SetActive(false);

            UpdateItems();

            OnSelect.AddListener(OnSelectCallback);
            OnDeselect.AddListener(OnDeselectCallback);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Moves the selected indicies up.
        /// </summary>
        /// <param name="index">Index.</param>
        /// <param name="range">Range.</param>
        void MoveSelectedIndiciesUp(int index, int range)
        {
            var start = index + 1;
            var end   = start + range;

            //deselect indicies in removed range
            SelectedIndicies.Where(x => start <= x && x <= end).ForEach(Deselect);

            var remove_indicies = SelectedIndicies.Where(x => x > end).ToList();
            var add_indicies    = remove_indicies.Select(x => x - range).ToList();

            SilentDeselect(remove_indicies);
            SilentSelect(add_indicies);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Coloring the specified component.
 /// </summary>
 /// <param name="component">Component.</param>
 protected override void Coloring(ListViewItem component)
 {
     if (component == null)
     {
         return;
     }
     if (SelectedIndicies.Contains(component.Index))
     {
         SelectColoring(component);
     }
     else
     {
         DefaultColoring(component);
     }
 }
Ejemplo n.º 7
0
        protected virtual void UpdateItems(List <TItem> newItems)
        {
            newItems = SortItems(newItems);

            SelectedIndicies.ForEach(index => {
                var new_index = newItems.FindIndex(x => x.Equals(customItems[index]));
                if (new_index == -1)
                {
                    Deselect(index);
                }
            });

            customItems = newItems;

            UpdateView();
        }
Ejemplo n.º 8
0
        void UpdateItems(List <string> newItems)
        {
            newItems = FilterItems(newItems);

            var new_selected_indicies = NewSelectedIndicies(newItems);

            SelectedIndicies.ForEach(x => {
                if (!new_selected_indicies.Contains(x))
                {
                    Deselect(x);
                }
            });

            strings = newItems;

            UpdateView();
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Updates the items.
        /// </summary>
        /// <param name="newItems">New items.</param>
        void UpdateItems(List <GameObject> newItems)
        {
            RemoveCallbacks();

            newItems = SortItems(newItems);

            var new_selected_indicies = SelectedIndicies
                                        .Select(x => objects.Count > x ? newItems.IndexOf(objects[x]) : -1)
                                        .Where(x => x != -1).ToList();

            SelectedIndicies.Except(new_selected_indicies).ForEach(Deselect);

            objects    = newItems;
            base.Items = newItems.Convert(x => x.GetComponent <ListViewItem>() ?? x.AddComponent <ListViewItem>());

            SelectedIndicies = new_selected_indicies;

            AddCallbacks();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Start this instance.
        /// </summary>
        public override void Start()
        {
            if (isStartedListView)
            {
                return;
            }
            isStartedListView = true;

            base.Start();
            base.Items = new List <ListViewItem>();

            SelectedItemsCache = SelectedIndicies.ConvertAll <string>(GetDataItem);

            DestroyGameObjects = false;

            if (DefaultItem == null)
            {
                throw new NullReferenceException("DefaultItem is null. Set component of type ImageAdvanced to DefaultItem.");
            }
            DefaultItem.gameObject.SetActive(true);
            if (DefaultItem.GetComponentInChildren <Text>() == null)
            {
                throw new MissingComponentException("DefaultItem don't have child with 'Text' component. Add child with 'Text' component to DefaultItem.");
            }

            var topFillerObj = new GameObject("top filler");

            topFillerObj.transform.SetParent(Container);
            topFiller = topFillerObj.AddComponent <RectTransform>();
            topFiller.SetAsFirstSibling();
            topFiller.localScale = Vector3.one;

            var bottomFillerObj = new GameObject("bottom filler");

            bottomFillerObj.transform.SetParent(Container);
            bottomFiller            = bottomFillerObj.AddComponent <RectTransform>();
            bottomFiller.localScale = Vector3.one;

            if (CanOptimize())
            {
                ScrollRect = scrollRect;

                var scrollRectTransform = scrollRect.transform as RectTransform;
                scrollHeight = scrollRectTransform.rect.height;
                scrollWidth  = scrollRectTransform.rect.width;

                var itemRectTransform = DefaultItem.transform as RectTransform;
                itemHeight = itemRectTransform.rect.height;
                itemWidth  = itemRectTransform.rect.width;

                layout = Container.GetComponent <EasyLayout.EasyLayout>();

                CalculateMaxVisibleItems();
            }

            DefaultItem.gameObject.SetActive(false);

            UpdateItems();

            OnSelect.AddListener(OnSelectCallback);
            OnDeselect.AddListener(OnDeselectCallback);
        }