protected virtual void DrawVisibleCells() { #if LUNAR_DEVELOPMENT if (CSystemVars.g_drawVisibleCells.BoolValue) { if (FirstVisibleCell != null) { GUI.Box(FirstVisibleCell.Frame, GUIContent.none); } if (LastVisibleCell != null) { GUI.Box(LastVisibleCell.Frame, GUIContent.none); } } #endif // LUNAR_DEVELOPMENT for (CTableViewCell cell = FirstVisibleCell; cell != null; cell = cell.NextCell) { if (IsCellSelected(cell.CellIndex)) { CUIHelper.DrawRect(cell.Frame, CSharedStyles.SelectedCellBackStyle); } cell.OnGUI(); } }
private void ShiftContent(float offset) { // we should scroll first and then shift cells Scroll(offset); // this will remove a cell if it's not visible for (CTableViewCell cell = FirstVisibleCell; cell != null; cell = cell.NextCell) { cell.Y -= offset; } m_contentOffset += offset; }
protected override bool OnMouseDoubleClick(CEvent evt, CTableViewCell cell) { CConsoleViewCell consoleCell = cell as CConsoleViewCell; if (consoleCell != null && consoleCell.OnMouseDoubleClick(evt)) { return(true); } return(base.OnMouseDoubleClick(evt, cell)); }
public CTableViewCell DequeueReusableCell(Type cellType) { CTableViewCell cell = TryGetUsedCellForType(cellType); if (cell != null) { cell.PrepareForReuse(); return(cell); } return(null); }
private CTableViewCell FindMouseCell(float clickX, float clickY) { for (CTableViewCell cell = FirstVisibleCell; cell != null; cell = cell.NextCell) { if (cell.ContainsPoint(clickX, clickY)) { return(cell); } } return(null); }
private void OnChangeWidth(float delta) { float totalHeight = 0; for (int cellIndex = m_cellsEntries.HeadIndex; cellIndex < m_cellsEntries.Length; ++cellIndex) { float cellHeight = Delegate.HeightForTableCell(cellIndex); int arrayIndex = m_cellsEntries.ToArrayIndex(cellIndex); m_cellsEntries.InternalArray[arrayIndex].Height = cellHeight; m_cellsEntries.InternalArray[arrayIndex].Top = totalHeight; totalHeight += cellHeight; } float diff = totalHeight - m_totalHeight; if (diff != 0) { m_totalHeight = totalHeight; CTableViewCell lastVisibleCell = this.LastVisibleCell; if (lastVisibleCell != null) { float screenDiff = (lastVisibleCell.Bottom + m_contentOffset) - this.ScrollPosTop; int lastVisibleCellIndex = lastVisibleCell.CellIndex; m_scrollPos = Mathf.Max(0, m_cellsEntries[lastVisibleCellIndex].Bottom - screenDiff); m_contentOffset = 0; // remove old visible cells RemoveVisibleCells(); // add new visible cells int rowIndex = FindFirstVisibleRow(m_scrollPos, m_cellsEntries.HeadIndex, m_cellsEntries.Length - 1); while (rowIndex < m_cellsEntries.Length && IsCellVisible(rowIndex, m_scrollPos)) { CTableViewCell cell = TableCellForRow(rowIndex); m_visibleCells.AddLastItem(cell); ++rowIndex; } } else { m_contentOffset = 0; m_scrollPos = 0; } m_lastSelectedIndex = -1; m_guiScrollPos = new Vector3(0, m_scrollPos, 0); } }
private CTableViewCell TableCellForRow(int index) { CTableViewCell cell = DataSource.TableCellForRow(this, index); if (cell == null) { throw new NullReferenceException("Table view cell is null"); } cell.Y = m_cellsEntries[index].Top - m_contentOffset; cell.Table = this; cell.CellIndex = index; return(cell); }
public CTableViewCell GetVisibleCell(int index) { if (index >= FirstVisibleCellIndex && index <= LastVisibleCellIndex) { for (CTableViewCell cell = FirstVisibleCell; cell != null; cell = cell.NextCell) { if (cell.CellIndex == index) { return(cell); } } } return(null); }
private void RecycleCell(CTableViewCell cell) { Type cellType = cell.GetType(); TableViewCellList cellList; if (!m_reusableCellsLists.TryGetValue(cellType, out cellList)) { cellList = new TableViewCellList(); m_reusableCellsLists[cellType] = cellList; } cell.PrepareForReuse(); cellList.AddLastItem(cell); }
private bool OnCellSelected(CTableViewCell cell) { int cellIndex = cell.CellIndex; if (this.SelectionMode == CTableViewSelectionMode.Multiple) { SetCellSelected(cellIndex, !IsCellSelected(cellIndex)); return(true); } if (!IsCellSelected(cellIndex)) { SwitchSelectedCell(cellIndex); return(true); } return(false); }
protected bool OnMouseDoubleClick(CEvent evt) { float clickX = evt.mousePosition.x; float clickY = evt.mousePosition.y + m_scrollPos - m_contentOffset; CTableViewCell cell = FindMouseCell(clickX, clickY); if (cell != null) { Vector2 oldPos = evt.mousePosition; evt.mousePosition = new Vector2(clickX - cell.X, clickY - cell.Y); bool result = OnMouseDoubleClick(evt, cell); evt.mousePosition = oldPos; return(result); } return(false); }
////////////////////////////////////////////////////////////////////////////// protected override void OnResize(float dx, float dy) { if (dx != 0) { float oldTotalHeight = this.TotalHeight; base.OnResize(dx, dy); if (oldTotalHeight == this.TotalHeight) // no re-layout: adjust cells size { for (CTableViewCell cell = this.FirstVisibleCell; cell != null; cell = cell.NextCell) { cell.OnTableResized(dx, dy); } } } else { base.OnResize(dx, dy); } }
private void OnChangeHeight(float delta) { if (delta > 0) { int rowsCount = this.RowsCount; // append more visible cells at the end for (int cellIndex = this.LastVisibleCellIndex + 1; cellIndex < rowsCount && IsCellVisible(cellIndex); ++cellIndex) { CTableViewCell cell = TableCellForRow(cellIndex); m_visibleCells.AddLastItem(cell); } } else if (delta < 0) { // wipe invisible cells while (this.VisibleCellsCount > 0 && !IsCellVisible(this.LastVisibleCellIndex)) { RemoveVisibleCell(this.LastVisibleCell); } } }
private void AddCell() { // the "head" index will be moved after new element is added if (m_cellsEntries.RealLength == m_cellsEntries.Capacity) { // "shift" content to compensate the lost cell int headIndex = m_cellsEntries.HeadIndex; ShiftContent(m_cellsEntries[headIndex].Height); } int cellIndex = m_cellsEntries.Length; float cellHeight = Delegate.HeightForTableCell(cellIndex); m_cellsEntries.Add(new CTableViewCellEntry(m_totalHeight, cellHeight)); if (IsCellVisible(cellIndex, m_scrollPos)) { CTableViewCell cell = TableCellForRow(cellIndex); m_visibleCells.AddLastItem(cell); } m_totalHeight += cellHeight; }
private void RemoveVisibleCell(CTableViewCell cell) { m_visibleCells.RemoveItem(cell); RecycleCell(cell); }
private bool IsCellSelected(CTableViewCell cell) { return(IsCellSelected(cell.CellIndex)); }
private void SetCellSelected(CTableViewCell cell, bool flag) { SetCellSelected(cell.CellIndex, flag); }
protected void OnScroll(float oldPos, float newPos) { float delta = newPos - oldPos; int firstVisibleCellIndex = FirstVisibleCellIndex; int lastVisibleCellIndex = LastVisibleCellIndex; if (delta > 0) { int rowsCount = RowsCount; // wipe invisible rows while (!IsCellVisible(firstVisibleCellIndex, newPos) && VisibleCellsCount > 0) { RemoveVisibleCell(FirstVisibleCell); ++firstVisibleCellIndex; } if (VisibleCellsCount > 0) // not all rows were wiped: just append more visible cells at the end { for (int cellIndex = lastVisibleCellIndex + 1; cellIndex < rowsCount && IsCellVisible(cellIndex, newPos); ++cellIndex) { CTableViewCell cell = TableCellForRow(cellIndex); m_visibleCells.AddLastItem(cell); } } else { int rowIndex = FindFirstVisibleRow(newPos, lastVisibleCellIndex + 1, rowsCount - 1); while (rowIndex < rowsCount && IsCellVisible(rowIndex, newPos)) { CTableViewCell cell = TableCellForRow(rowIndex); m_visibleCells.AddLastItem(cell); ++rowIndex; } } } else if (delta < 0) { while (this.VisibleCellsCount > 0 && !IsCellVisible(lastVisibleCellIndex, newPos)) { RemoveVisibleCell(LastVisibleCell); --lastVisibleCellIndex; } if (VisibleCellsCount > 0) // not all rows were wiped: just prepend more visible cells at the beginning { for (int cellIndex = firstVisibleCellIndex - 1; cellIndex >= m_cellsEntries.HeadIndex && IsCellVisible(cellIndex, newPos); --cellIndex) { CTableViewCell cell = TableCellForRow(cellIndex); m_visibleCells.AddFirstItem(cell); } } else { int rowIndex = FindLastVisibleRow(newPos, m_cellsEntries.HeadIndex, firstVisibleCellIndex - 1); while (rowIndex >= m_cellsEntries.HeadIndex && IsCellVisible(rowIndex, newPos)) { CTableViewCell cell = TableCellForRow(rowIndex); m_visibleCells.AddFirstItem(cell); --rowIndex; } } } if (ScrollDelegate != null) { ScrollDelegate.OnTableScroll(this, oldPos); } }
protected virtual bool OnMouseDoubleClick(CEvent evt, CTableViewCell cell) { return(false); }
protected virtual bool OnMouseDown(CEvent evt, CTableViewCell cell) { return(this.SelectionMode != CTableViewSelectionMode.None && OnCellSelected(cell)); }