private void CalculateMetrics(TreeItemCollection items, ref DrawContext context) { foreach (var item in items) { var props = new TreeItemProperties(); props.item = item; props.bounds = new RectangleF(0, context.offset * context.lineHeight, Width, context.lineHeight); props.selectBounds = new RectangleF(10 + context.indent * context.indentWidth, (context.offset + 0.5f) * context.lineHeight - 8, 16, 16); props.textBounds = new RectangleF(context.indent * context.indentWidth + 30, context.offset++ *context.lineHeight, Width, context.lineHeight); properties[item] = props; if (item.Expanded && item.Children.Count > 0) { context.indent++; CalculateMetrics(item.Children, ref context); context.indent--; } } }
protected internal override void OnMouseMove(MouseEventArgs e) { var position = scroller.ToScrollSpace(e.Position); if (TryFindItem(position, out var prop)) { hover = prop; checkHover = prop.selectBounds.Contains(position.X, position.Y); } }
private bool TryFindItem(Vector2 point, out TreeItemProperties property) { foreach (var item in properties) { if (item.Value.bounds.Contains(point.X, point.Y)) { property = item.Value; return(true); } } property = default; return(false); }