Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions demo/common/overview.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,26 @@ overview(struct nk_context *ctx)

nk_layout_row_static(ctx, 25, 25, 8);
nk_button_symbol(ctx, NK_SYMBOL_CIRCLE_SOLID);
nk_button_symbol(ctx, NK_SYMBOL_CIRCLE_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_RECT_SOLID);
nk_button_symbol(ctx, NK_SYMBOL_CIRCLE_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_RECT_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_UP);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_UP_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_DOWN);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_DOWN_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_LEFT);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_LEFT_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_UP_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_DOWN_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_TRIANGLE_LEFT_OUTLINE);
nk_button_symbol(ctx, NK_SYMBOL_CHEVRON_UP);
nk_button_symbol(ctx, NK_SYMBOL_CHEVRON_RIGHT);
nk_button_symbol(ctx, NK_SYMBOL_CHEVRON_DOWN);
nk_button_symbol(ctx, NK_SYMBOL_CHEVRON_LEFT);
nk_button_symbol(ctx, NK_SYMBOL_HAMBURGER);
nk_button_symbol(ctx, NK_SYMBOL_X);
nk_button_symbol(ctx, NK_SYMBOL_UNDERSCORE);
nk_button_symbol(ctx, NK_SYMBOL_PLUS);
nk_button_symbol(ctx, NK_SYMBOL_MINUS);

nk_layout_row_static(ctx, 30, 100, 2);
nk_button_symbol_label(ctx, NK_SYMBOL_TRIANGLE_LEFT, "prev", NK_TEXT_RIGHT);
Expand Down
87 changes: 78 additions & 9 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,11 @@ enum nk_symbol_type {
NK_SYMBOL_TRIANGLE_DOWN_OUTLINE,
NK_SYMBOL_TRIANGLE_LEFT_OUTLINE,
NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE,
NK_SYMBOL_CHEVRON_UP,
NK_SYMBOL_CHEVRON_RIGHT,
NK_SYMBOL_CHEVRON_DOWN,
NK_SYMBOL_CHEVRON_LEFT,
NK_SYMBOL_HAMBURGER, /** Three horizontal lines. */
NK_SYMBOL_MAX
};
/* =============================================================================
Expand Down Expand Up @@ -24531,20 +24536,32 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
struct nk_rect content, struct nk_color background, struct nk_color foreground,
float border_width, const struct nk_user_font *font)
{
/* Use the border_width as the line thickness. */
if (border_width <= 0.0f) {
border_width = 1.0f;
}
switch (type) {
case NK_SYMBOL_X:
case NK_SYMBOL_X: {
float pad_x = content.w * 0.2f;
float pad_y = content.h * 0.2f;
float x0 = content.x + pad_x;
float y0 = content.y + pad_y;
float x1 = content.x + content.w - pad_x;
float y1 = content.y + content.h - pad_y;
nk_stroke_line(out, x0, y0, x1, y1, border_width, foreground);
nk_stroke_line(out, x1, y0, x0, y1, border_width, foreground);
} break;
case NK_SYMBOL_UNDERSCORE:
case NK_SYMBOL_PLUS:
case NK_SYMBOL_MINUS: {
/* single character text symbol */
const char *X = (type == NK_SYMBOL_X) ? "x":
(type == NK_SYMBOL_UNDERSCORE) ? "_":
const char *character = (type == NK_SYMBOL_UNDERSCORE) ? "_":
(type == NK_SYMBOL_PLUS) ? "+": "-";
struct nk_text text;
text.padding = nk_vec2(0,0);
text.background = background;
text.text = foreground;
nk_widget_text(out, content, X, 1, &text, NK_TEXT_CENTERED, font);
nk_widget_text(out, content, character, 1, &text, NK_TEXT_CENTERED, font);
} break;
case NK_SYMBOL_CIRCLE_SOLID:
case NK_SYMBOL_CIRCLE_OUTLINE:
Expand All @@ -24558,7 +24575,7 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
} else {
nk_fill_circle(out, content, foreground);
if (type == NK_SYMBOL_CIRCLE_OUTLINE)
nk_fill_circle(out, nk_shrink_rect(content, 1), background);
nk_fill_circle(out, nk_shrink_rect(content, border_width), background);
}
} break;
case NK_SYMBOL_TRIANGLE_UP:
Expand Down Expand Up @@ -24587,6 +24604,58 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
nk_stroke_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y,
points[2].x, points[2].y, border_width, foreground);
} break;
case NK_SYMBOL_CHEVRON_UP:
case NK_SYMBOL_CHEVRON_RIGHT:
case NK_SYMBOL_CHEVRON_DOWN:
case NK_SYMBOL_CHEVRON_LEFT: {
struct nk_vec2 points[3];
switch (type) {
case NK_SYMBOL_CHEVRON_RIGHT:
points[0].x = content.x;
points[0].y = content.y;
points[1].x = content.x + content.w;
points[1].y = content.y + content.h * 0.5f;
points[2].x = content.x;
points[2].y = content.y + content.h;
break;
case NK_SYMBOL_CHEVRON_LEFT:
points[0].x = content.x + content.w;
points[0].y = content.y;
points[1].x = content.x;
points[1].y = content.y + content.h * 0.5f;
points[2].x = content.x + content.w;
points[2].y = content.y + content.h;
break;
case NK_SYMBOL_CHEVRON_UP:
points[0].x = content.x;
points[0].y = content.y + content.h;
points[1].x = content.x + content.w * 0.5f;
points[1].y = content.y;
points[2].x = content.x + content.w;
points[2].y = content.y + content.h;
break;
case NK_SYMBOL_CHEVRON_DOWN:
points[0].x = content.x;
points[0].y = content.y;
points[1].x = content.x + content.w * 0.5f;
points[1].y = content.y + content.h;
points[2].x = content.x + content.w;
points[2].y = content.y;
break;
default:
break;
}
nk_stroke_line(out, points[0].x, points[0].y, points[1].x, points[1].y, border_width, foreground);
nk_stroke_line(out, points[1].x, points[1].y, points[2].x, points[2].y, border_width, foreground);
} break;
case NK_SYMBOL_HAMBURGER: {
float y2 = content.y + content.h * 0.5f;
float y3 = content.y + content.h - border_width;
float x1 = content.x + content.w;
nk_stroke_line(out, content.x, content.y, x1, content.y, border_width, foreground);
nk_stroke_line(out, content.x, y2, x1, y2, border_width, foreground);
nk_stroke_line(out, content.x, y3, x1, y3, border_width, foreground);
} break;
default:
case NK_SYMBOL_NONE:
case NK_SYMBOL_MAX: break;
Expand Down Expand Up @@ -24741,7 +24810,7 @@ nk_draw_button_symbol(struct nk_command_buffer *out,
else sym = style->text_normal;

sym = nk_rgb_factor(sym, style->color_factor_text);
nk_draw_symbol(out, type, *content, bg, sym, 1, font);
nk_draw_symbol(out, type, *content, bg, sym, style->border, font);
}
NK_LIB nk_bool
nk_do_button_symbol(nk_flags *state,
Expand Down Expand Up @@ -24832,7 +24901,7 @@ nk_draw_button_text_symbol(struct nk_command_buffer *out,
sym = nk_rgb_factor(sym, style->color_factor_text);
text.text = nk_rgb_factor(text.text, style->color_factor_text);
text.padding = nk_vec2(0,0);
nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font);
nk_draw_symbol(out, type, *symbol, style->text_background, sym, style->border, font);
nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font);
}
NK_LIB nk_bool
Expand Down Expand Up @@ -30254,7 +30323,7 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct
bounds.x = header.x + style->combo.content_padding.x;
bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
nk_draw_symbol(&win->buffer, symbol, bounds, sym_background, symbol_color,
1.0f, style->font);
style->combo.border, style->font);

/* draw open/close button */
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
Expand Down Expand Up @@ -30357,7 +30426,7 @@ nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len
image.h = header.h - 2 * style->combo.content_padding.y;
image.w = image.h;
nk_draw_symbol(&win->buffer, symbol, image, text.background, symbol_color,
1.0f, style->font);
style->combo.border, style->font);

/* draw label */
text.padding = nk_vec2(0,0);
Expand Down
5 changes: 5 additions & 0 deletions src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ enum nk_symbol_type {
NK_SYMBOL_TRIANGLE_DOWN_OUTLINE,
NK_SYMBOL_TRIANGLE_LEFT_OUTLINE,
NK_SYMBOL_TRIANGLE_RIGHT_OUTLINE,
NK_SYMBOL_CHEVRON_UP,
NK_SYMBOL_CHEVRON_RIGHT,
NK_SYMBOL_CHEVRON_DOWN,
NK_SYMBOL_CHEVRON_LEFT,
NK_SYMBOL_HAMBURGER, /** Three horizontal lines. */
NK_SYMBOL_MAX
};
/* =============================================================================
Expand Down
78 changes: 71 additions & 7 deletions src/nuklear_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,32 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
struct nk_rect content, struct nk_color background, struct nk_color foreground,
float border_width, const struct nk_user_font *font)
{
/* Use the border_width as the line thickness. */
if (border_width <= 0.0f) {
border_width = 1.0f;
}
switch (type) {
case NK_SYMBOL_X:
case NK_SYMBOL_X: {
float pad_x = content.w * 0.2f;
float pad_y = content.h * 0.2f;
float x0 = content.x + pad_x;
float y0 = content.y + pad_y;
float x1 = content.x + content.w - pad_x;
float y1 = content.y + content.h - pad_y;
nk_stroke_line(out, x0, y0, x1, y1, border_width, foreground);
nk_stroke_line(out, x1, y0, x0, y1, border_width, foreground);
} break;
case NK_SYMBOL_UNDERSCORE:
case NK_SYMBOL_PLUS:
case NK_SYMBOL_MINUS: {
/* single character text symbol */
const char *X = (type == NK_SYMBOL_X) ? "x":
(type == NK_SYMBOL_UNDERSCORE) ? "_":
const char *character = (type == NK_SYMBOL_UNDERSCORE) ? "_":
(type == NK_SYMBOL_PLUS) ? "+": "-";
struct nk_text text;
text.padding = nk_vec2(0,0);
text.background = background;
text.text = foreground;
nk_widget_text(out, content, X, 1, &text, NK_TEXT_CENTERED, font);
nk_widget_text(out, content, character, 1, &text, NK_TEXT_CENTERED, font);
} break;
case NK_SYMBOL_CIRCLE_SOLID:
case NK_SYMBOL_CIRCLE_OUTLINE:
Expand All @@ -38,7 +50,7 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
} else {
nk_fill_circle(out, content, foreground);
if (type == NK_SYMBOL_CIRCLE_OUTLINE)
nk_fill_circle(out, nk_shrink_rect(content, 1), background);
nk_fill_circle(out, nk_shrink_rect(content, border_width), background);
}
} break;
case NK_SYMBOL_TRIANGLE_UP:
Expand Down Expand Up @@ -67,6 +79,58 @@ nk_draw_symbol(struct nk_command_buffer *out, enum nk_symbol_type type,
nk_stroke_triangle(out, points[0].x, points[0].y, points[1].x, points[1].y,
points[2].x, points[2].y, border_width, foreground);
} break;
case NK_SYMBOL_CHEVRON_UP:
case NK_SYMBOL_CHEVRON_RIGHT:
case NK_SYMBOL_CHEVRON_DOWN:
case NK_SYMBOL_CHEVRON_LEFT: {
struct nk_vec2 points[3];
switch (type) {
case NK_SYMBOL_CHEVRON_RIGHT:
points[0].x = content.x;
points[0].y = content.y;
points[1].x = content.x + content.w;
points[1].y = content.y + content.h * 0.5f;
points[2].x = content.x;
points[2].y = content.y + content.h;
break;
case NK_SYMBOL_CHEVRON_LEFT:
points[0].x = content.x + content.w;
points[0].y = content.y;
points[1].x = content.x;
points[1].y = content.y + content.h * 0.5f;
points[2].x = content.x + content.w;
points[2].y = content.y + content.h;
break;
case NK_SYMBOL_CHEVRON_UP:
points[0].x = content.x;
points[0].y = content.y + content.h;
points[1].x = content.x + content.w * 0.5f;
points[1].y = content.y;
points[2].x = content.x + content.w;
points[2].y = content.y + content.h;
break;
case NK_SYMBOL_CHEVRON_DOWN:
points[0].x = content.x;
points[0].y = content.y;
points[1].x = content.x + content.w * 0.5f;
points[1].y = content.y + content.h;
points[2].x = content.x + content.w;
points[2].y = content.y;
break;
default:
break;
}
nk_stroke_line(out, points[0].x, points[0].y, points[1].x, points[1].y, border_width, foreground);
nk_stroke_line(out, points[1].x, points[1].y, points[2].x, points[2].y, border_width, foreground);
} break;
case NK_SYMBOL_HAMBURGER: {
float y2 = content.y + content.h * 0.5f;
float y3 = content.y + content.h - border_width;
float x1 = content.x + content.w;
nk_stroke_line(out, content.x, content.y, x1, content.y, border_width, foreground);
nk_stroke_line(out, content.x, y2, x1, y2, border_width, foreground);
nk_stroke_line(out, content.x, y3, x1, y3, border_width, foreground);
} break;
default:
case NK_SYMBOL_NONE:
case NK_SYMBOL_MAX: break;
Expand Down Expand Up @@ -221,7 +285,7 @@ nk_draw_button_symbol(struct nk_command_buffer *out,
else sym = style->text_normal;

sym = nk_rgb_factor(sym, style->color_factor_text);
nk_draw_symbol(out, type, *content, bg, sym, 1, font);
nk_draw_symbol(out, type, *content, bg, sym, style->border, font);
}
NK_LIB nk_bool
nk_do_button_symbol(nk_flags *state,
Expand Down Expand Up @@ -312,7 +376,7 @@ nk_draw_button_text_symbol(struct nk_command_buffer *out,
sym = nk_rgb_factor(sym, style->color_factor_text);
text.text = nk_rgb_factor(text.text, style->color_factor_text);
text.padding = nk_vec2(0,0);
nk_draw_symbol(out, type, *symbol, style->text_background, sym, 0, font);
nk_draw_symbol(out, type, *symbol, style->text_background, sym, style->border, font);
nk_widget_text(out, *label, str, len, &text, NK_TEXT_CENTERED, font);
}
NK_LIB nk_bool
Expand Down
4 changes: 2 additions & 2 deletions src/nuklear_combo.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ nk_combo_begin_symbol(struct nk_context *ctx, enum nk_symbol_type symbol, struct
bounds.x = header.x + style->combo.content_padding.x;
bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
nk_draw_symbol(&win->buffer, symbol, bounds, sym_background, symbol_color,
1.0f, style->font);
style->combo.border, style->font);

/* draw open/close button */
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
Expand Down Expand Up @@ -435,7 +435,7 @@ nk_combo_begin_symbol_text(struct nk_context *ctx, const char *selected, int len
image.h = header.h - 2 * style->combo.content_padding.y;
image.w = image.h;
nk_draw_symbol(&win->buffer, symbol, image, text.background, symbol_color,
1.0f, style->font);
style->combo.border, style->font);

/* draw label */
text.padding = nk_vec2(0,0);
Expand Down
Loading