Skip to content

Commit 1407308

Browse files
authored
Merge pull request Immediate-Mode-UI#142 from zgcrowno/master
Make nk_combo header symbols ("icon" etc.) optional.
2 parents ad8c1ca + 5a1bacb commit 1407308

File tree

4 files changed

+95
-27
lines changed

4 files changed

+95
-27
lines changed

nuklear.h

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28262,13 +28262,18 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len,
2826228262
struct nk_rect label;
2826328263
struct nk_rect button;
2826428264
struct nk_rect content;
28265+
int draw_button_symbol;
2826528266

2826628267
enum nk_symbol_type sym;
2826728268
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
2826828269
sym = style->combo.sym_hover;
2826928270
else if (is_clicked)
2827028271
sym = style->combo.sym_active;
28271-
else sym = style->combo.sym_normal;
28272+
else
28273+
sym = style->combo.sym_normal;
28274+
28275+
/* represents whether or not the combo's button symbol should be drawn */
28276+
draw_button_symbol = sym != NK_SYMBOL_NONE;
2827228277

2827328278
/* calculate button */
2827428279
button.w = header.h - 2 * style->combo.button_padding.y;
@@ -28285,14 +28290,18 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len,
2828528290
text.padding = nk_vec2(0,0);
2828628291
label.x = header.x + style->combo.content_padding.x;
2828728292
label.y = header.y + style->combo.content_padding.y;
28288-
label.w = button.x - (style->combo.content_padding.x + style->combo.spacing.x) - label.x;;
2828928293
label.h = header.h - 2 * style->combo.content_padding.y;
28294+
if (draw_button_symbol)
28295+
label.w = button.x - (style->combo.content_padding.x + style->combo.spacing.x) - label.x;
28296+
else
28297+
label.w = header.w - 2 * style->combo.content_padding.x;
2829028298
nk_widget_text(&win->buffer, label, selected, len, &text,
2829128299
NK_TEXT_LEFT, ctx->style.font);
2829228300

2829328301
/* draw open/close button */
28294-
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
28295-
&ctx->style.combo.button, sym, style->font);
28302+
if (draw_button_symbol)
28303+
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
28304+
&ctx->style.combo.button, sym, style->font);
2829628305
}
2829728306
return nk_combo_begin(ctx, win, size, is_clicked, header);
2829828307
}
@@ -28346,6 +28355,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve
2834628355
struct nk_rect content;
2834728356
struct nk_rect button;
2834828357
struct nk_rect bounds;
28358+
int draw_button_symbol;
2834928359

2835028360
enum nk_symbol_type sym;
2835128361
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
@@ -28354,6 +28364,9 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve
2835428364
sym = style->combo.sym_active;
2835528365
else sym = style->combo.sym_normal;
2835628366

28367+
/* represents whether or not the combo's button symbol should be drawn */
28368+
draw_button_symbol = sym != NK_SYMBOL_NONE;
28369+
2835728370
/* calculate button */
2835828371
button.w = header.h - 2 * style->combo.button_padding.y;
2835928372
button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
@@ -28369,12 +28382,16 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve
2836928382
bounds.h = header.h - 4 * style->combo.content_padding.y;
2837028383
bounds.y = header.y + 2 * style->combo.content_padding.y;
2837128384
bounds.x = header.x + 2 * style->combo.content_padding.x;
28372-
bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x;
28385+
if (draw_button_symbol)
28386+
bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x;
28387+
else
28388+
bounds.w = header.w - 4 * style->combo.content_padding.x;
2837328389
nk_fill_rect(&win->buffer, bounds, 0, color);
2837428390

2837528391
/* draw open/close button */
28376-
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
28377-
&ctx->style.combo.button, sym, style->font);
28392+
if (draw_button_symbol)
28393+
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
28394+
&ctx->style.combo.button, sym, style->font);
2837828395
}
2837928396
return nk_combo_begin(ctx, win, size, is_clicked, header);
2838028397
}
@@ -28606,6 +28623,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2
2860628623
struct nk_rect bounds = {0,0,0,0};
2860728624
struct nk_rect content;
2860828625
struct nk_rect button;
28626+
int draw_button_symbol;
2860928627

2861028628
enum nk_symbol_type sym;
2861128629
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
@@ -28614,6 +28632,9 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2
2861428632
sym = style->combo.sym_active;
2861528633
else sym = style->combo.sym_normal;
2861628634

28635+
/* represents whether or not the combo's button symbol should be drawn */
28636+
draw_button_symbol = sym != NK_SYMBOL_NONE;
28637+
2861728638
/* calculate button */
2861828639
button.w = header.h - 2 * style->combo.button_padding.y;
2861928640
button.x = (header.x + header.w - header.h) - style->combo.button_padding.y;
@@ -28629,12 +28650,16 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2
2862928650
bounds.h = header.h - 2 * style->combo.content_padding.y;
2863028651
bounds.y = header.y + style->combo.content_padding.y;
2863128652
bounds.x = header.x + style->combo.content_padding.x;
28632-
bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
28653+
if (draw_button_symbol)
28654+
bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
28655+
else
28656+
bounds.w = header.w - 2 * style->combo.content_padding.x;
2863328657
nk_draw_image(&win->buffer, bounds, &img, nk_white);
2863428658

2863528659
/* draw open/close button */
28636-
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
28637-
&ctx->style.combo.button, sym, style->font);
28660+
if (draw_button_symbol)
28661+
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
28662+
&ctx->style.combo.button, sym, style->font);
2863828663
}
2863928664
return nk_combo_begin(ctx, win, size, is_clicked, header);
2864028665
}
@@ -28691,6 +28716,7 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
2869128716
struct nk_rect button;
2869228717
struct nk_rect label;
2869328718
struct nk_rect image;
28719+
int draw_button_symbol;
2869428720

2869528721
enum nk_symbol_type sym;
2869628722
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
@@ -28699,6 +28725,9 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
2869928725
sym = style->combo.sym_active;
2870028726
else sym = style->combo.sym_normal;
2870128727

28728+
/* represents whether or not the combo's button symbol should be drawn */
28729+
draw_button_symbol = sym != NK_SYMBOL_NONE;
28730+
2870228731
/* calculate button */
2870328732
button.w = header.h - 2 * style->combo.button_padding.y;
2870428733
button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
@@ -28709,8 +28738,9 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
2870928738
content.y = button.y + style->combo.button.padding.y;
2871028739
content.w = button.w - 2 * style->combo.button.padding.x;
2871128740
content.h = button.h - 2 * style->combo.button.padding.y;
28712-
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
28713-
&ctx->style.combo.button, sym, style->font);
28741+
if (draw_button_symbol)
28742+
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
28743+
&ctx->style.combo.button, sym, style->font);
2871428744

2871528745
/* draw image */
2871628746
image.x = header.x + style->combo.content_padding.x;
@@ -28723,8 +28753,11 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
2872328753
text.padding = nk_vec2(0,0);
2872428754
label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x;
2872528755
label.y = header.y + style->combo.content_padding.y;
28726-
label.w = (button.x - style->combo.content_padding.x) - label.x;
2872728756
label.h = header.h - 2 * style->combo.content_padding.y;
28757+
if (draw_button_symbol)
28758+
label.w = (button.x - style->combo.content_padding.x) - label.x;
28759+
else
28760+
label.w = (header.x + header.w - style->combo.content_padding.x) - label.x;
2872828761
nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font);
2872928762
}
2873028763
return nk_combo_begin(ctx, win, size, is_clicked, header);
@@ -29097,6 +29130,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args)
2909729130
/// - [yy]: Minor version with non-breaking API and library changes
2909829131
/// - [zz]: Bug fix version with no direct changes to API
2909929132
///
29133+
/// - 2020/06/04 (4.03.0) - Made nk_combo header symbols optional.
2910029134
/// - 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget.
2910129135
/// - 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug
2910229136
/// - 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nuklear",
3-
"version": "4.02.5",
3+
"version": "4.03.0",
44
"repo": "Immediate-Mode-UI/Nuklear",
55
"description": "A small ANSI C gui toolkit",
66
"keywords": ["gl", "ui", "toolkit"],

src/CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/// - [yy]: Minor version with non-breaking API and library changes
99
/// - [zz]: Bug fix version with no direct changes to API
1010
///
11+
/// - 2020/06/04 (4.03.0) - Made nk_combo header symbols optional.
1112
/// - 2020/05/27 (4.02.5) - Fix nk_do_edit: Keep scroll position when re-activating edit widget.
1213
/// - 2020/05/09 (4.02.4) - Fix nk_menubar height calculation bug
1314
/// - 2020/05/08 (4.02.3) - Fix missing stdarg.h with NK_INCLUDE_STANDARD_VARARGS

src/nuklear_combo.c

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,18 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len,
9595
struct nk_rect label;
9696
struct nk_rect button;
9797
struct nk_rect content;
98+
int draw_button_symbol;
9899

99100
enum nk_symbol_type sym;
100101
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
101102
sym = style->combo.sym_hover;
102103
else if (is_clicked)
103104
sym = style->combo.sym_active;
104-
else sym = style->combo.sym_normal;
105+
else
106+
sym = style->combo.sym_normal;
107+
108+
/* represents whether or not the combo's button symbol should be drawn */
109+
draw_button_symbol = sym != NK_SYMBOL_NONE;
105110

106111
/* calculate button */
107112
button.w = header.h - 2 * style->combo.button_padding.y;
@@ -118,14 +123,18 @@ nk_combo_begin_text(struct nk_context *ctx, const char *selected, int len,
118123
text.padding = nk_vec2(0,0);
119124
label.x = header.x + style->combo.content_padding.x;
120125
label.y = header.y + style->combo.content_padding.y;
121-
label.w = button.x - (style->combo.content_padding.x + style->combo.spacing.x) - label.x;;
122126
label.h = header.h - 2 * style->combo.content_padding.y;
127+
if (draw_button_symbol)
128+
label.w = button.x - (style->combo.content_padding.x + style->combo.spacing.x) - label.x;
129+
else
130+
label.w = header.w - 2 * style->combo.content_padding.x;
123131
nk_widget_text(&win->buffer, label, selected, len, &text,
124132
NK_TEXT_LEFT, ctx->style.font);
125133

126134
/* draw open/close button */
127-
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
128-
&ctx->style.combo.button, sym, style->font);
135+
if (draw_button_symbol)
136+
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
137+
&ctx->style.combo.button, sym, style->font);
129138
}
130139
return nk_combo_begin(ctx, win, size, is_clicked, header);
131140
}
@@ -179,6 +188,7 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve
179188
struct nk_rect content;
180189
struct nk_rect button;
181190
struct nk_rect bounds;
191+
int draw_button_symbol;
182192

183193
enum nk_symbol_type sym;
184194
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
@@ -187,6 +197,9 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve
187197
sym = style->combo.sym_active;
188198
else sym = style->combo.sym_normal;
189199

200+
/* represents whether or not the combo's button symbol should be drawn */
201+
draw_button_symbol = sym != NK_SYMBOL_NONE;
202+
190203
/* calculate button */
191204
button.w = header.h - 2 * style->combo.button_padding.y;
192205
button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
@@ -202,12 +215,16 @@ nk_combo_begin_color(struct nk_context *ctx, struct nk_color color, struct nk_ve
202215
bounds.h = header.h - 4 * style->combo.content_padding.y;
203216
bounds.y = header.y + 2 * style->combo.content_padding.y;
204217
bounds.x = header.x + 2 * style->combo.content_padding.x;
205-
bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x;
218+
if (draw_button_symbol)
219+
bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x;
220+
else
221+
bounds.w = header.w - 4 * style->combo.content_padding.x;
206222
nk_fill_rect(&win->buffer, bounds, 0, color);
207223

208224
/* draw open/close button */
209-
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
210-
&ctx->style.combo.button, sym, style->font);
225+
if (draw_button_symbol)
226+
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
227+
&ctx->style.combo.button, sym, style->font);
211228
}
212229
return nk_combo_begin(ctx, win, size, is_clicked, header);
213230
}
@@ -439,6 +456,7 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2
439456
struct nk_rect bounds = {0,0,0,0};
440457
struct nk_rect content;
441458
struct nk_rect button;
459+
int draw_button_symbol;
442460

443461
enum nk_symbol_type sym;
444462
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
@@ -447,6 +465,9 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2
447465
sym = style->combo.sym_active;
448466
else sym = style->combo.sym_normal;
449467

468+
/* represents whether or not the combo's button symbol should be drawn */
469+
draw_button_symbol = sym != NK_SYMBOL_NONE;
470+
450471
/* calculate button */
451472
button.w = header.h - 2 * style->combo.button_padding.y;
452473
button.x = (header.x + header.w - header.h) - style->combo.button_padding.y;
@@ -462,12 +483,16 @@ nk_combo_begin_image(struct nk_context *ctx, struct nk_image img, struct nk_vec2
462483
bounds.h = header.h - 2 * style->combo.content_padding.y;
463484
bounds.y = header.y + style->combo.content_padding.y;
464485
bounds.x = header.x + style->combo.content_padding.x;
465-
bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
486+
if (draw_button_symbol)
487+
bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
488+
else
489+
bounds.w = header.w - 2 * style->combo.content_padding.x;
466490
nk_draw_image(&win->buffer, bounds, &img, nk_white);
467491

468492
/* draw open/close button */
469-
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
470-
&ctx->style.combo.button, sym, style->font);
493+
if (draw_button_symbol)
494+
nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
495+
&ctx->style.combo.button, sym, style->font);
471496
}
472497
return nk_combo_begin(ctx, win, size, is_clicked, header);
473498
}
@@ -524,6 +549,7 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
524549
struct nk_rect button;
525550
struct nk_rect label;
526551
struct nk_rect image;
552+
int draw_button_symbol;
527553

528554
enum nk_symbol_type sym;
529555
if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
@@ -532,6 +558,9 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
532558
sym = style->combo.sym_active;
533559
else sym = style->combo.sym_normal;
534560

561+
/* represents whether or not the combo's button symbol should be drawn */
562+
draw_button_symbol = sym != NK_SYMBOL_NONE;
563+
535564
/* calculate button */
536565
button.w = header.h - 2 * style->combo.button_padding.y;
537566
button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
@@ -542,8 +571,9 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
542571
content.y = button.y + style->combo.button.padding.y;
543572
content.w = button.w - 2 * style->combo.button.padding.x;
544573
content.h = button.h - 2 * style->combo.button.padding.y;
545-
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
546-
&ctx->style.combo.button, sym, style->font);
574+
if (draw_button_symbol)
575+
nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
576+
&ctx->style.combo.button, sym, style->font);
547577

548578
/* draw image */
549579
image.x = header.x + style->combo.content_padding.x;
@@ -556,8 +586,11 @@ nk_combo_begin_image_text(struct nk_context *ctx, const char *selected, int len,
556586
text.padding = nk_vec2(0,0);
557587
label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x;
558588
label.y = header.y + style->combo.content_padding.y;
559-
label.w = (button.x - style->combo.content_padding.x) - label.x;
560589
label.h = header.h - 2 * style->combo.content_padding.y;
590+
if (draw_button_symbol)
591+
label.w = (button.x - style->combo.content_padding.x) - label.x;
592+
else
593+
label.w = (header.x + header.w - style->combo.content_padding.x) - label.x;
561594
nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font);
562595
}
563596
return nk_combo_begin(ctx, win, size, is_clicked, header);

0 commit comments

Comments
 (0)