Beispiel #1
0
        public static int Combo(this NuklearContext ctx, string[] items, int count, int selected, int item_height,
                                Vector2 size)
        {
            var i = 0;
            int max_height;
            var item_spacing   = new Vector2();
            var window_padding = new Vector2();

            if (ctx == null || items == null || count == 0)
            {
                return(selected);
            }
            item_spacing   = ctx.style.window.spacing;
            window_padding = nk_panel_get_padding(ctx.style, ctx.current.Layout.Type);
            max_height     = count * item_height + count * (int)item_spacing.Y;
            max_height    += (int)item_spacing.Y * 2 + (int)window_padding.Y * 2;
            size.Y         = size.Y < (float)max_height ? size.Y : max_height;
            if (ComboBeginLabel(ctx, items[selected], size))
            {
                ctx.LayoutRowDynamic(item_height, 1);
                for (i = 0; i < count; ++i)
                {
                    if (ComboItemLabel(ctx, items[i], nk_text_align.NK_TEXT_LEFT))
                    {
                        selected = i;
                    }
                }
                ComboEnd(ctx);
            }

            return(selected);
        }
Beispiel #2
0
        public static int nk_combo_separator(this NuklearContext ctx, string items_separated_by_separator,
                                             int separator, int selected,
                                             int count, int item_height, Vector2 size)
        {
            int           i;
            int           max_height;
            var           item_spacing   = new Vector2();
            var           window_padding = new Vector2();
            StringSegment current_item;
            StringSegment iter;

            if (ctx == null || items_separated_by_separator == null)
            {
                return(selected);
            }
            item_spacing   = ctx.style.window.spacing;
            window_padding = nk_panel_get_padding(ctx.style, ctx.current.Layout.Type);
            max_height     = count * item_height + count * (int)item_spacing.Y;
            max_height    += (int)item_spacing.Y * 2 + (int)window_padding.Y * 2;
            size.Y         = size.Y < (float)max_height ? size.Y : max_height;
            current_item   = items_separated_by_separator;
            for (i = 0; i < count; ++i)
            {
                iter = current_item;
                while (!iter.IsNullOrEmpty && iter[0] != separator)
                {
                    iter = iter + 1;
                }
                if (i == selected)
                {
                    break;
                }
                current_item = iter + 1;
            }

            if (ComboBeginText(ctx, current_item, size))
            {
                current_item = items_separated_by_separator;
                ctx.LayoutRowDynamic(item_height, 1);
                for (i = 0; i < count; ++i)
                {
                    iter = current_item;
                    while (!iter.IsNullOrEmpty && iter[0] != separator)
                    {
                        iter = iter + 1;
                    }
                    if (ComboItemText(ctx, current_item, nk_text_align.NK_TEXT_LEFT))
                    {
                        selected = i;
                    }
                    current_item = current_item + iter.Length + 1;
                }

                ComboEnd(ctx);
            }

            return(selected);
        }
Beispiel #3
0
        public static void nk_tooltip(this NuklearContext ctx, string text)
        {
            nk_style style;
            var      padding = new Vector2();
            float    text_width;
            float    text_height;

            if (ctx == null || ctx.current == null || ctx.current.Layout == null || text == null)
            {
                return;
            }
            style       = ctx.style;
            padding     = style.window.padding;
            text_width  = style.font.width(text);
            text_width += 4 * padding.X;
            text_height = style.font.Size + 2 * padding.Y;
            if (nk_tooltip_begin(ctx, text_width))
            {
                ctx.LayoutRowDynamic(text_height, 1);
                ctx.nk_text_(text, nk_text_align.NK_TEXT_LEFT);
                nk_tooltip_end(ctx);
            }
        }
Beispiel #4
0
        public static int nk_combo_callback(this NuklearContext ctx, NkComboCallback item_getter, int selected,
                                            int count, int item_height, Vector2 size)
        {
            int    i;
            int    max_height;
            var    item_spacing   = new Vector2();
            var    window_padding = new Vector2();
            string item;

            if (ctx == null || item_getter == null)
            {
                return(selected);
            }
            item_spacing   = ctx.style.window.spacing;
            window_padding = nk_panel_get_padding(ctx.style, ctx.current.Layout.Type);
            max_height     = count * item_height + count * (int)item_spacing.Y;
            max_height    += (int)item_spacing.Y * 2 + (int)window_padding.Y * 2;
            size.Y         = size.Y < (float)max_height ? size.Y : max_height;
            item_getter(selected, out item);
            if (ComboBeginLabel(ctx, item, size))
            {
                ctx.LayoutRowDynamic(item_height, 1);
                for (i = 0; i < count; ++i)
                {
                    item_getter(i, out item);
                    if (ComboItemLabel(ctx, item, nk_text_align.NK_TEXT_LEFT))
                    {
                        selected = i;
                    }
                }

                ComboEnd(ctx);
            }

            return(selected);
        }
Beispiel #5
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);
        }