public bool RemoveSubview() { mySubview = null; myDisplayDelegate = null; myGetSizeToDisplayDelegate = null; return(true); }
// ====================================================================== // DSVerticalLayoutView implementation. // ---------------------------------------------------------------------- void DisplayVerticalLayout(DSView view, Rect displayArea) { Relayout(displayArea); for (int i = 0; i < mySubviews.Count; ++i) { mySubviews[i].Display(mySubviewFrames[i]); } }
// ====================================================================== // Subview management // ---------------------------------------------------------------------- public void AddSubview(DSView subview, RectOffset margins, DSView.AnchorEnum alignment = DSView.AnchorEnum.TopLeft) { DSCellView container = new DSCellView(margins, false, subview); container.Anchor = alignment; mySubviews.Add(container); mySubviewFrames.Add(new Rect(0, 0, 0, 0)); }
Vector2 GetVerticalLayoutSize(DSView view, Rect displayArea) { Vector2 size = Vector2.zero; foreach (var subview in mySubviews) { var subviewSize = subview.GetSizeToDisplay(displayArea); size.x = Mathf.Max(size.x, subviewSize.x); size.y += subviewSize.y; } return(size); }
public bool RemoveSubview(DSView subview) { int idx = FindIndexOfSubview(subview); if (idx < 0) { return(false); } mySubviews.RemoveAt(idx); mySubviewFrames.RemoveAt(idx); return(true); }
int FindIndexOfSubview(DSView subview) { int idx = -1; for (int i = 0; i < mySubviews.Count; ++i) { if (mySubviews[i].Subview == subview) { idx = i; break; } } return(idx); }
public bool ReplaceSubview(DSView toRemove, DSView bySubview, RectOffset margins, DSView.AnchorEnum alignment = DSView.AnchorEnum.TopLeft) { int idx = FindIndexOfSubview(toRemove); if (idx < 0) { return(false); } DSCellView container = new DSCellView(margins, false, bySubview); container.Anchor = alignment; mySubviews[idx] = container; mySubviewFrames[idx] = new Rect(0, 0, 0, 0); return(true); }
// ====================================================================== // Subview management // ---------------------------------------------------------------------- public void AddSubview(GUIContent selecionId, DSView subview) { // Add to selection id array. System.Array.Resize(ref mySelectionIds, mySelectionIds.Length + 1); mySelectionIds[mySelectionIds.Length - 1] = selecionId; // Add to subview array. System.Array.Resize(ref mySubviews, mySubviews.Length + 1); mySubviews[mySubviews.Length - 1] = subview; // Prime first subview. if (mySubviews.Length == 1) { mySelectionIdx = 0; AddSwapableSubview(mySelectionIdx); } }
// ---------------------------------------------------------------------- public bool RemoveSubview(DSView subview) { bool found = false; int idx = 0; for (; idx < mySubviews.Length; ++idx) { if (mySubviews[idx] == subview) { found = true; break; } } if (!found) { return(false); } // Recompute selected subview if it was removed. bool needNewSelection = false; if (idx == mySelectionIdx) { RemoveSwapableSubview(mySelectionIdx); needNewSelection = true; } // Cleanup internal information. for (int i = idx + 1; i < mySelectionIds.Length; ++i) { mySelectionIds[i - 1] = mySelectionIds[i]; } System.Array.Resize(ref mySelectionIds, mySelectionIds.Length - 1); for (int i = idx + 1; i < mySubviews.Length; ++i) { mySubviews[i - 1] = mySubviews[i]; } System.Array.Resize(ref mySubviews, mySubviews.Length - 1); // Rearrange selection. if (needNewSelection) { if (mySelectionIdx != 0) { --mySelectionIdx; } AddSwapableSubview(mySelectionIdx); } return(true); }
// ====================================================================== // DSSearchView implementation. // ---------------------------------------------------------------------- void DisplaySearchField(DSView view, Rect displayArea) { if (mySearchFieldGUIStyle == null) { mySearchString = GUI.TextField(displayArea, mySearchString); } else { mySearchString = GUI.TextField(displayArea, mySearchString, mySearchFieldGUIStyle); } if (GUI.changed) { if (mySearchAction != null) { mySearchAction(this, mySearchString); } } }
Vector2 GetSearchFieldSize(DSView view, Rect displayArea) { return(mySearchFieldSize); }
public DSTitleView(RectOffset margins, bool shouldDisplayFrame, GUIContent title, AnchorEnum titleAlignment, bool titleSeperator, DSView subview) : this(margins, shouldDisplayFrame, title, titleAlignment, titleSeperator, (v, f) => { subview.Display(f); }, (v, f) => { return(subview.GetSizeToDisplay(f)); }) {}
// ====================================================================== // Subview management // ---------------------------------------------------------------------- public void SetSubview(DSView subview) { myDisplayDelegate = (v, f) => subview.Display(f); myGetSizeToDisplayDelegate = (v, f) => subview.GetSizeToDisplay(f); }
public DSCellView(RectOffset margins, bool shouldDisplayFrame, DSView subview) : this(margins, shouldDisplayFrame, (v, f) => subview.Display(f), (v, f) => subview.GetSizeToDisplay(f)) { mySubview = subview; }
public DSScrollView(RectOffset margins, bool shouldDisplayFrame, bool useFullWidth, bool useFullHeight, DSView subview) : this(margins, shouldDisplayFrame, useFullWidth, useFullHeight, (v, f) => subview.Display(f), (v, f) => subview.GetSizeToDisplay(f)) { }