Beispiel #1
0
        public static void DrawButtonTextImage(this CommandBuffer _out_, RectangleF *bounds, RectangleF *label,
                                               RectangleF *image, uint state, nk_style_button style, string str, nk_font font, nk_image img)
        {
            var           text = new nk_text();
            nk_style_item background;

            background = DrawButton(_out_, bounds, state, style);
            if (background.type == NK_STYLE_ITEM_COLOR)
            {
                text.Background = background.Color;
            }
            else
            {
                text.Background = style.text_background;
            }
            if ((state & NK_WIDGET_STATE_HOVER) != 0)
            {
                text.text = style.text_hover;
            }
            else if ((state & NK_WIDGET_STATE_ACTIVED) != 0)
            {
                text.text = style.text_active;
            }
            else
            {
                text.text = style.text_normal;
            }
            text.padding = new Vector2(0, 0);
            _out_.WidgetText(*label, str, &text, nk_text_align.NK_TEXT_CENTERED, font);
            _out_.DrawImage(*image, img, nk_white);
        }
Beispiel #2
0
        public static void DrawButtonText(this CommandBuffer _out_, RectangleF *bounds, RectangleF *content, uint state,
                                          nk_style_button style, StringSegment txt, nk_text_align text_alignment, nk_font font)
        {
            var           text = new nk_text();
            nk_style_item background;

            background = DrawButton(_out_, bounds, state, style);
            if (background.type == NK_STYLE_ITEM_COLOR)
            {
                text.Background = background.Color;
            }
            else
            {
                text.Background = style.text_background;
            }
            if ((state & NK_WIDGET_STATE_HOVER) != 0)
            {
                text.text = style.text_hover;
            }
            else if ((state & NK_WIDGET_STATE_ACTIVED) != 0)
            {
                text.text = style.text_active;
            }
            else
            {
                text.text = style.text_normal;
            }
            text.padding = new Vector2(0, 0);
            _out_.WidgetText(*content, txt, &text, text_alignment, font);
        }
Beispiel #3
0
        public static void DrawCheckBox(this CommandBuffer _out_, uint state, nk_style_toggle style, bool active,
                                        RectangleF *label, RectangleF *selector, RectangleF *cursors, string _string_, nk_font font)
        {
            nk_style_item background;
            nk_style_item cursor;
            var           text = new nk_text();

            if ((state & NK_WIDGET_STATE_HOVER) != 0)
            {
                background = style.hover;
                cursor     = style.cursor_hover;
                text.text  = style.text_hover;
            }
            else if ((state & NK_WIDGET_STATE_ACTIVED) != 0)
            {
                background = style.hover;
                cursor     = style.cursor_hover;
                text.text  = style.text_active;
            }
            else
            {
                background = style.normal;
                cursor     = style.cursor_normal;
                text.text  = style.text_normal;
            }

            if (background.type == NK_STYLE_ITEM_COLOR)
            {
                _out_.FillRect(*selector, 0, style.border_color);
                _out_.FillRect(RectangleF.nk_shrink_rect_(*selector, style.border),
                               0, background.Color);
            }
            else
            {
                _out_.DrawImage(*selector, background.Image, nk_white);
            }

            if (active)
            {
                if (cursor.type == NK_STYLE_ITEM_IMAGE)
                {
                    _out_.DrawImage(*cursors, cursor.Image, nk_white);
                }
                else
                {
                    _out_.FillRect(*cursors, 0, cursor.Color);
                }
            }

            text.padding.X  = 0;
            text.padding.Y  = 0;
            text.Background = style.text_background;
            _out_.WidgetText(*label, _string_, &text, nk_text_align.NK_TEXT_LEFT, font);
        }
Beispiel #4
0
		public static void nk_text_wrap_colored(this NuklearContext ctx, StringSegment str, Color color)
		{
			nk_window win;
			nk_style style;
			var item_padding = new Vector2();
			var bounds = new RectangleF();
			var text = new nk_text();
			if (ctx == null || ctx.current == null || ctx.current.Layout == null) return;
			win = ctx.current;
			style = ctx.style;
			ctx.PanelAllocSpace(ref bounds);
			item_padding = style.text.Padding;
			text.padding.X = item_padding.X;
			text.padding.Y = item_padding.Y;
			text.Background = style.window.background;
			text.text = color;
			win.Buffer.nk_widget_text_wrap(bounds, str, &text, style.font);
		}
Beispiel #5
0
        public static void DrawProperty(this CommandBuffer _out_, nk_style_property style, RectangleF *bounds,
                                        RectangleF *label, uint state, string name, nk_font font)
        {
            var           text = new nk_text();
            nk_style_item background;

            if ((state & NK_WIDGET_STATE_ACTIVED) != 0)
            {
                background = style.active;
                text.text  = style.label_active;
            }
            else if ((state & NK_WIDGET_STATE_HOVER) != 0)
            {
                background = style.hover;
                text.text  = style.label_hover;
            }
            else
            {
                background = style.normal;
                text.text  = style.label_normal;
            }

            if (background.type == NK_STYLE_ITEM_IMAGE)
            {
                _out_.DrawImage(*bounds, background.Image, nk_white);
                text.Background = Color.Transparent;
            }
            else
            {
                text.Background = background.Color;
                _out_.FillRect(*bounds, style.Rounding, background.Color);
                _out_.StrokeRect(*bounds, style.Rounding, style.border,
                                 background.Color);
            }

            text.padding = new Vector2(0, 0);
            _out_.WidgetText(*label, name, &text, nk_text_align.NK_TEXT_CENTERED, font);
        }
Beispiel #6
0
		public static void nk_widget_text_wrap(this CommandBuffer o, RectangleF b, StringSegment _string_, nk_text* t,
			nk_font f)
		{
			float width;
			var glyphs = 0;
			var fitting = 0;
			var done = 0;
			var line = new RectangleF();
			var text = new nk_text();
			var seperator = stackalloc uint[1];
			seperator[0] = ' ';

			if (o == null || t == null)
				return;
			text.padding = new Vector2(0, 0);
			text.Background = t->Background;
			text.text = t->text;
			b.Width = b.Width < 2 * t->padding.X ? 2 * t->padding.X : b.Width;
			b.Height = b.Height < 2 * t->padding.Y ? 2 * t->padding.Y : b.Height;
			b.Height = b.Height - 2 * t->padding.Y;
			line.X = b.X + t->padding.X;
			line.Y = b.Y + t->padding.Y;
			line.Width = b.Width - 2 * t->padding.X;
			line.Height = 2 * t->padding.Y + f.Size;
			fitting = f.nk_text_clamp(_string_, line.Width, out glyphs, out width, seperator, 1);
			while (done < _string_.Length)
			{
				if (fitting == 0 || line.Y + line.Height >= b.Y + b.Height)
					break;
				WidgetText(o, line, _string_ + done, &text, nk_text_align.NK_TEXT_LEFT, f);
				done += fitting;
				line.Y += f.Size + 2 * t->padding.Y;
				fitting = f.nk_text_clamp(_string_ + done, line.Width, out glyphs, out width,
					seperator, 1);
			}
		}
Beispiel #7
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);
        }
Beispiel #8
0
        public static bool ComboBeginImageText(this NuklearContext ctx, string selected, nk_image img, Vector2 size)
        {
            nk_window     win;
            nk_style      style;
            nk_input      _in_;
            var           header     = new RectangleF();
            var           is_clicked = false;
            int           s;
            nk_style_item background;
            var           text = new nk_text();

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }
            win   = ctx.current;
            style = ctx.style;
            s     = ctx.Widget(ref header);
            if (s == 0)
            {
                return(false);
            }
            _in_ = (win.Layout.Flags & NK_WINDOW_ROM) != 0 || s == NK_WIDGET_ROM ? null : ctx.input;
            if (ButtonBehavior(ref ctx.last_widget_state, header, _in_, NK_BUTTON_DEFAULT))
            {
                is_clicked = true;
            }
            if ((ctx.last_widget_state & NK_WIDGET_STATE_ACTIVED) != 0)
            {
                background = style.combo.active;
                text.text  = style.combo.label_active;
            }
            else if ((ctx.last_widget_state & NK_WIDGET_STATE_HOVER) != 0)
            {
                background = style.combo.hover;
                text.text  = style.combo.label_hover;
            }
            else
            {
                background = style.combo.normal;
                text.text  = style.combo.label_normal;
            }

            if (background.type == NK_STYLE_ITEM_IMAGE)
            {
                text.Background = Color.Transparent;
                win.Buffer.DrawImage(header, background.Image, nk_white);
            }
            else
            {
                text.Background = background.Color;
                win.Buffer.FillRect(header, style.combo.Rounding, background.Color);
                win.Buffer.StrokeRect(header, style.combo.Rounding, style.combo.border,
                                      style.combo.border_color);
            }

            {
                var            content = new RectangleF();
                var            button  = new RectangleF();
                var            label   = new RectangleF();
                var            image   = new RectangleF();
                nk_symbol_type sym;
                if ((ctx.last_widget_state & NK_WIDGET_STATE_HOVER) != 0)
                {
                    sym = style.combo.sym_hover;
                }
                else if (is_clicked)
                {
                    sym = style.combo.sym_active;
                }
                else
                {
                    sym = style.combo.sym_normal;
                }
                button.Width   = header.Height - 2 * style.combo.button_padding.Y;
                button.X       = header.X + header.Width - header.Height - style.combo.button_padding.X;
                button.Y       = header.Y + style.combo.button_padding.Y;
                button.Height  = button.Width;
                content.X      = button.X + style.combo.button.padding.X;
                content.Y      = button.Y + style.combo.button.padding.Y;
                content.Width  = button.Width - 2 * style.combo.button.padding.X;
                content.Height = button.Height - 2 * style.combo.button.padding.Y;
                win.Buffer.DrawButtonSymbol(&button, &content, ctx.last_widget_state, ctx.style.combo.button,
                                            sym, style.font);
                image.X      = header.X + style.combo.content_padding.X;
                image.Y      = header.Y + style.combo.content_padding.Y;
                image.Height = header.Height - 2 * style.combo.content_padding.Y;
                image.Width  = image.Height;
                win.Buffer.DrawImage(image, img, nk_white);
                text.padding = new Vector2(0, 0);
                label.X      = image.X + image.Width + style.combo.spacing.X + style.combo.content_padding.X;
                label.Y      = header.Y + style.combo.content_padding.Y;
                label.Width  = button.X - style.combo.content_padding.X - label.X;
                label.Height = header.Height - 2 * style.combo.content_padding.Y;
                win.Buffer.WidgetText(label, selected, &text, nk_text_align.NK_TEXT_LEFT, style.font);
            }

            return(ComboBegin(ctx, win, size, is_clicked, header));
        }
Beispiel #9
0
        public static void DrawSymbol(this CommandBuffer _out_, nk_symbol_type type, RectangleF content,
                                      Color background, Color foreground, float border_width, nk_font font)
        {
            switch (type)
            {
            case nk_symbol_type.NK_SYMBOL_X:
            case nk_symbol_type.NK_SYMBOL_UNDERSCORE:
            case nk_symbol_type.NK_SYMBOL_PLUS:
            case nk_symbol_type.NK_SYMBOL_MINUS:
            {
                var X = type == nk_symbol_type.NK_SYMBOL_X
                                                        ? "x"
                                                        : type == nk_symbol_type.NK_SYMBOL_UNDERSCORE
                                                                ? "_"
                                                                : type == nk_symbol_type.NK_SYMBOL_PLUS
                                                                        ? "+"
                                                                        : "-";
                var text = new nk_text();
                text.padding    = new Vector2(0, 0);
                text.Background = background;
                text.text       = foreground;
                _out_.WidgetText(content, X, &text, nk_text_align.NK_TEXT_CENTERED, font);
            }
            break;

            case nk_symbol_type.NK_SYMBOL_CIRCLE_SOLID:
            case nk_symbol_type.NK_SYMBOL_CIRCLE_OUTLINE:
            case nk_symbol_type.NK_SYMBOL_RECT_SOLID:
            case nk_symbol_type.NK_SYMBOL_RECT_OUTLINE:
            {
                if (type == nk_symbol_type.NK_SYMBOL_RECT_SOLID || type == nk_symbol_type.NK_SYMBOL_RECT_OUTLINE)
                {
                    _out_.FillRect(content, 0, foreground);
                    if (type == nk_symbol_type.NK_SYMBOL_RECT_OUTLINE)
                    {
                        _out_.FillRect(RectangleF.nk_shrink_rect_(content, border_width),
                                       0, background);
                    }
                }
                else
                {
                    _out_.nk_fill_circle(content, foreground);
                    if (type == nk_symbol_type.NK_SYMBOL_CIRCLE_OUTLINE)
                    {
                        _out_.nk_fill_circle(RectangleF.nk_shrink_rect_(content, 1),
                                             background);
                    }
                }
            }
            break;

            case nk_symbol_type.NK_SYMBOL_TRIANGLE_UP:
            case nk_symbol_type.NK_SYMBOL_TRIANGLE_DOWN:
            case nk_symbol_type.NK_SYMBOL_TRIANGLE_LEFT:
            case nk_symbol_type.NK_SYMBOL_TRIANGLE_RIGHT:
            {
                int heading;
                var points = stackalloc Vector2[3];
                heading =
                    type == nk_symbol_type.NK_SYMBOL_TRIANGLE_RIGHT
                                                                ? NK_RIGHT
                                                                : type == nk_symbol_type.NK_SYMBOL_TRIANGLE_LEFT
                                                                        ? NK_LEFT
                                                                        : type == nk_symbol_type.NK_SYMBOL_TRIANGLE_UP
                                                                                ? NK_UP
                                                                                : NK_DOWN;
                RectangleF.nk_triangle_from_direction(points, content, 0, 0, heading);
                _out_.FillTriangle(points[0].X, points[0].Y, points[1].X,
                                   points[1].Y, points[2].X, points[2].Y, foreground);
            }
            break;

            default:
            case nk_symbol_type.NK_SYMBOL_NONE:
            case nk_symbol_type.NK_SYMBOL_MAX:
                break;
            }
        }
Beispiel #10
0
        public static bool nk_panel_begin(this NuklearContext ctx, string title, int panel_type)
        {
            nk_input      _in_;
            nk_window     win;
            nk_panel      layout;
            CommandBuffer _out_;
            nk_style      style;
            nk_font       font;
            var           scrollbar_size = new Vector2();
            var           panel_padding  = new Vector2();

            if (ctx == null || ctx.current == null || ctx.current.Layout == null)
            {
                return(false);
            }

            if ((ctx.current.Flags & NK_WINDOW_HIDDEN) != 0 || (ctx.current.Flags & NK_WINDOW_CLOSED) != 0)
            {
                ctx.current.Layout.Type = panel_type;
                return(false);
            }

            style          = ctx.style;
            font           = style.font;
            win            = ctx.current;
            layout         = win.Layout;
            _out_          = win.Buffer;
            _in_           = (win.Flags & NK_WINDOW_NO_INPUT) != 0 ? null : ctx.input;
            scrollbar_size = style.window.scrollbar_size;
            panel_padding  = nk_panel_get_padding(style, panel_type);
            if ((win.Flags & NK_WINDOW_MOVABLE) != 0 && (win.Flags & NK_WINDOW_ROM) == 0)
            {
                bool left_mouse_down;
                bool left_mouse_click_in_cursor;
                var  header = new RectangleF();
                header.X     = win.Bounds.X;
                header.Y     = win.Bounds.Y;
                header.Width = win.Bounds.Width;
                if (nk_panel_has_header(win.Flags, title) != 0)
                {
                    header.Height  = font.Size + 2.0f * style.window.header.padding.Y;
                    header.Height += 2.0f * style.window.header.label_padding.Y;
                }
                else
                {
                    header.Height = panel_padding.Y;
                }

                left_mouse_down            = _in_.mouse.buttons[NK_BUTTON_LEFT].down;
                left_mouse_click_in_cursor =
                    nk_input_has_mouse_click_down_in_rect(_in_, NK_BUTTON_LEFT, header, true);
                if (left_mouse_down && left_mouse_click_in_cursor)
                {
                    win.Bounds.X = win.Bounds.X + _in_.mouse.delta.X;
                    win.Bounds.Y = win.Bounds.Y + _in_.mouse.delta.Y;
                    _in_.mouse.buttons[NK_BUTTON_LEFT].clicked_pos.X +=
                        _in_.mouse.delta.X;
                    _in_.mouse.buttons[NK_BUTTON_LEFT].clicked_pos.Y +=
                        _in_.mouse.delta.Y;
                    ctx.style.cursor_active = ctx.style.cursors[NK_CURSOR_MOVE];
                }
            }

            layout.Type          = panel_type;
            layout.Flags         = win.Flags;
            layout.Bounds        = win.Bounds;
            layout.Bounds.X     += panel_padding.X;
            layout.Bounds.Width -= 2 * panel_padding.X;
            if ((win.Flags & NK_WINDOW_BORDER) != 0)
            {
                layout.Border = nk_panel_get_border(style, win.Flags, panel_type);
                layout.Bounds = RectangleF.nk_shrink_rect_(layout.Bounds, layout.Border);
            }
            else
            {
                layout.Border = 0;
            }

            layout.At_y          = layout.Bounds.Y;
            layout.At_x          = layout.Bounds.X;
            layout.Max_x         = 0;
            layout.Header_height = 0;
            layout.Footer_height = 0;
            ctx.LayoutResetMinRowHeight();
            layout.Row.index      = 0;
            layout.Row.columns    = 0;
            layout.Row.ratio      = null;
            layout.Row.item_width = 0;
            layout.Row.tree_depth = 0;
            layout.Row.height     = panel_padding.Y;
            layout.Has_scrolling  = nk_true;
            if ((win.Flags & NK_WINDOW_NO_SCROLLBAR) == 0)
            {
                layout.Bounds.Width -= scrollbar_size.X;
            }
            if (nk_panel_is_nonblock(panel_type) == 0)
            {
                layout.Footer_height = 0;
                if ((win.Flags & NK_WINDOW_NO_SCROLLBAR) == 0 || (win.Flags & NK_WINDOW_SCALABLE) != 0)
                {
                    layout.Footer_height = scrollbar_size.Y;
                }
                layout.Bounds.Height -= layout.Footer_height;
            }

            if (nk_panel_has_header(win.Flags, title) != 0)
            {
                var           text       = new nk_text();
                var           header     = new RectangleF();
                nk_style_item background = null;
                header.X              = win.Bounds.X;
                header.Y              = win.Bounds.Y;
                header.Width          = win.Bounds.Width;
                header.Height         = font.Size + 2.0f * style.window.header.padding.Y;
                header.Height        += 2.0f * style.window.header.label_padding.Y;
                layout.Header_height  = header.Height;
                layout.Bounds.Y      += header.Height;
                layout.Bounds.Height -= header.Height;
                layout.At_y          += header.Height;
                if (ctx.active == win)
                {
                    background = style.window.header.active;
                    text.text  = style.window.header.label_active;
                }
                else if (nk_input_is_mouse_hovering_rect(ctx.input, header))
                {
                    background = style.window.header.hover;
                    text.text  = style.window.header.label_hover;
                }
                else
                {
                    background = style.window.header.normal;
                    text.text  = style.window.header.label_normal;
                }

                header.Height += 1.0f;
                if (background.type == NK_STYLE_ITEM_IMAGE)
                {
                    text.Background = Color.Transparent;
                    win.Buffer.DrawImage(header, background.Image, nk_white);
                }
                else
                {
                    text.Background = background.Color;
                    _out_.FillRect(header, 0, background.Color);
                }

                {
                    var button = new RectangleF();
                    button.Y      = header.Y + style.window.header.padding.Y;
                    button.Height = header.Height - 2 * style.window.header.padding.Y;
                    button.Width  = button.Height;
                    if ((win.Flags & NK_WINDOW_CLOSABLE) != 0)
                    {
                        var ws = (uint)0;
                        if (style.window.header.align == NK_HEADER_RIGHT)
                        {
                            button.X = header.Width + header.X -
                                       (button.Width + style.window.header.padding.X);
                            header.Width -= button.Width + style.window.header.spacing.X +
                                            style.window.header.padding.X;
                        }
                        else
                        {
                            button.X  = header.X + style.window.header.padding.X;
                            header.X += button.Width + style.window.header.spacing.X +
                                        style.window.header.padding.X;
                        }

                        if (
                            DoButtonSymbol(ref ws, win.Buffer, button,
                                           style.window.header.close_symbol,
                                           NK_BUTTON_DEFAULT, style.window.header.close_button, _in_, style.font) &&
                            (win.Flags & NK_WINDOW_ROM) == 0)
                        {
                            layout.Flags |= NK_WINDOW_HIDDEN;
                            layout.Flags &= ~(uint)NK_WINDOW_MINIMIZED;
                        }
                    }

                    if ((win.Flags & NK_WINDOW_MINIMIZABLE) != 0)
                    {
                        var ws = (uint)0;
                        if (style.window.header.align == NK_HEADER_RIGHT)
                        {
                            button.X = header.Width + header.X - button.Width;
                            if ((win.Flags & NK_WINDOW_CLOSABLE) == 0)
                            {
                                button.X     -= style.window.header.padding.X;
                                header.Width -= style.window.header.padding.X;
                            }

                            header.Width -= button.Width + style.window.header.spacing.X;
                        }
                        else
                        {
                            button.X  = header.X;
                            header.X += button.Width + style.window.header.spacing.X +
                                        style.window.header.padding.X;
                        }

                        if (
                            DoButtonSymbol(ref ws, win.Buffer, button,
                                           (layout.Flags & NK_WINDOW_MINIMIZED) != 0
                                                                        ? style.window.header.maximize_symbol
                                                                        : style.window.header.minimize_symbol, NK_BUTTON_DEFAULT,
                                           style.window.header.minimize_button, _in_,
                                           style.font) && (win.Flags & NK_WINDOW_ROM) == 0)
                        {
                            layout.Flags =
                                (layout.Flags & NK_WINDOW_MINIMIZED) != 0
                                                                        ? layout.Flags & ~(uint)NK_WINDOW_MINIMIZED
                                                                        : layout.Flags | NK_WINDOW_MINIMIZED;
                        }
                    }
                }
                {
                    var label = new RectangleF();
                    var t     = font.width(title);
                    text.padding = new Vector2(0, 0);
                    label.X      = header.X + style.window.header.padding.X;
                    label.X     += style.window.header.label_padding.X;
                    label.Y      = header.Y + style.window.header.label_padding.Y;
                    label.Height = font.Size + 2 * style.window.header.label_padding.Y;
                    label.Width  = t + 2 * style.window.header.spacing.X;
                    label.Width  =
                        (label.Width < header.X + header.Width - label.X
                                                        ? label.Width
                                                        : header.X + header.Width - label.X) < 0
                                                        ? 0
                                                        : label.Width < header.X + header.Width - label.X
                                                                ? label.Width
                                                                : header.X + header.Width - label.X;
                    _out_.WidgetText(label, title, &text, nk_text_align.NK_TEXT_LEFT, font);
                }
            }

            if ((layout.Flags & NK_WINDOW_MINIMIZED) == 0 && (layout.Flags & NK_WINDOW_DYNAMIC) == 0)
            {
                var body = new RectangleF();
                body.X      = win.Bounds.X;
                body.Width  = win.Bounds.Width;
                body.Y      = win.Bounds.Y + layout.Header_height;
                body.Height = win.Bounds.Height - layout.Header_height;
                if (style.window.fixed_background.type == NK_STYLE_ITEM_IMAGE)
                {
                    _out_.DrawImage(body, style.window.fixed_background.Image, nk_white);
                }
                else
                {
                    _out_.FillRect(body, 0,
                                   style.window.fixed_background.Color);
                }
            }

            {
                var clip = new RectangleF();
                layout.Clip = layout.Bounds;
                RectangleF.nk_unify(ref clip, ref win.Buffer.Clip, layout.Clip.X, layout.Clip.Y,
                                    layout.Clip.X + layout.Clip.Width, layout.Clip.Y + layout.Clip.Height);
                _out_.Scissor(clip);
                layout.Clip = clip;
            }

            return((layout.Flags & NK_WINDOW_HIDDEN) == 0 && (layout.Flags & NK_WINDOW_MINIMIZED) == 0);
        }
Beispiel #11
0
        public static void DrawSelectable(this CommandBuffer _out_, uint state, nk_style_selectable style, bool active,
                                          RectangleF *bounds, RectangleF *icon, nk_image img, string _string_, nk_text_align align,
                                          nk_font font)
        {
            nk_style_item background;
            var           text = new nk_text();

            text.padding = style.padding;
            if (!active)
            {
                if ((state & NK_WIDGET_STATE_ACTIVED) != 0)
                {
                    background = style.pressed;
                    text.text  = style.text_pressed;
                }
                else if ((state & NK_WIDGET_STATE_HOVER) != 0)
                {
                    background = style.hover;
                    text.text  = style.text_hover;
                }
                else
                {
                    background = style.normal;
                    text.text  = style.text_normal;
                }
            }
            else
            {
                if ((state & NK_WIDGET_STATE_ACTIVED) != 0)
                {
                    background = style.pressed_active;
                    text.text  = style.text_pressed_active;
                }
                else if ((state & NK_WIDGET_STATE_HOVER) != 0)
                {
                    background = style.hover_active;
                    text.text  = style.text_hover_active;
                }
                else
                {
                    background = style.normal_active;
                    text.text  = style.text_normal_active;
                }
            }

            if (background.type == NK_STYLE_ITEM_IMAGE)
            {
                _out_.DrawImage(*bounds, background.Image, nk_white);
                text.Background = Color.Transparent;
            }
            else
            {
                _out_.FillRect(*bounds, style.Rounding, background.Color);
                text.Background = background.Color;
            }

            if (img != null && icon != null)
            {
                _out_.DrawImage(*icon, img, nk_white);
            }
            _out_.WidgetText(*bounds, _string_, &text, align, font);
        }