2#include "nuklear_internal.h"
13nk_combo_calc_max_height(
const struct nk_context *ctx,
int count,
int item_height)
18 spacing = ctx->style.window.spacing;
19 padding = nk_panel_get_padding(&ctx->style, NK_PANEL_COMBO);
20 return (
float)count * (float)item_height
21 + (
float)count * spacing.y
23 + 2.0f * ctx->style.window.combo_border;
36 NK_ASSERT(ctx->current);
37 NK_ASSERT(ctx->current->layout);
38 if (!ctx || !ctx->current || !ctx->current->layout)
41 popup = win->popup.win;
44 body.y = header.y + header.h-ctx->style.window.combo_border;
47 hash = win->popup.combo_count++;
48 is_open = (popup) ? nk_true:nk_false;
49 is_active = (popup && (win->popup.name == hash) && win->popup.type == NK_PANEL_COMBO);
50 if ((is_clicked && is_open && !is_active) || (is_open && !is_active) ||
51 (!is_open && !is_active && !is_clicked))
return 0;
52 if (!nk_nonblock_begin(ctx, 0, body,
53 (is_clicked && is_open)?
nk_rect(0,0,0,0):header, NK_PANEL_COMBO)) return 0;
55 win->popup.type = NK_PANEL_COMBO;
56 win->popup.name = hash;
60nk_combo_begin_text(
struct nk_context *ctx,
const char *selected,
int len,
67 enum nk_widget_layout_states s;
68 int is_clicked = nk_false;
75 NK_ASSERT(ctx->current);
76 NK_ASSERT(ctx->current->layout);
77 if (!ctx || !ctx->current || !ctx->current->layout || !selected)
82 s = nk_widget(&header, ctx);
83 if (s == NK_WIDGET_INVALID)
86 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
87 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
91 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) {
92 background = &style->combo.active;
93 text.text = style->combo.label_active;
94 }
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) {
95 background = &style->combo.hover;
96 text.text = style->combo.label_hover;
98 background = &style->combo.normal;
99 text.text = style->combo.label_normal;
102 text.text = nk_rgb_factor(text.text, style->combo.color_factor);
104 switch(background->type) {
105 case NK_STYLE_ITEM_IMAGE:
106 text.background = nk_rgba(0, 0, 0, 0);
107 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
109 case NK_STYLE_ITEM_NINE_SLICE:
110 text.background = nk_rgba(0, 0, 0, 0);
111 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
113 case NK_STYLE_ITEM_COLOR:
114 text.background = background->data.color;
115 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
116 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
124 int draw_button_symbol;
126 enum nk_symbol_type sym;
127 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
128 sym = style->combo.sym_hover;
130 sym = style->combo.sym_active;
132 sym = style->combo.sym_normal;
135 draw_button_symbol = sym != NK_SYMBOL_NONE;
138 button.w = header.h - 2 * style->combo.button_padding.y;
139 button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
140 button.y = header.y + style->combo.button_padding.y;
143 content.x = button.x + style->combo.button.padding.x;
144 content.y = button.y + style->combo.button.padding.y;
145 content.w = button.w - 2 * style->combo.button.padding.x;
146 content.h = button.h - 2 * style->combo.button.padding.y;
150 label.x = header.x + style->combo.content_padding.x;
151 label.y = header.y + style->combo.content_padding.y;
152 label.h = header.h - 2 * style->combo.content_padding.y;
153 if (draw_button_symbol)
154 label.w = button.x - (style->combo.content_padding.x + style->combo.spacing.x) - label.x;
156 label.w = header.w - 2 * style->combo.content_padding.x;
157 nk_widget_text(&win->buffer, label, selected, len, &text,
158 NK_TEXT_LEFT, ctx->style.font);
161 if (draw_button_symbol)
162 nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
163 &ctx->style.combo.button, sym, style->font);
165 return nk_combo_begin(ctx, win, size, is_clicked, header);
168nk_combo_begin_label(
struct nk_context *ctx,
const char *selected,
struct nk_vec2 size)
170 return nk_combo_begin_text(ctx, selected, nk_strlen(selected), size);
180 int is_clicked = nk_false;
181 enum nk_widget_layout_states s;
185 NK_ASSERT(ctx->current);
186 NK_ASSERT(ctx->current->layout);
187 if (!ctx || !ctx->current || !ctx->current->layout)
192 s = nk_widget(&header, ctx);
193 if (s == NK_WIDGET_INVALID)
196 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
197 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
198 is_clicked = nk_true;
201 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED)
202 background = &style->combo.active;
203 else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
204 background = &style->combo.hover;
205 else background = &style->combo.normal;
207 switch(background->type) {
208 case NK_STYLE_ITEM_IMAGE:
209 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
211 case NK_STYLE_ITEM_NINE_SLICE:
212 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
214 case NK_STYLE_ITEM_COLOR:
215 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
216 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
223 int draw_button_symbol;
225 enum nk_symbol_type sym;
226 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
227 sym = style->combo.sym_hover;
229 sym = style->combo.sym_active;
230 else sym = style->combo.sym_normal;
233 draw_button_symbol = sym != NK_SYMBOL_NONE;
236 button.w = header.h - 2 * style->combo.button_padding.y;
237 button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
238 button.y = header.y + style->combo.button_padding.y;
241 content.x = button.x + style->combo.button.padding.x;
242 content.y = button.y + style->combo.button.padding.y;
243 content.w = button.w - 2 * style->combo.button.padding.x;
244 content.h = button.h - 2 * style->combo.button.padding.y;
247 bounds.h = header.h - 4 * style->combo.content_padding.y;
248 bounds.y = header.y + 2 * style->combo.content_padding.y;
249 bounds.x = header.x + 2 * style->combo.content_padding.x;
250 if (draw_button_symbol)
251 bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x;
253 bounds.w = header.w - 4 * style->combo.content_padding.x;
254 nk_fill_rect(&win->buffer, bounds, 0, nk_rgb_factor(color, style->combo.color_factor));
257 if (draw_button_symbol)
258 nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
259 &ctx->style.combo.button, sym, style->font);
261 return nk_combo_begin(ctx, win, size, is_clicked, header);
264nk_combo_begin_symbol(
struct nk_context *ctx,
enum nk_symbol_type symbol,
struct nk_vec2 size)
271 int is_clicked = nk_false;
272 enum nk_widget_layout_states s;
278 NK_ASSERT(ctx->current);
279 NK_ASSERT(ctx->current->layout);
280 if (!ctx || !ctx->current || !ctx->current->layout)
285 s = nk_widget(&header, ctx);
286 if (s == NK_WIDGET_INVALID)
289 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
290 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
291 is_clicked = nk_true;
294 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) {
295 background = &style->combo.active;
296 symbol_color = style->combo.symbol_active;
297 }
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) {
298 background = &style->combo.hover;
299 symbol_color = style->combo.symbol_hover;
301 background = &style->combo.normal;
302 symbol_color = style->combo.symbol_hover;
305 symbol_color = nk_rgb_factor(symbol_color, style->combo.color_factor);
307 switch(background->type) {
308 case NK_STYLE_ITEM_IMAGE:
309 sym_background = nk_rgba(0, 0, 0, 0);
310 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
312 case NK_STYLE_ITEM_NINE_SLICE:
313 sym_background = nk_rgba(0, 0, 0, 0);
314 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
316 case NK_STYLE_ITEM_COLOR:
317 sym_background = background->data.color;
318 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
319 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
323 struct nk_rect bounds = {0,0,0,0};
327 enum nk_symbol_type sym;
328 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
329 sym = style->combo.sym_hover;
331 sym = style->combo.sym_active;
332 else sym = style->combo.sym_normal;
335 button.w = header.h - 2 * style->combo.button_padding.y;
336 button.x = (header.x + header.w - header.h) - style->combo.button_padding.y;
337 button.y = header.y + style->combo.button_padding.y;
340 content.x = button.x + style->combo.button.padding.x;
341 content.y = button.y + style->combo.button.padding.y;
342 content.w = button.w - 2 * style->combo.button.padding.x;
343 content.h = button.h - 2 * style->combo.button.padding.y;
346 bounds.h = header.h - 2 * style->combo.content_padding.y;
347 bounds.y = header.y + style->combo.content_padding.y;
348 bounds.x = header.x + style->combo.content_padding.x;
349 bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
350 nk_draw_symbol(&win->buffer, symbol, bounds, sym_background, symbol_color,
351 style->combo.border, style->font);
354 nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
355 &ctx->style.combo.button, sym, style->font);
357 return nk_combo_begin(ctx, win, size, is_clicked, header);
360nk_combo_begin_symbol_text(
struct nk_context *ctx,
const char *selected,
int len,
361 enum nk_symbol_type symbol,
struct nk_vec2 size)
368 int is_clicked = nk_false;
369 enum nk_widget_layout_states s;
375 NK_ASSERT(ctx->current);
376 NK_ASSERT(ctx->current->layout);
377 if (!ctx || !ctx->current || !ctx->current->layout)
382 s = nk_widget(&header, ctx);
385 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
386 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
387 is_clicked = nk_true;
390 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) {
391 background = &style->combo.active;
392 symbol_color = style->combo.symbol_active;
393 text.text = style->combo.label_active;
394 }
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) {
395 background = &style->combo.hover;
396 symbol_color = style->combo.symbol_hover;
397 text.text = style->combo.label_hover;
399 background = &style->combo.normal;
400 symbol_color = style->combo.symbol_normal;
401 text.text = style->combo.label_normal;
404 text.text = nk_rgb_factor(text.text, style->combo.color_factor);
405 symbol_color = nk_rgb_factor(symbol_color, style->combo.color_factor);
407 switch(background->type) {
408 case NK_STYLE_ITEM_IMAGE:
409 text.background = nk_rgba(0, 0, 0, 0);
410 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
412 case NK_STYLE_ITEM_NINE_SLICE:
413 text.background = nk_rgba(0, 0, 0, 0);
414 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
416 case NK_STYLE_ITEM_COLOR:
417 text.background = background->data.color;
418 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
419 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
428 enum nk_symbol_type sym;
429 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
430 sym = style->combo.sym_hover;
432 sym = style->combo.sym_active;
433 else sym = style->combo.sym_normal;
436 button.w = header.h - 2 * style->combo.button_padding.y;
437 button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
438 button.y = header.y + style->combo.button_padding.y;
441 content.x = button.x + style->combo.button.padding.x;
442 content.y = button.y + style->combo.button.padding.y;
443 content.w = button.w - 2 * style->combo.button.padding.x;
444 content.h = button.h - 2 * style->combo.button.padding.y;
445 nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
446 &ctx->style.combo.button, sym, style->font);
449 image.x = header.x + style->combo.content_padding.x;
450 image.y = header.y + style->combo.content_padding.y;
451 image.h = header.h - 2 * style->combo.content_padding.y;
453 nk_draw_symbol(&win->buffer, symbol, image, text.background, symbol_color,
454 style->combo.border, style->font);
458 label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x;
459 label.y = header.y + style->combo.content_padding.y;
460 label.w = (button.x - style->combo.content_padding.x) - label.x;
461 label.h = header.h - 2 * style->combo.content_padding.y;
462 nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font);
464 return nk_combo_begin(ctx, win, size, is_clicked, header);
474 int is_clicked = nk_false;
475 enum nk_widget_layout_states s;
479 NK_ASSERT(ctx->current);
480 NK_ASSERT(ctx->current->layout);
481 if (!ctx || !ctx->current || !ctx->current->layout)
486 s = nk_widget(&header, ctx);
487 if (s == NK_WIDGET_INVALID)
490 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
491 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
492 is_clicked = nk_true;
495 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED)
496 background = &style->combo.active;
497 else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
498 background = &style->combo.hover;
499 else background = &style->combo.normal;
501 switch (background->type) {
502 case NK_STYLE_ITEM_IMAGE:
503 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
505 case NK_STYLE_ITEM_NINE_SLICE:
506 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
508 case NK_STYLE_ITEM_COLOR:
509 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
510 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
514 struct nk_rect bounds = {0,0,0,0};
517 int draw_button_symbol;
519 enum nk_symbol_type sym;
520 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
521 sym = style->combo.sym_hover;
523 sym = style->combo.sym_active;
524 else sym = style->combo.sym_normal;
527 draw_button_symbol = sym != NK_SYMBOL_NONE;
530 button.w = header.h - 2 * style->combo.button_padding.y;
531 button.x = (header.x + header.w - header.h) - style->combo.button_padding.y;
532 button.y = header.y + style->combo.button_padding.y;
535 content.x = button.x + style->combo.button.padding.x;
536 content.y = button.y + style->combo.button.padding.y;
537 content.w = button.w - 2 * style->combo.button.padding.x;
538 content.h = button.h - 2 * style->combo.button.padding.y;
541 bounds.h = header.h - 2 * style->combo.content_padding.y;
542 bounds.y = header.y + style->combo.content_padding.y;
543 bounds.x = header.x + style->combo.content_padding.x;
544 if (draw_button_symbol)
545 bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
547 bounds.w = header.w - 2 * style->combo.content_padding.x;
548 nk_draw_image(&win->buffer, bounds, &img, nk_rgb_factor(nk_white, style->combo.color_factor));
551 if (draw_button_symbol)
552 nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
553 &ctx->style.combo.button, sym, style->font);
555 return nk_combo_begin(ctx, win, size, is_clicked, header);
558nk_combo_begin_image_text(
struct nk_context *ctx,
const char *selected,
int len,
566 int is_clicked = nk_false;
567 enum nk_widget_layout_states s;
572 NK_ASSERT(ctx->current);
573 NK_ASSERT(ctx->current->layout);
574 if (!ctx || !ctx->current || !ctx->current->layout)
579 s = nk_widget(&header, ctx);
582 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
583 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
584 is_clicked = nk_true;
587 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) {
588 background = &style->combo.active;
589 text.text = style->combo.label_active;
590 }
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) {
591 background = &style->combo.hover;
592 text.text = style->combo.label_hover;
594 background = &style->combo.normal;
595 text.text = style->combo.label_normal;
598 text.text = nk_rgb_factor(text.text, style->combo.color_factor);
600 switch(background->type) {
601 case NK_STYLE_ITEM_IMAGE:
602 text.background = nk_rgba(0, 0, 0, 0);
603 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
605 case NK_STYLE_ITEM_NINE_SLICE:
606 text.background = nk_rgba(0, 0, 0, 0);
607 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
609 case NK_STYLE_ITEM_COLOR:
610 text.background = background->data.color;
611 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
612 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
620 int draw_button_symbol;
622 enum nk_symbol_type sym;
623 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
624 sym = style->combo.sym_hover;
626 sym = style->combo.sym_active;
627 else sym = style->combo.sym_normal;
630 draw_button_symbol = sym != NK_SYMBOL_NONE;
633 button.w = header.h - 2 * style->combo.button_padding.y;
634 button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
635 button.y = header.y + style->combo.button_padding.y;
638 content.x = button.x + style->combo.button.padding.x;
639 content.y = button.y + style->combo.button.padding.y;
640 content.w = button.w - 2 * style->combo.button.padding.x;
641 content.h = button.h - 2 * style->combo.button.padding.y;
642 if (draw_button_symbol)
643 nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
644 &ctx->style.combo.button, sym, style->font);
647 image.x = header.x + style->combo.content_padding.x;
648 image.y = header.y + style->combo.content_padding.y;
649 image.h = header.h - 2 * style->combo.content_padding.y;
651 nk_draw_image(&win->buffer, image, &img, nk_rgb_factor(nk_white, style->combo.color_factor));
655 label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x;
656 label.y = header.y + style->combo.content_padding.y;
657 label.h = header.h - 2 * style->combo.content_padding.y;
658 if (draw_button_symbol)
659 label.w = (button.x - style->combo.content_padding.x) - label.x;
661 label.w = (header.x + header.w - style->combo.content_padding.x) - label.x;
662 nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font);
664 return nk_combo_begin(ctx, win, size, is_clicked, header);
667nk_combo_begin_symbol_label(
struct nk_context *ctx,
668 const char *selected,
enum nk_symbol_type type,
struct nk_vec2 size)
670 return nk_combo_begin_symbol_text(ctx, selected, nk_strlen(selected), type, size);
673nk_combo_begin_image_label(
struct nk_context *ctx,
676 return nk_combo_begin_image_text(ctx, selected, nk_strlen(selected), img, size);
679nk_combo_item_text(
struct nk_context *ctx,
const char *text,
int len,nk_flags align)
681 return nk_contextual_item_text(ctx, text, len, align);
684nk_combo_item_label(
struct nk_context *ctx,
const char *label, nk_flags align)
686 return nk_contextual_item_label(ctx, label, align);
689nk_combo_item_image_text(
struct nk_context *ctx,
struct nk_image img,
const char *text,
690 int len, nk_flags alignment)
692 return nk_contextual_item_image_text(ctx, img, text, len, alignment);
696 const char *text, nk_flags alignment)
698 return nk_contextual_item_image_label(ctx, img, text, alignment);
701nk_combo_item_symbol_text(
struct nk_context *ctx,
enum nk_symbol_type sym,
702 const char *text,
int len, nk_flags alignment)
704 return nk_contextual_item_symbol_text(ctx, sym, text, len, alignment);
707nk_combo_item_symbol_label(
struct nk_context *ctx,
enum nk_symbol_type sym,
708 const char *label, nk_flags alignment)
710 return nk_contextual_item_symbol_label(ctx, sym, label, alignment);
712NK_API
void nk_combo_end(
struct nk_context *ctx)
714 nk_contextual_end(ctx);
716NK_API
void nk_combo_close(
struct nk_context *ctx)
718 nk_contextual_close(ctx);
721nk_combo(
struct nk_context *ctx,
const char *
const *items,
int count,
722 int selected,
int item_height,
struct nk_vec2 size)
729 NK_ASSERT(ctx->current);
730 if (!ctx || !items ||!count)
733 max_height = nk_combo_calc_max_height(ctx, count, item_height);
734 size.y = NK_MIN(size.y, max_height);
735 if (nk_combo_begin_label(ctx, items[selected], size)) {
736 nk_layout_row_dynamic(ctx, (
float)item_height, 1);
737 for (i = 0; i < count; ++i) {
738 if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
746nk_combo_separator(
struct nk_context *ctx,
const char *items_separated_by_separator,
747 int separator,
int selected,
int count,
int item_height,
struct nk_vec2 size)
751 const char *current_item;
756 NK_ASSERT(items_separated_by_separator);
757 if (!ctx || !items_separated_by_separator)
760 max_height = nk_combo_calc_max_height(ctx, count, item_height);
761 size.y = NK_MIN(size.y, max_height);
764 current_item = items_separated_by_separator;
765 for (i = 0; i < count; ++i) {
767 while (*iter && *iter != separator) iter++;
768 length = (int)(iter - current_item);
769 if (i == selected)
break;
770 current_item = iter + 1;
773 if (nk_combo_begin_text(ctx, current_item, length, size)) {
774 current_item = items_separated_by_separator;
775 nk_layout_row_dynamic(ctx, (
float)item_height, 1);
776 for (i = 0; i < count; ++i) {
778 while (*iter && *iter != separator) iter++;
779 length = (int)(iter - current_item);
780 if (nk_combo_item_text(ctx, current_item, length, NK_TEXT_LEFT))
782 current_item = current_item + length + 1;
789nk_combo_string(
struct nk_context *ctx,
const char *items_separated_by_zeros,
790 int selected,
int count,
int item_height,
struct nk_vec2 size)
792 return nk_combo_separator(ctx, items_separated_by_zeros,
'\0', selected, count, item_height, size);
795nk_combo_callback(
struct nk_context *ctx,
void(*item_getter)(
void*,
int,
const char**),
796 void *userdata,
int selected,
int count,
int item_height,
struct nk_vec2 size)
803 NK_ASSERT(item_getter);
804 if (!ctx || !item_getter)
807 max_height = nk_combo_calc_max_height(ctx, count, item_height);
808 size.y = NK_MIN(size.y, max_height);
810 item_getter(userdata, selected, &item);
811 if (nk_combo_begin_label(ctx, item, size)) {
812 nk_layout_row_dynamic(ctx, (
float)item_height, 1);
813 for (i = 0; i < count; ++i) {
814 item_getter(userdata, i, &item);
815 if (nk_combo_item_label(ctx, item, NK_TEXT_LEFT))
822nk_combobox(
struct nk_context *ctx,
const char *
const *items,
int count,
823 int *selected,
int item_height,
struct nk_vec2 size)
826 *selected = nk_combo(ctx, items, count, *selected, item_height, size);
827 return tmp != *selected;
830nk_combobox_string(
struct nk_context *ctx,
const char *items_separated_by_zeros,
831 int *selected,
int count,
int item_height,
struct nk_vec2 size)
834 *selected = nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height, size);
835 return tmp != *selected;
838nk_combobox_separator(
struct nk_context *ctx,
const char *items_separated_by_separator,
839 int separator,
int *selected,
int count,
int item_height,
struct nk_vec2 size)
842 *selected = nk_combo_separator(ctx, items_separated_by_separator, separator,
843 *selected, count, item_height, size);
844 return tmp != *selected;
848 void(*item_getter)(
void* data,
int id,
const char **out_text),
849 void *userdata,
int *selected,
int count,
int item_height,
struct nk_vec2 size)
852 *selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size);
853 return tmp != *selected;