void ScrollUpdate() { var oldTopHiddenItems = topHiddenItems; topHiddenItems = GetFirstVisibleIndex(); bottomHiddenItems = Mathf.Max(0, DataSource.Count - visibleItems - topHiddenItems); if (oldTopHiddenItems == topHiddenItems) { //do nothing } // optimization on +-1 item scroll else if (oldTopHiddenItems == (topHiddenItems + 1)) { var bottomComponent = ComponentTopToBottom(); bottomComponent.Index = topHiddenItems; bottomComponent.Text.text = DataSource[topHiddenItems]; Coloring(bottomComponent); } else if (oldTopHiddenItems == (topHiddenItems - 1)) { var topComponent = ComponentBottomToTop(); var new_index = topHiddenItems + visibleItems - 1; topComponent.Index = new_index; topComponent.Text.text = DataSource[new_index]; Coloring(topComponent); } // all other cases else { //! var new_indicies = Enumerable.Range(topHiddenItems, visibleItems).ToArray(); components.ForEach((x, i) => { x.Index = new_indicies[i]; x.Text.text = DataSource[new_indicies[i]]; Coloring(x); }); } UpdateTopFiller(); UpdateBottomFiller(); if (layout) { layout.UpdateLayout(); } }
/// <summary> /// Updates the layout. /// </summary> public void UpdateLayout() { Layout.UpdateLayout(); if (fitter != null) { fitter.SetLayoutHorizontal(); fitter.SetLayoutVertical(); } }
protected virtual void OnScroll(float value) { var oldTopHiddenItems = topHiddenItems; topHiddenItems = GetFirstVisibleIndex(); bottomHiddenItems = Math.Max(0, customItems.Count - visibleItems - topHiddenItems); if (oldTopHiddenItems == topHiddenItems) { //do nothing } // optimization on +-1 item scroll else if (oldTopHiddenItems == (topHiddenItems + 1)) { var bottomComponent = components[components.Count - 1]; components.RemoveAt(components.Count - 1); components.Insert(0, bottomComponent); bottomComponent.transform.SetAsFirstSibling(); bottomComponent.Index = topHiddenItems; SetData(bottomComponent, customItems[topHiddenItems]); Coloring(bottomComponent as ListViewItem); } else if (oldTopHiddenItems == (topHiddenItems - 1)) { var topComponent = components[0]; components.RemoveAt(0); components.Add(topComponent); topComponent.transform.SetAsLastSibling(); topComponent.Index = topHiddenItems + visibleItems - 1; SetData(topComponent, customItems[topHiddenItems + visibleItems - 1]); Coloring(topComponent as ListViewItem); } // all other cases else { var new_indicies = Enumerable.Range(topHiddenItems, visibleItems).ToArray(); components.ForEach((x, i) => { x.Index = new_indicies[i]; SetData(x, customItems[new_indicies[i]]); Coloring(x as ListViewItem); }); } SetTopFiller(); SetBottomFiller(); if (layout) { layout.UpdateLayout(); } }
void UpdateView() { RemoveCallbacks(); if ((CanOptimize()) && (strings.Count > 0)) { visibleItems = (maxVisibleItems < strings.Count) ? maxVisibleItems : strings.Count; } else { visibleItems = strings.Count; } components = GetNewComponents(); var base_items = new List <ListViewItem>(); components.ForEach(x => base_items.Add(x)); base.Items = base_items; components.ForEach((x, i) => { x.Index = i; x.Text.text = strings[i]; Coloring(x); }); AddCallbacks(); topHiddenItems = 0; bottomHiddenItems = strings.Count() - visibleItems; UpdateTopFiller(); UpdateBottomFiller(); if (layout) { //force rebuild //layout.SetLayoutVertical(); layout.UpdateLayout(); } if (scrollRect != null) { var r = scrollRect.GetComponent <RectTransform>(); r.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, r.rect.width); } }
/// <summary> /// Updates the layout. /// </summary> public void UpdateLayout() { Layout.UpdateLayout(); }
/// <summary> /// On ScrollUpdate. /// </summary> protected virtual void ScrollUpdate() { var oldTopHiddenItems = topHiddenItems; topHiddenItems = GetFirstVisibleIndex(); bottomHiddenItems = Mathf.Max(0, DataSource.Count - visibleItems - topHiddenItems); if (oldTopHiddenItems == topHiddenItems) { //do nothing } // optimization on +-1 item scroll else if (oldTopHiddenItems == (topHiddenItems + 1)) { var bottomComponent = components[components.Count - 1]; components.RemoveAt(components.Count - 1); components.Insert(0, bottomComponent); bottomComponent.transform.SetAsFirstSibling(); bottomComponent.Index = topHiddenItems; SetData(bottomComponent, DataSource[topHiddenItems]); Coloring(bottomComponent as ListViewItem); } else if (oldTopHiddenItems == (topHiddenItems - 1)) { var topComponent = components[0]; components.RemoveAt(0); components.Add(topComponent); topComponent.transform.SetAsLastSibling(); topComponent.Index = topHiddenItems + visibleItems - 1; SetData(topComponent, DataSource[topHiddenItems + visibleItems - 1]); Coloring(topComponent as ListViewItem); } // all other cases else { var current_visible_range = components.ConvertAll <int>(GetComponentIndex); var new_visible_range = Enumerable.Range(topHiddenItems, visibleItems).ToArray(); var new_indicies_to_change = new_visible_range.Except(current_visible_range).ToList(); var components_to_change = new Stack <TComponent>(components.Where(x => !new_visible_range.Contains(x.Index))); new_indicies_to_change.ForEach(index => { var component = components_to_change.Pop(); component.Index = index; SetData(component, DataSource[index]); Coloring(component as ListViewItem); }); components.Sort(ComponentsComparer); components.ForEach(SetComponentAsLastSibling); } if (layout) { SetFiller(); layout.UpdateLayout(); } }