Ejemplo n.º 1
0
        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--;
                }
            }
        }
Ejemplo n.º 2
0
        private void DrawItems(TreeItemCollection items, ref DrawContext context)
        {
            foreach (var item in items)
            {
                if (hover?.item == item)
                {
                    context.brush.Color = Color.ToRawColor4();
                    context.canvas.NativeDeviceContext.FillRectangle(hover.bounds, context.brush);
                    context.brush.Color = (checkHover ? Backcolor : Forecolor).ToRawColor4();
                }

                if (item.Children.Count > 0)
                {
                    var select = new RectangleF(context.indent * context.indentWidth + 10,
                                                (context.offset + 0.5f) * context.lineHeight - 8,
                                                16, 16);
                    context.canvas.NativeDeviceContext.FillRectangle(select, context.brush);
                }

                context.brush.Color = Forecolor.ToRawColor4();
                if (item.Text != null)
                {
                    var rect = new RectangleF(context.indent * context.indentWidth + 30,
                                              context.offset++ *context.lineHeight, Width, context.lineHeight);
                    context.canvas.NativeDeviceContext.DrawText(item.Text, context.format, rect, context.brush);
                }


                if (item.Expanded && item.Children.Count > 0)
                {
                    context.indent++;
                    DrawItems(item.Children, ref context);
                    context.indent--;
                }
            }
        }
Ejemplo n.º 3
0
 public Tree()
 {
     Items    = new TreeItemCollection(this);
     scroller = new Scroller(this);
 }