2#include "nuklear_internal.h" 
   16    case NK_SYMBOL_UNDERSCORE:
 
   18    case NK_SYMBOL_MINUS: {
 
   20        const char *X = (type == NK_SYMBOL_X) ? 
"x":
 
   21            (type == NK_SYMBOL_UNDERSCORE) ? 
"_":
 
   22            (type == NK_SYMBOL_PLUS) ? 
"+": 
"-";
 
   25        text.background = background;
 
   26        text.text = foreground;
 
   27        nk_widget_text(out, content, X, 1, &text, NK_TEXT_CENTERED, font);
 
   29    case NK_SYMBOL_CIRCLE_SOLID:
 
   30    case NK_SYMBOL_CIRCLE_OUTLINE:
 
   31    case NK_SYMBOL_RECT_SOLID:
 
   32    case NK_SYMBOL_RECT_OUTLINE: {
 
   34        if (type == NK_SYMBOL_RECT_SOLID || type == NK_SYMBOL_RECT_OUTLINE) {
 
   36            if (type == NK_SYMBOL_RECT_OUTLINE)
 
   37                nk_fill_rect(out, nk_shrink_rect(content, border_width), 0, background);
 
   39            nk_fill_circle(out, content, foreground);
 
   40            if (type == NK_SYMBOL_CIRCLE_OUTLINE)
 
   41                nk_fill_circle(out, nk_shrink_rect(content, 1), background);
 
   44    case NK_SYMBOL_TRIANGLE_UP:
 
   45    case NK_SYMBOL_TRIANGLE_DOWN:
 
   46    case NK_SYMBOL_TRIANGLE_LEFT:
 
   47    case NK_SYMBOL_TRIANGLE_RIGHT: {
 
   48        enum nk_heading heading;
 
   50        heading = (type == NK_SYMBOL_TRIANGLE_RIGHT) ? NK_RIGHT :
 
   51            (type == NK_SYMBOL_TRIANGLE_LEFT) ? NK_LEFT:
 
   52            (type == NK_SYMBOL_TRIANGLE_UP) ? NK_UP: NK_DOWN;
 
   53        nk_triangle_from_direction(points, content, 0, 0, heading);
 
   54        nk_fill_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y,
 
   55            points[2].x, points[2].y, foreground);
 
   57    case NK_SYMBOL_TRIANGLE_UP_OUTLINE:
 
   58    case NK_SYMBOL_TRIANGLE_DOWN_OUTLINE:
 
   59    case NK_SYMBOL_TRIANGLE_LEFT_OUTLINE:
 
   60    case NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE: {
 
   61        enum nk_heading heading;
 
   63        heading = (type == NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE) ? NK_RIGHT :
 
   64            (type == NK_SYMBOL_TRIANGLE_LEFT_OUTLINE) ? NK_LEFT:
 
   65            (type == NK_SYMBOL_TRIANGLE_UP_OUTLINE) ? NK_UP: NK_DOWN;
 
   66        nk_triangle_from_direction(points, content, 0, 0, heading);
 
   67        nk_stroke_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y,
 
   68            points[2].x, points[2].y, border_width, foreground);
 
   72    case NK_SYMBOL_MAX: 
break;
 
   76nk_button_behavior(nk_flags *state, 
struct nk_rect r,
 
   77    const struct nk_input *i, 
enum nk_button_behavior behavior)
 
   80    nk_widget_state_reset(state);
 
   82    if (nk_input_is_mouse_hovering_rect(i, r)) {
 
   84        if (nk_input_is_mouse_down(i, NK_BUTTON_LEFT))
 
   86        if (nk_input_has_mouse_click_in_button_rect(i, NK_BUTTON_LEFT, r)) {
 
   87            ret = (behavior != NK_BUTTON_DEFAULT) ?
 
   88                nk_input_is_mouse_down(i, NK_BUTTON_LEFT):
 
   89#ifdef NK_BUTTON_TRIGGER_ON_RELEASE 
   90                nk_input_is_mouse_released(i, NK_BUTTON_LEFT);
 
   92                nk_input_is_mouse_pressed(i, NK_BUTTON_LEFT);
 
   98    else if (nk_input_is_mouse_prev_hovering_rect(i, r))
 
  104    const struct nk_rect *bounds, nk_flags state,
 
  109        background = &style->hover;
 
  111        background = &style->active;
 
  112    else background = &style->normal;
 
  114    switch (background->type) {
 
  115        case NK_STYLE_ITEM_IMAGE:
 
  116            nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor_background));
 
  118        case NK_STYLE_ITEM_NINE_SLICE:
 
  119            nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor_background));
 
  121        case NK_STYLE_ITEM_COLOR:
 
  122            nk_fill_rect(out, *bounds, style->rounding, nk_rgb_factor(background->data.color, style->color_factor_background));
 
  123            nk_stroke_rect(out, *bounds, style->rounding, style->border, nk_rgb_factor(style->border_color, style->color_factor_background));
 
  131    enum nk_button_behavior behavior, 
struct nk_rect *content)
 
  141    content->x = r.x + style->padding.x + style->border + style->rounding;
 
  142    content->y = r.y + style->padding.y + style->border + style->rounding;
 
  143    content->w = r.w - (2 * (style->padding.x + style->border + style->rounding));
 
  144    content->h = r.h - (2 * (style->padding.y + style->border + style->rounding));
 
  147    bounds.x = r.x - style->touch_padding.x;
 
  148    bounds.y = r.y - style->touch_padding.y;
 
  149    bounds.w = r.w + 2 * style->touch_padding.x;
 
  150    bounds.h = r.h + 2 * style->touch_padding.y;
 
  151    return nk_button_behavior(state, bounds, in, behavior);
 
  155    const struct nk_rect *bounds, 
const struct nk_rect *content, nk_flags state,
 
  157    nk_flags text_alignment, 
const struct nk_user_font *font)
 
  161    background = nk_draw_button(out, bounds, state, style);
 
  164    if (background->type == NK_STYLE_ITEM_COLOR)
 
  165        text.background = background->data.color;
 
  166    else text.background = style->text_background;
 
  168        text.text = style->text_hover;
 
  170        text.text = style->text_active;
 
  171    else text.text = style->text_normal;
 
  173    text.text = nk_rgb_factor(text.text, style->color_factor_text);
 
  176    nk_widget_text(out, *content, txt, len, &text, text_alignment, font);
 
  179nk_do_button_text(nk_flags *state,
 
  181    const char *
string, 
int len, nk_flags align, 
enum nk_button_behavior behavior,
 
  193    if (!out || !style || !font || !
string)
 
  196    ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
 
  197    if (style->draw_begin) style->draw_begin(out, style->userdata);
 
  198    nk_draw_button_text(out, &bounds, &content, *state, style, 
string, len, align, font);
 
  199    if (style->draw_end) style->draw_end(out, style->userdata);
 
  206    enum nk_symbol_type type, 
const struct nk_user_font *font)
 
  212    background = nk_draw_button(out, bounds, state, style);
 
  213    if (background->type == NK_STYLE_ITEM_COLOR)
 
  214        bg = background->data.color;
 
  215    else bg = style->text_background;
 
  218        sym = style->text_hover;
 
  220        sym = style->text_active;
 
  221    else sym = style->text_normal;
 
  223    sym = nk_rgb_factor(sym, style->color_factor_text);
 
  224    nk_draw_symbol(out, type, *content, bg, sym, 1, font);
 
  227nk_do_button_symbol(nk_flags *state,
 
  229    enum nk_symbol_type symbol, 
enum nk_button_behavior behavior,
 
  240    if (!out || !style || !font || !state)
 
  243    ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
 
  244    if (style->draw_begin) style->draw_begin(out, style->userdata);
 
  245    nk_draw_button_symbol(out, &bounds, &content, *state, style, symbol, font);
 
  246    if (style->draw_end) style->draw_end(out, style->userdata);
 
  254    nk_draw_button(out, bounds, state, style);
 
  255    nk_draw_image(out, *content, img, nk_rgb_factor(nk_white, style->color_factor_background));
 
  258nk_do_button_image(nk_flags *state,
 
  260    struct nk_image img, 
enum nk_button_behavior b,
 
  269    if (!out || !style || !state)
 
  272    ret = nk_do_button(state, out, bounds, style, in, b, &content);
 
  273    content.x += style->image_padding.x;
 
  274    content.y += style->image_padding.y;
 
  275    content.w -= 2 * style->image_padding.x;
 
  276    content.h -= 2 * style->image_padding.y;
 
  278    if (style->draw_begin) style->draw_begin(out, style->userdata);
 
  279    nk_draw_button_image(out, &bounds, &content, *state, style, &img);
 
  280    if (style->draw_end) style->draw_end(out, style->userdata);
 
  287    const char *str, 
int len, 
enum nk_symbol_type type,
 
  295    background = nk_draw_button(out, bounds, state, style);
 
  296    if (background->type == NK_STYLE_ITEM_COLOR)
 
  297        text.background = background->data.color;
 
  298    else text.background = style->text_background;
 
  302        sym = style->text_hover;
 
  303        text.text = style->text_hover;
 
  305        sym = style->text_active;
 
  306        text.text = style->text_active;
 
  308        sym = style->text_normal;
 
  309        text.text = style->text_normal;
 
  312    sym = nk_rgb_factor(sym, style->color_factor_text);
 
  313    text.text = nk_rgb_factor(text.text, style->color_factor_text);
 
  315    nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font);
 
  316    nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font);
 
  319nk_do_button_text_symbol(nk_flags *state,
 
  321    enum nk_symbol_type symbol, 
const char *str, 
int len, nk_flags align,
 
  326    struct nk_rect tri = {0,0,0,0};
 
  332    if (!out || !style || !font)
 
  335    ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
 
  336    tri.y = content.y + (content.h/2) - font->
height/2;
 
  338    if (align & NK_TEXT_ALIGN_LEFT) {
 
  339        tri.x = (content.x + content.w) - (2 * style->padding.x + tri.w);
 
  340        tri.x = NK_MAX(tri.x, 0);
 
  341    } 
else tri.x = content.x + 2 * style->padding.x;
 
  344    if (style->draw_begin) style->draw_begin(out, style->userdata);
 
  345    nk_draw_button_text_symbol(out, &bounds, &content, &tri,
 
  346        *state, style, str, len, symbol, font);
 
  347    if (style->draw_end) style->draw_end(out, style->userdata);
 
  354    const char *str, 
int len, 
const struct nk_user_font *font,
 
  359    background = nk_draw_button(out, bounds, state, style);
 
  362    if (background->type == NK_STYLE_ITEM_COLOR)
 
  363        text.background = background->data.color;
 
  364    else text.background = style->text_background;
 
  366        text.text = style->text_hover;
 
  368        text.text = style->text_active;
 
  369    else text.text = style->text_normal;
 
  371    text.text = nk_rgb_factor(text.text, style->color_factor_text);
 
  373    nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font);
 
  374    nk_draw_image(out, *image, img, nk_rgb_factor(nk_white, style->color_factor_background));
 
  377nk_do_button_text_image(nk_flags *state,
 
  379    struct nk_image img, 
const char* str, 
int len, nk_flags align,
 
  391    if (!out || !font || !style || !str)
 
  394    ret = nk_do_button(state, out, bounds, style, in, behavior, &content);
 
  395    icon.y = bounds.y + style->padding.y;
 
  396    icon.w = icon.h = bounds.h - 2 * style->padding.y;
 
  397    if (align & NK_TEXT_ALIGN_LEFT) {
 
  398        icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w);
 
  399        icon.x = NK_MAX(icon.x, 0);
 
  400    } 
else icon.x = bounds.x + 2 * style->padding.x;
 
  402    icon.x += style->image_padding.x;
 
  403    icon.y += style->image_padding.y;
 
  404    icon.w -= 2 * style->image_padding.x;
 
  405    icon.h -= 2 * style->image_padding.y;
 
  407    if (style->draw_begin) style->draw_begin(out, style->userdata);
 
  408    nk_draw_button_text_image(out, &bounds, &content, &icon, *state, style, str, len, font, &img);
 
  409    if (style->draw_end) style->draw_end(out, style->userdata);
 
  413nk_button_set_behavior(
struct nk_context *ctx, 
enum nk_button_behavior behavior)
 
  417    ctx->button_behavior = behavior;
 
  420nk_button_push_behavior(
struct nk_context *ctx, 
enum nk_button_behavior behavior)
 
  422    struct nk_config_stack_button_behavior *button_stack;
 
  423    struct nk_config_stack_button_behavior_element *element;
 
  428    button_stack = &ctx->stacks.button_behaviors;
 
  429    NK_ASSERT(button_stack->head < (
int)NK_LEN(button_stack->elements));
 
  430    if (button_stack->head >= (
int)NK_LEN(button_stack->elements))
 
  433    element = &button_stack->elements[button_stack->head++];
 
  434    element->address = &ctx->button_behavior;
 
  435    element->old_value = ctx->button_behavior;
 
  436    ctx->button_behavior = behavior;
 
  442    struct nk_config_stack_button_behavior *button_stack;
 
  443    struct nk_config_stack_button_behavior_element *element;
 
  448    button_stack = &ctx->stacks.button_behaviors;
 
  449    NK_ASSERT(button_stack->head > 0);
 
  450    if (button_stack->head < 1)
 
  453    element = &button_stack->elements[--button_stack->head];
 
  454    *element->address = element->old_value;
 
  470    NK_ASSERT(ctx->current);
 
  471    NK_ASSERT(ctx->current->layout);
 
  472    if (!style || !ctx || !ctx->current || !ctx->current->layout) 
return 0;
 
  475    layout = win->layout;
 
  476    state = nk_widget(&bounds, ctx);
 
  478    if (!state) 
return 0;
 
  480    return nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds,
 
  481                    title, len, style->text_alignment, ctx->button_behavior,
 
  482                    style, in, ctx->style.font);
 
  485nk_button_text(
struct nk_context *ctx, 
const char *title, 
int len)
 
  489    return nk_button_text_styled(ctx, &ctx->style.button, title, len);
 
  491NK_API nk_bool nk_button_label_styled(
struct nk_context *ctx,
 
  494    return nk_button_text_styled(ctx, style, title, nk_strlen(title));
 
  496NK_API nk_bool nk_button_label(
struct nk_context *ctx, 
const char *title)
 
  498    return nk_button_text(ctx, title, nk_strlen(title));
 
  514    NK_ASSERT(ctx->current);
 
  515    NK_ASSERT(ctx->current->layout);
 
  516    if (!ctx || !ctx->current || !ctx->current->layout)
 
  520    layout = win->layout;
 
  522    state = nk_widget(&bounds, ctx);
 
  523    if (!state) 
return 0;
 
  526    button = ctx->style.button;
 
  527    button.normal = nk_style_item_color(color);
 
  528    button.hover = nk_style_item_color(color);
 
  529    button.active = nk_style_item_color(color);
 
  530    ret = nk_do_button(&ctx->last_widget_state, &win->buffer, bounds,
 
  531                &button, in, ctx->button_behavior, &content);
 
  532    nk_draw_button(&win->buffer, &bounds, ctx->last_widget_state, &button);
 
  536nk_button_symbol_styled(
struct nk_context *ctx,
 
  547    NK_ASSERT(ctx->current);
 
  548    NK_ASSERT(ctx->current->layout);
 
  549    if (!ctx || !ctx->current || !ctx->current->layout)
 
  553    layout = win->layout;
 
  554    state = nk_widget(&bounds, ctx);
 
  555    if (!state) 
return 0;
 
  557    return nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds,
 
  558            symbol, ctx->button_behavior, style, in, ctx->style.font);
 
  561nk_button_symbol(
struct nk_context *ctx, 
enum nk_symbol_type symbol)
 
  565    return nk_button_symbol_styled(ctx, &ctx->style.button, symbol);
 
  579    NK_ASSERT(ctx->current);
 
  580    NK_ASSERT(ctx->current->layout);
 
  581    if (!ctx || !ctx->current || !ctx->current->layout)
 
  585    layout = win->layout;
 
  587    state = nk_widget(&bounds, ctx);
 
  588    if (!state) 
return 0;
 
  590    return nk_do_button_image(&ctx->last_widget_state, &win->buffer, bounds,
 
  591                img, ctx->button_behavior, style, in);
 
  598    return nk_button_image_styled(ctx, &ctx->style.button, img);
 
  601nk_button_symbol_text_styled(
struct nk_context *ctx,
 
  603    const char *text, 
int len, nk_flags align)
 
  613    NK_ASSERT(ctx->current);
 
  614    NK_ASSERT(ctx->current->layout);
 
  615    if (!ctx || !ctx->current || !ctx->current->layout)
 
  619    layout = win->layout;
 
  621    state = nk_widget(&bounds, ctx);
 
  622    if (!state) 
return 0;
 
  624    return nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds,
 
  625                symbol, text, len, align, ctx->button_behavior,
 
  626                style, ctx->style.font, in);
 
  629nk_button_symbol_text(
struct nk_context *ctx, 
enum nk_symbol_type symbol,
 
  630    const char* text, 
int len, nk_flags align)
 
  634    return nk_button_symbol_text_styled(ctx, &ctx->style.button, symbol, text, len, align);
 
  636NK_API nk_bool nk_button_symbol_label(
struct nk_context *ctx, 
enum nk_symbol_type symbol,
 
  637    const char *label, nk_flags align)
 
  639    return nk_button_symbol_text(ctx, symbol, label, nk_strlen(label), align);
 
  641NK_API nk_bool nk_button_symbol_label_styled(
struct nk_context *ctx,
 
  643    const char *title, nk_flags align)
 
  645    return nk_button_symbol_text_styled(ctx, style, symbol, title, nk_strlen(title), align);
 
  648nk_button_image_text_styled(
struct nk_context *ctx,
 
  650    int len, nk_flags align)
 
  660    NK_ASSERT(ctx->current);
 
  661    NK_ASSERT(ctx->current->layout);
 
  662    if (!ctx || !ctx->current || !ctx->current->layout)
 
  666    layout = win->layout;
 
  668    state = nk_widget(&bounds, ctx);
 
  669    if (!state) 
return 0;
 
  671    return nk_do_button_text_image(&ctx->last_widget_state, &win->buffer,
 
  672            bounds, img, text, len, align, ctx->button_behavior,
 
  673            style, ctx->style.font, in);
 
  677    const char *text, 
int len, nk_flags align)
 
  679    return nk_button_image_text_styled(ctx, &ctx->style.button,img, text, len, align);
 
  682    const char *label, nk_flags align)
 
  684    return nk_button_image_text(ctx, img, label, nk_strlen(label), align);
 
  686NK_API nk_bool nk_button_image_label_styled(
struct nk_context *ctx,
 
  688    const char *label, nk_flags text_alignment)
 
  690    return nk_button_image_text_styled(ctx, style, img, label, nk_strlen(label), text_alignment);
 
main API and documentation file
 
@ NK_WINDOW_ROM
sets window widgets into a read only mode and does not allow input changes
 
NK_API void nk_draw_image(struct nk_command_buffer *, struct nk_rect, const struct nk_image *, struct nk_color)
misc
 
NK_API void nk_fill_rect(struct nk_command_buffer *, struct nk_rect, float rounding, struct nk_color)
filled shades
 
@ NK_WIDGET_STATE_LEFT
!< widget is currently activated
 
@ NK_WIDGET_STATE_ACTIVED
!< widget is being hovered
 
@ NK_WIDGET_STATE_ENTERED
!< widget is neither active nor hovered
 
@ NK_WIDGET_STATE_HOVER
!< widget has been hovered on the current frame
 
@ NK_WIDGET_STATE_ACTIVE
!< widget is being hovered
 
@ NK_WIDGET_STATE_HOVERED
!< widget is from this frame on not hovered anymore
 
@ NK_WIDGET_DISABLED
The widget is manually disabled and acts like NK_WIDGET_ROM.
 
@ NK_WIDGET_ROM
The widget is partially visible and cannot be updated.
 
float height
!< user provided font handle