Beispiel #1
0
        public static void DrawOption(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_.nk_fill_circle(*selector, style.border_color);
                _out_.nk_fill_circle(RectangleF.nk_shrink_rect_(*selector, style.border),
                                     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_.nk_fill_circle(*cursors, 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 #2
0
        public static bool DoToggle(ref uint state, CommandBuffer _out_, RectangleF r, ref bool active, string str,
                                    int type, nk_style_toggle style, nk_input _in_, nk_font font)
        {
            bool was_active;
            var  bounds = new RectangleF();
            var  select = new RectangleF();
            var  cursor = new RectangleF();
            var  label  = new RectangleF();

            if (_out_ == null || style == null || font == null || active == null)
            {
                return(false);
            }
            r.Width       = r.Width < font.Size + 2 * style.padding.X ? font.Size + 2 * style.padding.X : r.Width;
            r.Height      = r.Height < font.Size + 2 * style.padding.Y ? font.Size + 2 * style.padding.Y : r.Height;
            bounds.X      = r.X - style.touch_padding.X;
            bounds.Y      = r.Y - style.touch_padding.Y;
            bounds.Width  = r.Width + 2 * style.touch_padding.X;
            bounds.Height = r.Height + 2 * style.touch_padding.Y;
            select.Width  = font.Size;
            select.Height = select.Width;
            select.Y      = r.Y + r.Height / 2.0f - select.Height / 2.0f;
            select.X      = r.X;
            cursor.X      = select.X + style.padding.X + style.border;
            cursor.Y      = select.Y + style.padding.Y + style.border;
            cursor.Width  = select.Width - (2 * style.padding.X + 2 * style.border);
            cursor.Height = select.Height - (2 * style.padding.Y + 2 * style.border);
            label.X       = select.X + select.Width + style.spacing;
            label.Y       = select.Y;
            label.Width   = (r.X + r.Width < label.X ? label.X : r.X + r.Width) - label.X;
            label.Height  = select.Width;
            was_active    = active;
            active        = ToggleBehavior(_in_, bounds, ref state, active);
            if (style.draw_begin != null)
            {
                style.draw_begin(_out_);
            }
            if (type == NK_TOGGLE_CHECK)
            {
                _out_.DrawCheckBox(state, style, active, &label, &select, &cursor, str, font);
            }
            else
            {
                _out_.DrawOption(state, style, active, &label, &select, &cursor, str, font);
            }

            if (style.draw_end != null)
            {
                style.draw_end(_out_);
            }
            return(was_active != active);
        }