private void ResizeHeight(float height) { m_ScrollView.contentContainer.style.height = itemsSource.Count * itemHeight; // Restore scroll offset and pre-emptively update the highValue // in case this is the initial restore from persistent data and // the ScrollView's OnGeometryChanged() didn't update the low // and highValues. m_ScrollView.verticalScroller.highValue = Mathf.Max(m_ScrollOffset, m_ScrollView.verticalScroller.highValue); m_ScrollView.verticalScroller.value = m_ScrollOffset; int itemCount = Math.Min((int)(height / itemHeight) + m_ExtraVisibleItems, itemsSource.Count); if (m_VisibleItemCount != itemCount) { if (m_VisibleItemCount > itemCount) { // Shrink int removeCount = m_VisibleItemCount - itemCount; for (int i = 0; i < removeCount; i++) { m_Pool.RemoveAt(m_Pool.Count - 1); m_ScrollView.RemoveAt(m_ScrollView.childCount - 1); } } else { // Grow int addCount = itemCount - m_VisibleItemCount; for (int i = 0; i < addCount; i++) { int index = i + m_FirstVisibleIndex + m_VisibleItemCount; var item = makeItem(); var recycledItem = new RecycledItem(item); m_Pool.Add(recycledItem); item.style.marginTop = 0; item.style.marginBottom = 0; item.style.positionType = PositionType.Absolute; item.style.positionLeft = 0; item.style.positionRight = 0; item.style.height = itemHeight; if (index < itemsSource.Count) { Setup(recycledItem, index); } else { item.style.visibility = Visibility.Hidden; } m_ScrollView.Add(item); } } m_VisibleItemCount = itemCount; } m_LastHeight = height; }
private void Setup(RecycledItem recycledItem, int newIndex) { var newId = GetIdFromIndex(newIndex); recycledItem.element.style.visibility = Visibility.Visible; if (recycledItem.index == newIndex) { return; } m_LastItemIndex = newIndex; if (showAlternatingRowBackgrounds != AlternatingRowBackground.None && newIndex % 2 == 1) { recycledItem.element.AddToClassList(itemAlternativeBackgroundUssClassName); } else { recycledItem.element.RemoveFromClassList(itemAlternativeBackgroundUssClassName); } recycledItem.index = newIndex; recycledItem.id = newId; recycledItem.element.style.top = recycledItem.index * m_PixelAlignedItemHeight; recycledItem.element.style.bottom = (itemsSource.Count - recycledItem.index - 1) * m_PixelAlignedItemHeight; bindItem(recycledItem.element, recycledItem.index); recycledItem.SetSelected(m_SelectedIds.Contains(newId)); }
private void Setup(RecycledItem recycledItem, int newIndex) { Assert.IsTrue(newIndex < itemsSource.Count); recycledItem.index = newIndex; recycledItem.element.style.positionTop = recycledItem.index * itemHeight; recycledItem.element.style.positionBottom = (itemsSource.Count - recycledItem.index - 1) * itemHeight; bindItem(recycledItem.element, recycledItem.index); recycledItem.SetSelected(m_SelectedIndices.Contains(newIndex)); }
public override void Deserialize(IDataReader reader) { uint num = (uint)reader.ReadUShort(); for (int index = 0; (long)index < (long)num; ++index) { RecycledItem recycledItem = new RecycledItem(); recycledItem.Deserialize(reader); this.recycledItems.Add(recycledItem); } }
private void Setup(RecycledItem recycledItem, int newIndex) { var newId = GetIdFromIndex(newIndex); recycledItem.element.style.visibility = Visibility.Visible; recycledItem.index = newIndex; recycledItem.id = newId; recycledItem.element.style.top = recycledItem.index * itemHeight; recycledItem.element.style.bottom = (itemsSource.Count - recycledItem.index - 1) * itemHeight; bindItem(recycledItem.element, recycledItem.index); recycledItem.SetSelected(m_SelectedIds.Contains(newId)); }
public override void Deserialize(ICustomDataInput reader) { var countRecycledItems = reader.ReadShort(); RecycledItems = new List <RecycledItem>(); for (short i = 0; i < countRecycledItems; i++) { RecycledItem type = new RecycledItem(); type.Deserialize(reader); RecycledItems.Add(type); } }
public override void Deserialize(IDataReader reader) { var RecycledItemsCount = reader.ReadShort(); RecycledItems = new List <RecycledItem>(); for (var i = 0; i < RecycledItemsCount; i++) { var objectToAdd = new RecycledItem(); objectToAdd.Deserialize(reader); RecycledItems.Add(objectToAdd); } }
private void Setup(RecycledItem recycledItem, int newIndex) { var newId = GetIdFromIndex(newIndex); recycledItem.element.style.display = DisplayStyle.Flex; if (recycledItem.index == newIndex) { return; } m_LastItemIndex = newIndex; if (showAlternatingRowBackgrounds != AlternatingRowBackground.None && newIndex % 2 == 1) { recycledItem.element.AddToClassList(itemAlternativeBackgroundUssClassName); } else { recycledItem.element.RemoveFromClassList(itemAlternativeBackgroundUssClassName); } if (recycledItem.index != RecycledItem.kUndefinedIndex) { unbindItem?.Invoke(recycledItem.element, recycledItem.index); } recycledItem.index = newIndex; recycledItem.id = newId; int indexInParent = newIndex - m_FirstVisibleIndex; if (indexInParent == contentContainer.childCount) { recycledItem.element.BringToFront(); } else { recycledItem.element.PlaceBehind(contentContainer[indexInParent]); } bindItem(recycledItem.element, recycledItem.index); recycledItem.SetSelected(m_SelectedIds.Contains(newId)); }
public void Refresh() { m_Pool.Clear(); m_ScrollView.Clear(); m_ScrollView.contentContainer.style.width = m_ScrollView.contentViewport.layout.width; m_ScrollView.contentContainer.style.flex = 0; if (!HasValidDataAndBindings()) { return; } // Resize ScrollView in case the collection has changed. m_ScrollView.contentContainer.style.height = itemsSource.Count * itemHeight; // Restore scroll offset and pre-emptively update the highValue // in case this is the initial restore from persistent data and // the ScrollView's OnGeometryChanged() didn't update the low // and highValues. m_ScrollView.verticalScroller.highValue = Mathf.Max(m_ScrollOffset, m_ScrollView.verticalScroller.highValue); m_ScrollView.verticalScroller.value = m_ScrollOffset; if (m_LastSize != m_ScrollView.layout) { m_LastSize = m_ScrollView.layout; } if (float.IsNaN(m_LastSize.height)) { return; } m_ScrollView.contentContainer.style.height = itemsSource.Count * itemHeight; m_VisibleItemCount = (int)(m_LastSize.height / itemHeight) + m_ExtraVisibleItems; for (var i = m_FirstVisibleIndex; i < m_VisibleItemCount + m_FirstVisibleIndex; i++) { var item = makeItem(); var recycledItem = new RecycledItem(item); m_Pool.Add(recycledItem); item.style.marginTop = 0; item.style.marginBottom = 0; item.style.positionType = PositionType.Absolute; item.style.positionLeft = 0; item.style.positionRight = 0; item.style.height = itemHeight; if (i < itemsSource.Count) { item.style.visibility = Visibility.Visible; Setup(recycledItem, i); } else { item.style.visibility = Visibility.Hidden; } m_ScrollView.Add(item); } schedule.Execute(() => { Dirty(ChangeType.Layout); }); }
private void ResizeHeight(float height) { var contentHeight = itemsSource.Count * itemHeight; m_ScrollView.contentContainer.style.height = contentHeight; // Restore scroll offset and pre-emptively update the highValue // in case this is the initial restore from persistent data and // the ScrollView's OnGeometryChanged() didn't update the low // and highValues. var scrollableHeight = Mathf.Max(0, contentHeight - m_ScrollView.contentViewport.layout.height); m_ScrollView.verticalScroller.highValue = Mathf.Min(Mathf.Max(m_ScrollOffset, m_ScrollView.verticalScroller.highValue), scrollableHeight); m_ScrollView.verticalScroller.value = Mathf.Min(m_ScrollOffset, m_ScrollView.verticalScroller.highValue); int itemCount = Math.Min((int)(height / itemHeight) + k_ExtraVisibleItems, itemsSource.Count); if (m_VisibleItemCount != itemCount) { if (m_VisibleItemCount > itemCount) { // Shrink int removeCount = m_VisibleItemCount - itemCount; for (int i = 0; i < removeCount; i++) { m_Pool[m_Pool.Count - 1].DetachElement(); m_Pool.RemoveAt(m_Pool.Count - 1); RemoveAt(childCount - 1); } } else { // Grow int addCount = itemCount - m_VisibleItemCount; for (int i = 0; i < addCount; i++) { int index = i + m_FirstVisibleIndex + m_VisibleItemCount; var item = makeItem(); var recycledItem = new RecycledItem(item); m_Pool.Add(recycledItem); item.AddToClassList("unity-listview-item"); item.style.marginTop = 0f; item.style.marginBottom = 0f; item.style.position = Position.Absolute; item.style.left = 0f; item.style.right = 0f; item.style.height = itemHeight; if (index < itemsSource.Count) { Setup(recycledItem, index); } else { item.style.visibility = Visibility.Hidden; } Add(item); } } m_VisibleItemCount = itemCount; } m_LastHeight = height; // Add selected objects to working lists. for (int index = 0; index < m_ItemsSource.Count; ++index) { if (m_SelectedIds.Contains(GetIdFromIndex(index))) { m_SelectedIndices.Add(index); m_SelectedItems.Add(m_ItemsSource[index]); } } }
private void ResizeHeight(float height) { UpdatePixelAlignedHeight(); var contentHeight = itemsSource.Count * m_PixelAlignedItemHeight; m_ScrollView.contentContainer.style.height = contentHeight; // Restore scroll offset and preemptively update the highValue // in case this is the initial restore from persistent data and // the ScrollView's OnGeometryChanged() didn't update the low // and highValues. var scrollableHeight = Mathf.Max(0, contentHeight - m_ScrollView.contentViewport.layout.height); m_ScrollView.verticalScroller.highValue = Mathf.Min(Mathf.Max(m_ScrollOffset, m_ScrollView.verticalScroller.highValue), scrollableHeight); m_ScrollView.verticalScroller.value = Mathf.Min(m_ScrollOffset, m_ScrollView.verticalScroller.highValue); int itemCount = Math.Min((int)(height / m_PixelAlignedItemHeight) + k_ExtraVisibleItems, itemsSource.Count); if (m_VisibleItemCount != itemCount) { if (m_VisibleItemCount > itemCount) { // Shrink int removeCount = m_VisibleItemCount - itemCount; for (int i = 0; i < removeCount; i++) { int lastIndex = m_Pool.Count - 1; var poolItem = m_Pool[lastIndex]; poolItem.element.RemoveFromHierarchy(); poolItem.DetachElement(); m_Pool.RemoveAt(lastIndex); } } else { // Grow int addCount = itemCount - m_VisibleItemCount; for (int i = 0; i < addCount; i++) { int index = i + m_FirstVisibleIndex + m_VisibleItemCount; var item = makeItem(); var recycledItem = new RecycledItem(item); m_Pool.Add(recycledItem); item.AddToClassList("unity-listview-item"); item.style.marginTop = 0f; item.style.marginBottom = 0f; item.style.position = Position.Absolute; item.style.left = 0f; item.style.right = 0f; item.style.height = m_PixelAlignedItemHeight; if (index < itemsSource.Count) { Setup(recycledItem, index); } else { item.style.visibility = Visibility.Hidden; } Add(item); } } m_VisibleItemCount = itemCount; } m_LastHeight = height; UpdateBackground(); }