public FR2_TreeItemUI RemoveChild(FR2_TreeItemUI child) { #if DEV_MODE { if (!IsValidChild(child)) { return(this); } if (child.parent != this) { Debug.LogWarning("child.parent != this, can not remove"); return(this); } if (!children.Contains(child)) { Debug.LogWarning("Something broken, child.parent == this but this.children does not contains child"); return(this); } } #endif child.parent = null; children.Remove(child); //Recursive update nVIsible items up the tree var delta = child.GetNVisible(_treeStamp); SetDeltaVisible(-delta, _treeStamp); return(this); }
public FR2_TreeItemUI AddChild(FR2_TreeItemUI child) { #if DEV_MODE { if (!IsValidChild(child)) { return(this); } if (child.parent == this) { Debug.LogWarning("Child.parent already == this"); return(this); } if (children.Contains(child)) { Debug.LogWarning("Something broken, child already in this.children list <" + child + "> but its parent not set to this"); return(this); } } #endif if (child.parent != null) { child.parent.RemoveChild(child); } child.parent = this; children.Add(child); var delta = child.GetNVisible(_treeStamp); SetDeltaVisible(delta, _treeStamp); return(this); }
private void RefreshVisibleCount(int stamp) { _treeStamp = stamp; _nVisible = 1; for (var i = 0; i < children.Count; i++) { FR2_TreeItemUI c = children[i]; _nVisible += c.GetNVisible(stamp); } }
public void Draw <T>(List <T> list) where T : FR2_TreeItemUI { if (root == null) { root = new FR2_TreeItemUI(); for (var i = 0; i < list.Count; i++) { root.AddChild(list[i]); } } Draw(root, false); }
private bool IsValidChild(FR2_TreeItemUI child) { if (child == null) { Debug.LogWarning("Child should not be null <" + child + ">"); return(false); } //if (child.target == null){ // Debug.LogWarning("Child's target should not be null <" + child + ">"); // return false; //} return(true); }
public void Draw(FR2_TreeItemUI root, bool drawRoot = true) { var evtType = Event.current.type; var r = GUILayoutUtility.GetRect(1f, Screen.width, itemH, Screen.height); if (evtType != EventType.Layout) { visibleRect = r; } var n = root.GetNVisible(Mathf.Max(root._treeStamp, 1)); var contentRect = new Rect(0f, 0f, 1f, n * itemH); var nVisible = Mathf.RoundToInt(visibleRect.height / itemH) + 1; var min = Mathf.Max(0, Mathf.FloorToInt(position.y / itemH)); var max = Mathf.Min(min + nVisible, n); var noScroll = contentRect.height < visibleRect.height; //Debug.Log("Drawing :: " + min + ":" + max + ":" + n); if (noScroll) { position = Vector2.zero; } position = GUI.BeginScrollView(visibleRect, position, contentRect); { var rect = new Rect(0, 0, r.width - (noScroll ? 4f : itemH), itemH); var current = 0; if (drawRoot) { root.Draw(min, max, ref rect, ref current); } else { root.DrawChildren(min, max, ref rect, ref current); } } GUI.EndScrollView(); }