Exemplo 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);
        }
Exemplo 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;
        }
Exemplo n.º 3
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);
        }