Example #1
0
        public static int nk_tree_state_base(this NuklearContext ctx, int type, nk_image img, string title,
                                             ref int state)
        {
            nk_window       win;
            nk_panel        layout;
            nk_style        style;
            CommandBuffer   _out_;
            nk_input        _in_;
            nk_style_button button;
            nk_symbol_type  symbol;
            float           row_height;
            var             item_spacing = new Vector2();
            var             header       = new RectangleF();
            var             sym          = new RectangleF();
            var             text         = new nk_text();
            uint            ws           = 0;
            int             widget_state;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(0);
            }
            win          = ctx.current;
            layout       = win.Layout;
            _out_        = win.Buffer;
            style        = ctx.style;
            item_spacing = style.window.spacing;
            row_height   = style.font.Size + 2 * style.tab.padding.Y;
            ctx.LayoutSetMinRowHeight(row_height);
            ctx.LayoutRowDynamic(row_height, 1);
            ctx.LayoutResetMinRowHeight();
            widget_state = ctx.Widget(ref header);
            if (type == NK_TREE_TAB)
            {
                var background = style.tab.background;
                if (background.type == NK_STYLE_ITEM_IMAGE)
                {
                    _out_.DrawImage(header, background.Image, nk_white);
                    text.Background = Color.Transparent;
                }
                else
                {
                    text.Background = background.Color;
                    _out_.FillRect(header, 0, style.tab.border_color);
                    _out_.FillRect(RectangleF.nk_shrink_rect_(header, style.tab.border),
                                   style.tab.Rounding, background.Color);
                }
            }
            else
            {
                text.Background = style.window.background;
            }

            _in_ = (layout.Flags & NK_WINDOW_ROM) == 0 ? ctx.input : null;
            _in_ = _in_ != null && widget_state == NK_WIDGET_VALID ? ctx.input : null;
            if (ButtonBehavior(ref ws, header, _in_, NK_BUTTON_DEFAULT))
            {
                state = state == NK_MAXIMIZED ? NK_MINIMIZED : NK_MAXIMIZED;
            }
            if (state == NK_MAXIMIZED)
            {
                symbol = style.tab.sym_maximize;
                if (type == NK_TREE_TAB)
                {
                    button = style.tab.tab_maximize_button;
                }
                else
                {
                    button = style.tab.node_maximize_button;
                }
            }
            else
            {
                symbol = style.tab.sym_minimize;
                if (type == NK_TREE_TAB)
                {
                    button = style.tab.tab_minimize_button;
                }
                else
                {
                    button = style.tab.node_minimize_button;
                }
            }

            {
                sym.Width = sym.Height = style.font.Size;
                sym.Y     = header.Y + style.tab.padding.Y;
                sym.X     = header.X + style.tab.padding.X;
                DoButtonSymbol(ref ws, win.Buffer, sym, symbol, NK_BUTTON_DEFAULT, button, null,
                               style.font);
                if (img != null)
                {
                    sym.X = sym.X + sym.Width + 4 * item_spacing.X;
                    win.Buffer.DrawImage(sym, img, nk_white);
                    sym.Width = style.font.Size + style.tab.spacing.X;
                }
            }

            {
                var label = new RectangleF();
                header.Width = header.Width < sym.Width + item_spacing.X ? sym.Width + item_spacing.X : header.Width;
                label.X      = sym.X + sym.Width + item_spacing.X;
                label.Y      = sym.Y;
                label.Width  = header.Width - (sym.Width + item_spacing.Y + style.tab.indent);
                label.Height = style.font.Size;
                text.text    = style.tab.text;
                text.padding = new Vector2(0, 0);
                _out_.WidgetText(label, title, &text, nk_text_align.NK_TEXT_LEFT, style.font);
            }

            if (state == NK_MAXIMIZED)
            {
                layout.At_x          = header.X + layout.Offset.X + style.tab.indent;
                layout.Bounds.Width  = layout.Bounds.Width < style.tab.indent ? style.tab.indent : layout.Bounds.Width;
                layout.Bounds.Width -= style.tab.indent + style.window.padding.X;
                layout.Row.tree_depth++;
                return(nk_true);
            }

            return(nk_false);
        }