Ejemplo n.º 1
0
        public static bool nk_do_selectable(ref uint state, CommandBuffer _out_, RectangleF bounds, string str,
                                            nk_text_align align, ref bool value, nk_style_selectable style, nk_input _in_, nk_font font)
        {
            bool old_value;
            var  touch = new RectangleF();

            if (_out_ == null || str == null || style == null ||
                font == null)
            {
                return(false);
            }
            old_value    = value;
            touch.X      = bounds.X - style.touch_padding.X;
            touch.Y      = bounds.Y - style.touch_padding.Y;
            touch.Width  = bounds.Width + style.touch_padding.X * 2;
            touch.Height = bounds.Height + style.touch_padding.Y * 2;
            if (ButtonBehavior(ref state, touch, _in_, NK_BUTTON_DEFAULT))
            {
                value = !value;
            }
            if (style.draw_begin != null)
            {
                style.draw_begin(_out_);
            }
            _out_.DrawSelectable(state, style, value, &bounds, null, null, str, align,
                                 font);
            if (style.draw_end != null)
            {
                style.draw_end(_out_);
            }
            return(old_value != value);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static bool nk_do_selectable_image(ref uint state, CommandBuffer _out_, RectangleF bounds,
                                                  string str,
                                                  nk_text_align align, ref bool value, nk_image img, nk_style_selectable style, nk_input _in_,
                                                  nk_font font)
        {
            bool old_value;
            var  touch = new RectangleF();
            var  icon  = new RectangleF();

            if (_out_ == null || str == null || style == null ||
                font == null)
            {
                return(false);
            }
            old_value    = value;
            touch.X      = bounds.X - style.touch_padding.X;
            touch.Y      = bounds.Y - style.touch_padding.Y;
            touch.Width  = bounds.Width + style.touch_padding.X * 2;
            touch.Height = bounds.Height + style.touch_padding.Y * 2;
            if (ButtonBehavior(ref state, touch, _in_, NK_BUTTON_DEFAULT))
            {
                value = !value;
            }
            icon.Y     = bounds.Y + style.padding.Y;
            icon.Width = icon.Height = bounds.Height - 2 * style.padding.Y;
            if ((align & nk_text_align.NK_TEXT_ALIGN_LEFT) != 0)
            {
                icon.X = bounds.X + bounds.Width - (2 * style.padding.X + icon.Width);
                icon.X = icon.X < 0 ? 0 : icon.X;
            }
            else
            {
                icon.X = bounds.X + 2 * style.padding.X;
            }

            icon.X      += style.image_padding.X;
            icon.Y      += style.image_padding.Y;
            icon.Width  -= 2 * style.image_padding.X;
            icon.Height -= 2 * style.image_padding.Y;
            if (style.draw_begin != null)
            {
                style.draw_begin(_out_);
            }
            _out_.DrawSelectable(state, style, value, &bounds, &icon, img, str, align,
                                 font);
            if (style.draw_end != null)
            {
                style.draw_end(_out_);
            }
            return(old_value != value);
        }