public TreeViewItemWrapper( TSource dataItem, ITreeviewSourceDecoder <TSource> decoder, ITreeViewItemWrapper <TSource> parent, bool isLastSibling, ITreeview <TSource> treeview) { if (dataItem == null) { throw new ArgumentNullException("dataItem"); } if (decoder == null) { throw new ArgumentNullException("decoder"); } if (treeview == null) { throw new ArgumentNullException("treeview"); } this._dataItem = dataItem; this._decoder = decoder; this._parent = parent; this._isLastSibling = isLastSibling; this.treeview = treeview; }
public Vector2 RenderItemIcon(ITreeViewItemWrapper <TSource> item, Vector2 topLeft) { if (item == null) { throw new ArgumentNullException("item"); } var iconRect = this.InternalRenderIcon(IconTypes.Item, topLeft, item); return(new Vector2(iconRect.width, iconRect.height)); }
private float RenderTreeviewIcons(ITreeViewItemWrapper <TSource> item, Rect iconSpace, EventType currentEventType) { var gridx = 0f; Vector2 icon; if (item.Parent == null) { var iconType = item.IsExpanded ? IconTypes.LMinus : IconTypes.LPlus; // Root item icon = iconRenderer.RenderIcon(iconType, new Vector2(0, iconSpace.y)); if (currentEventType == EventType.Repaint) { // Co-ordinates only accurate during repaint. this.rowClickableLocations.RegisterRowExpander(new Rect(0, iconSpace.y, icon.x, icon.y), item); } gridx = icon.x; } else { // All other items gridx = hierarchyLinesRenderer.Render(item, new Vector2(0, iconSpace.y)); // Item if (item.HasChildren) { var iconType = item.IsExpanded ? item.IsLastSibling ? IconTypes.LMinus : IconTypes.TMinus : item.IsLastSibling ? IconTypes.LPlus : IconTypes.TPlus; icon = iconRenderer.RenderIcon(iconType, new Vector2(gridx, iconSpace.y)); if (currentEventType == EventType.Repaint) { // Co-ordinates only accurate during repaint. this.rowClickableLocations.RegisterRowExpander(new Rect(gridx, iconSpace.y, icon.x, icon.y), item); } gridx += icon.x; } else { var iconType = item.IsLastSibling ? IconTypes.LBar : IconTypes.TBar; icon = iconRenderer.RenderIcon(iconType, new Vector2(gridx, iconSpace.y)); gridx += icon.x; } } return(gridx); }
private void RenderChildren(ITreeViewItemWrapper <TSource> parent, ITreeviewSourceDecoder <TSource> treeviewSourceDecoder, EventType currentEventType) { foreach (var child in parent.Children) { treeviewRowRenderer.RenderRow(child, treeviewSourceDecoder, currentEventType); if (child.IsExpanded) { RenderChildren(child, treeviewSourceDecoder, currentEventType); } } }
public void RenderRow(ITreeViewItemWrapper <TSource> item, ITreeviewSourceDecoder <TSource> treeviewSourceDecoder, EventType currentEventType) { if (item == null) { throw new ArgumentNullException("item"); } if (treeviewSourceDecoder == null) { throw new ArgumentNullException("treeviewSourceDecoder"); } var gridRect = new Rect(0, 0, 0, 0); guiLayout.BeginHorizontal(); guiLayout.Space(1); // In order to use the GUI.DrawTexture which takes absolute position on the page // we have to get the relative location of the space we just drew. if (currentEventType == EventType.repaint) { gridRect = guiLayout.GetLastRect(); } var structureX = RenderTreeviewIcons(item, gridRect, currentEventType); var iconTopLeft = new Vector2(gridRect.x + structureX, gridRect.y); guiLayout.Space(gridRect.x + structureX); var itemIconDimensions = iconRenderer.RenderItemIcon(item, iconTopLeft); if (itemIconDimensions.x > 0) { rowClickableLocations.RegisterRowIcon(new Rect(iconTopLeft.x, iconTopLeft.y, itemIconDimensions.x, itemIconDimensions.y), item); } guiLayout.Space(itemIconDimensions.x); var renderContext = new RenderDisplayContext(item.IsSelected, item.IsExpanded, item.IsActive); treeviewSourceDecoder.RenderDisplay(item.Value, renderContext); if (currentEventType == EventType.repaint) { gridRect = guiLayout.GetLastRect(); rowClickableLocations.RegisterRowContent(gridRect, item); } guiLayout.EndHorizontal(); }
public float Render(ITreeViewItemWrapper <TSource> item, Vector2 lineTopLeft) { if (item == null) { throw new ArgumentNullException("item"); } if (item.Parent == null) { // Item is the root item, there is no hierarchy to render for this node. return(0); } return(this.RenderLevel(item.Parent, lineTopLeft)); }
private float RenderLevel(ITreeViewItemWrapper <TSource> item, Vector2 lineTopLeft) { var xStart = lineTopLeft.x; if (item.Parent != null) { xStart = this.RenderLevel(item.Parent, lineTopLeft); var iconType = item.IsLastSibling ? IconTypes.Space : IconTypes.Bar; var icon1 = this._iconRenderer.RenderIcon(iconType, new Vector2(xStart, lineTopLeft.y)); xStart += icon1.x; } else { var icon2 = this._iconRenderer.RenderIcon(IconTypes.Space, new Vector2(xStart, lineTopLeft.y)); xStart += icon2.x; } return(xStart); }
private Rect InternalRenderIcon(IconTypes type, Vector2 topleft, ITreeViewItemWrapper <TSource> item) { Texture2D icon; switch (type) { case IconTypes.Bar: icon = this._treeviewIcons.BarDownIcon; break; case IconTypes.LBar: icon = this._treeviewIcons.BarLIcon; break; case IconTypes.LMinus: icon = this._treeviewIcons.LMinusIcon; break; case IconTypes.LPlus: icon = this._treeviewIcons.LPlusIcon; break; case IconTypes.TMinus: icon = this._treeviewIcons.TMinusIcon; break; case IconTypes.TPlus: icon = this._treeviewIcons.TPlusIcon; break; case IconTypes.Space: icon = this._treeviewIcons.BlankIcon; break; case IconTypes.TBar: icon = this._treeviewIcons.BarTIcon; break; case IconTypes.Item: if (item == null) { // in situations where RenderIcon is used to render the Itemicon. return(new Rect(topleft.x, topleft.y, 0, 0)); } icon = this._treeviewIcons.ItemIcon(item.Value, new RenderDisplayContext(item.IsSelected, item.IsExpanded, item.IsActive)); // For blank icons, null is passed. if (icon == null) { return(new Rect(topleft.x, topleft.y, 0, 0)); } break; default: throw new Exception(string.Format("Unknown icon type: {0}", type)); } if (icon == null) { throw new NullReferenceException(string.Format("Icon {0} is null.", type)); } var iconRect = new Rect(topleft.x, topleft.y, icon.width, icon.height); this._gui.DrawTexture(iconRect, icon); return(iconRect); }
public void RegisterRowIcon(Rect icon, ITreeViewItemWrapper <TSource> data) { this.locations.Add(new RowData <TSource> { Data = data, Location = icon, RowDataType = RowDataType.Icon }); }
public void RegisterRowExpander(Rect expander, ITreeViewItemWrapper <TSource> data) { this.locations.Add(new RowData <TSource> { Data = data, Location = expander, RowDataType = RowDataType.Expander }); }
public void RegisterRowContent(Rect content, ITreeViewItemWrapper <TSource> data) { this.locations.Add(new RowData <TSource> { Data = data, Location = content, RowDataType = RowDataType.Content }); }