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 {nk_flags flags = NK_WINDOW_NO_SCROLLBAR;
53 float known_h = (is_active) ? win->popup.
last_h : 0;
54 body = nk_fit_popup_rect(ctx, body, header, NK_POPUP_FIT_FLIP, known_h,
56 win->popup.
pinned_up = (body.y < header.y);
59 if (known_h > 0.0f && body.h + 0.5f < known_h)
61 if (!nk_nonblock_begin(ctx, flags, body,
62 (is_clicked && is_open)?
nk_rect(0,0,0,0):header, NK_PANEL_COMBO))
return 0;}
64 win->popup.type = NK_PANEL_COMBO;
65 win->popup.name = hash;
69nk_combo_begin_text(
struct nk_context *ctx,
const char *selected,
int len,
76 enum nk_widget_layout_states s;
77 int is_clicked = nk_false;
84 NK_ASSERT(ctx->current);
85 NK_ASSERT(ctx->current->layout);
86 if (!ctx || !ctx->current || !ctx->current->layout || !selected)
91 s = nk_widget(&header, ctx);
92 if (s == NK_WIDGET_INVALID)
95 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
96 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
100 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) {
101 background = &style->combo.active;
102 text.text = style->combo.label_active;
103 }
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) {
104 background = &style->combo.hover;
105 text.text = style->combo.label_hover;
107 background = &style->combo.normal;
108 text.text = style->combo.label_normal;
111 text.text = nk_rgb_factor(text.text, style->combo.color_factor);
113 switch(background->type) {
114 case NK_STYLE_ITEM_IMAGE:
115 text.background = nk_rgba(0, 0, 0, 0);
116 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
118 case NK_STYLE_ITEM_NINE_SLICE:
119 text.background = nk_rgba(0, 0, 0, 0);
120 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
122 case NK_STYLE_ITEM_COLOR:
123 text.background = background->data.color;
124 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
125 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
133 int draw_button_symbol;
135 enum nk_symbol_type sym;
136 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
137 sym = style->combo.sym_hover;
139 sym = style->combo.sym_active;
141 sym = style->combo.sym_normal;
144 draw_button_symbol = sym != NK_SYMBOL_NONE;
147 button.w = header.h - 2 * style->combo.button_padding.y;
148 button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
149 button.y = header.y + style->combo.button_padding.y;
152 content.x = button.x + style->combo.button.padding.x;
153 content.y = button.y + style->combo.button.padding.y;
154 content.w = button.w - 2 * style->combo.button.padding.x;
155 content.h = button.h - 2 * style->combo.button.padding.y;
159 label.x = header.x + style->combo.content_padding.x;
160 label.y = header.y + style->combo.content_padding.y;
161 label.h = header.h - 2 * style->combo.content_padding.y;
162 if (draw_button_symbol)
163 label.w = button.x - (style->combo.content_padding.x + style->combo.spacing.x) - label.x;
165 label.w = header.w - 2 * style->combo.content_padding.x;
166 nk_widget_text(&win->buffer, label, selected, len, &text,
167 NK_TEXT_LEFT, ctx->style.font);
170 if (draw_button_symbol)
171 nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
172 &ctx->style.combo.button, sym, style->font);
174 return nk_combo_begin(ctx, win, size, is_clicked, header);
177nk_combo_begin_label(
struct nk_context *ctx,
const char *selected,
struct nk_vec2 size)
179 return nk_combo_begin_text(ctx, selected, nk_strlen(selected), size);
189 int is_clicked = nk_false;
190 enum nk_widget_layout_states s;
194 NK_ASSERT(ctx->current);
195 NK_ASSERT(ctx->current->layout);
196 if (!ctx || !ctx->current || !ctx->current->layout)
201 s = nk_widget(&header, ctx);
202 if (s == NK_WIDGET_INVALID)
205 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
206 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
207 is_clicked = nk_true;
210 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED)
211 background = &style->combo.active;
212 else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
213 background = &style->combo.hover;
214 else background = &style->combo.normal;
216 switch(background->type) {
217 case NK_STYLE_ITEM_IMAGE:
218 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
220 case NK_STYLE_ITEM_NINE_SLICE:
221 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
223 case NK_STYLE_ITEM_COLOR:
224 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
225 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
232 int draw_button_symbol;
234 enum nk_symbol_type sym;
235 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
236 sym = style->combo.sym_hover;
238 sym = style->combo.sym_active;
239 else sym = style->combo.sym_normal;
242 draw_button_symbol = sym != NK_SYMBOL_NONE;
245 button.w = header.h - 2 * style->combo.button_padding.y;
246 button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
247 button.y = header.y + style->combo.button_padding.y;
250 content.x = button.x + style->combo.button.padding.x;
251 content.y = button.y + style->combo.button.padding.y;
252 content.w = button.w - 2 * style->combo.button.padding.x;
253 content.h = button.h - 2 * style->combo.button.padding.y;
256 bounds.h = header.h - 4 * style->combo.content_padding.y;
257 bounds.y = header.y + 2 * style->combo.content_padding.y;
258 bounds.x = header.x + 2 * style->combo.content_padding.x;
259 if (draw_button_symbol)
260 bounds.w = (button.x - (style->combo.content_padding.x + style->combo.spacing.x)) - bounds.x;
262 bounds.w = header.w - 4 * style->combo.content_padding.x;
263 nk_fill_rect(&win->buffer, bounds, 0, nk_rgb_factor(color, style->combo.color_factor));
266 if (draw_button_symbol)
267 nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
268 &ctx->style.combo.button, sym, style->font);
270 return nk_combo_begin(ctx, win, size, is_clicked, header);
273nk_combo_begin_symbol(
struct nk_context *ctx,
enum nk_symbol_type symbol,
struct nk_vec2 size)
280 int is_clicked = nk_false;
281 enum nk_widget_layout_states s;
287 NK_ASSERT(ctx->current);
288 NK_ASSERT(ctx->current->layout);
289 if (!ctx || !ctx->current || !ctx->current->layout)
294 s = nk_widget(&header, ctx);
295 if (s == NK_WIDGET_INVALID)
298 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
299 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
300 is_clicked = nk_true;
303 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) {
304 background = &style->combo.active;
305 symbol_color = style->combo.symbol_active;
306 }
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) {
307 background = &style->combo.hover;
308 symbol_color = style->combo.symbol_hover;
310 background = &style->combo.normal;
311 symbol_color = style->combo.symbol_hover;
314 symbol_color = nk_rgb_factor(symbol_color, style->combo.color_factor);
316 switch(background->type) {
317 case NK_STYLE_ITEM_IMAGE:
318 sym_background = nk_rgba(0, 0, 0, 0);
319 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
321 case NK_STYLE_ITEM_NINE_SLICE:
322 sym_background = nk_rgba(0, 0, 0, 0);
323 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
325 case NK_STYLE_ITEM_COLOR:
326 sym_background = background->data.color;
327 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
328 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
332 struct nk_rect bounds = {0,0,0,0};
336 enum nk_symbol_type sym;
337 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
338 sym = style->combo.sym_hover;
340 sym = style->combo.sym_active;
341 else sym = style->combo.sym_normal;
344 button.w = header.h - 2 * style->combo.button_padding.y;
345 button.x = (header.x + header.w - header.h) - style->combo.button_padding.y;
346 button.y = header.y + style->combo.button_padding.y;
349 content.x = button.x + style->combo.button.padding.x;
350 content.y = button.y + style->combo.button.padding.y;
351 content.w = button.w - 2 * style->combo.button.padding.x;
352 content.h = button.h - 2 * style->combo.button.padding.y;
355 bounds.h = header.h - 2 * style->combo.content_padding.y;
356 bounds.y = header.y + style->combo.content_padding.y;
357 bounds.x = header.x + style->combo.content_padding.x;
358 bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
359 nk_draw_symbol(&win->buffer, symbol, bounds, sym_background, symbol_color,
360 style->combo.border, style->font);
363 nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
364 &ctx->style.combo.button, sym, style->font);
366 return nk_combo_begin(ctx, win, size, is_clicked, header);
369nk_combo_begin_symbol_text(
struct nk_context *ctx,
const char *selected,
int len,
370 enum nk_symbol_type symbol,
struct nk_vec2 size)
377 int is_clicked = nk_false;
378 enum nk_widget_layout_states s;
384 NK_ASSERT(ctx->current);
385 NK_ASSERT(ctx->current->layout);
386 if (!ctx || !ctx->current || !ctx->current->layout)
391 s = nk_widget(&header, ctx);
394 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
395 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
396 is_clicked = nk_true;
399 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) {
400 background = &style->combo.active;
401 symbol_color = style->combo.symbol_active;
402 text.text = style->combo.label_active;
403 }
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) {
404 background = &style->combo.hover;
405 symbol_color = style->combo.symbol_hover;
406 text.text = style->combo.label_hover;
408 background = &style->combo.normal;
409 symbol_color = style->combo.symbol_normal;
410 text.text = style->combo.label_normal;
413 text.text = nk_rgb_factor(text.text, style->combo.color_factor);
414 symbol_color = nk_rgb_factor(symbol_color, style->combo.color_factor);
416 switch(background->type) {
417 case NK_STYLE_ITEM_IMAGE:
418 text.background = nk_rgba(0, 0, 0, 0);
419 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
421 case NK_STYLE_ITEM_NINE_SLICE:
422 text.background = nk_rgba(0, 0, 0, 0);
423 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
425 case NK_STYLE_ITEM_COLOR:
426 text.background = background->data.color;
427 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
428 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
437 enum nk_symbol_type sym;
438 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
439 sym = style->combo.sym_hover;
441 sym = style->combo.sym_active;
442 else sym = style->combo.sym_normal;
445 button.w = header.h - 2 * style->combo.button_padding.y;
446 button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
447 button.y = header.y + style->combo.button_padding.y;
450 content.x = button.x + style->combo.button.padding.x;
451 content.y = button.y + style->combo.button.padding.y;
452 content.w = button.w - 2 * style->combo.button.padding.x;
453 content.h = button.h - 2 * style->combo.button.padding.y;
454 nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
455 &ctx->style.combo.button, sym, style->font);
458 image.x = header.x + style->combo.content_padding.x;
459 image.y = header.y + style->combo.content_padding.y;
460 image.h = header.h - 2 * style->combo.content_padding.y;
462 nk_draw_symbol(&win->buffer, symbol, image, text.background, symbol_color,
463 style->combo.border, style->font);
467 label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x;
468 label.y = header.y + style->combo.content_padding.y;
469 label.w = (button.x - style->combo.content_padding.x) - label.x;
470 label.h = header.h - 2 * style->combo.content_padding.y;
471 nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font);
473 return nk_combo_begin(ctx, win, size, is_clicked, header);
483 int is_clicked = nk_false;
484 enum nk_widget_layout_states s;
488 NK_ASSERT(ctx->current);
489 NK_ASSERT(ctx->current->layout);
490 if (!ctx || !ctx->current || !ctx->current->layout)
495 s = nk_widget(&header, ctx);
496 if (s == NK_WIDGET_INVALID)
499 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
500 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
501 is_clicked = nk_true;
504 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED)
505 background = &style->combo.active;
506 else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
507 background = &style->combo.hover;
508 else background = &style->combo.normal;
510 switch (background->type) {
511 case NK_STYLE_ITEM_IMAGE:
512 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
514 case NK_STYLE_ITEM_NINE_SLICE:
515 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
517 case NK_STYLE_ITEM_COLOR:
518 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
519 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
523 struct nk_rect bounds = {0,0,0,0};
526 int draw_button_symbol;
528 enum nk_symbol_type sym;
529 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
530 sym = style->combo.sym_hover;
532 sym = style->combo.sym_active;
533 else sym = style->combo.sym_normal;
536 draw_button_symbol = sym != NK_SYMBOL_NONE;
539 button.w = header.h - 2 * style->combo.button_padding.y;
540 button.x = (header.x + header.w - header.h) - style->combo.button_padding.y;
541 button.y = header.y + style->combo.button_padding.y;
544 content.x = button.x + style->combo.button.padding.x;
545 content.y = button.y + style->combo.button.padding.y;
546 content.w = button.w - 2 * style->combo.button.padding.x;
547 content.h = button.h - 2 * style->combo.button.padding.y;
550 bounds.h = header.h - 2 * style->combo.content_padding.y;
551 bounds.y = header.y + style->combo.content_padding.y;
552 bounds.x = header.x + style->combo.content_padding.x;
553 if (draw_button_symbol)
554 bounds.w = (button.x - style->combo.content_padding.y) - bounds.x;
556 bounds.w = header.w - 2 * style->combo.content_padding.x;
557 nk_draw_image(&win->buffer, bounds, &img, nk_rgb_factor(nk_white, style->combo.color_factor));
560 if (draw_button_symbol)
561 nk_draw_button_symbol(&win->buffer, &bounds, &content, ctx->last_widget_state,
562 &ctx->style.combo.button, sym, style->font);
564 return nk_combo_begin(ctx, win, size, is_clicked, header);
567nk_combo_begin_image_text(
struct nk_context *ctx,
const char *selected,
int len,
575 int is_clicked = nk_false;
576 enum nk_widget_layout_states s;
581 NK_ASSERT(ctx->current);
582 NK_ASSERT(ctx->current->layout);
583 if (!ctx || !ctx->current || !ctx->current->layout)
588 s = nk_widget(&header, ctx);
591 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_DISABLED || s == NK_WIDGET_ROM)? 0: &ctx->input;
592 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
593 is_clicked = nk_true;
596 if (ctx->last_widget_state & NK_WIDGET_STATE_ACTIVED) {
597 background = &style->combo.active;
598 text.text = style->combo.label_active;
599 }
else if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER) {
600 background = &style->combo.hover;
601 text.text = style->combo.label_hover;
603 background = &style->combo.normal;
604 text.text = style->combo.label_normal;
607 text.text = nk_rgb_factor(text.text, style->combo.color_factor);
609 switch(background->type) {
610 case NK_STYLE_ITEM_IMAGE:
611 text.background = nk_rgba(0, 0, 0, 0);
612 nk_draw_image(&win->buffer, header, &background->data.image, nk_rgb_factor(nk_white, style->combo.color_factor));
614 case NK_STYLE_ITEM_NINE_SLICE:
615 text.background = nk_rgba(0, 0, 0, 0);
616 nk_draw_nine_slice(&win->buffer, header, &background->data.slice, nk_rgb_factor(nk_white, style->combo.color_factor));
618 case NK_STYLE_ITEM_COLOR:
619 text.background = background->data.color;
620 nk_fill_rect(&win->buffer, header, style->combo.rounding, nk_rgb_factor(background->data.color, style->combo.color_factor));
621 nk_stroke_rect(&win->buffer, header, style->combo.rounding, style->combo.border, nk_rgb_factor(style->combo.border_color, style->combo.color_factor));
629 int draw_button_symbol;
631 enum nk_symbol_type sym;
632 if (ctx->last_widget_state & NK_WIDGET_STATE_HOVER)
633 sym = style->combo.sym_hover;
635 sym = style->combo.sym_active;
636 else sym = style->combo.sym_normal;
639 draw_button_symbol = sym != NK_SYMBOL_NONE;
642 button.w = header.h - 2 * style->combo.button_padding.y;
643 button.x = (header.x + header.w - header.h) - style->combo.button_padding.x;
644 button.y = header.y + style->combo.button_padding.y;
647 content.x = button.x + style->combo.button.padding.x;
648 content.y = button.y + style->combo.button.padding.y;
649 content.w = button.w - 2 * style->combo.button.padding.x;
650 content.h = button.h - 2 * style->combo.button.padding.y;
651 if (draw_button_symbol)
652 nk_draw_button_symbol(&win->buffer, &button, &content, ctx->last_widget_state,
653 &ctx->style.combo.button, sym, style->font);
656 image.x = header.x + style->combo.content_padding.x;
657 image.y = header.y + style->combo.content_padding.y;
658 image.h = header.h - 2 * style->combo.content_padding.y;
660 nk_draw_image(&win->buffer, image, &img, nk_rgb_factor(nk_white, style->combo.color_factor));
664 label.x = image.x + image.w + style->combo.spacing.x + style->combo.content_padding.x;
665 label.y = header.y + style->combo.content_padding.y;
666 label.h = header.h - 2 * style->combo.content_padding.y;
667 if (draw_button_symbol)
668 label.w = (button.x - style->combo.content_padding.x) - label.x;
670 label.w = (header.x + header.w - style->combo.content_padding.x) - label.x;
671 nk_widget_text(&win->buffer, label, selected, len, &text, NK_TEXT_LEFT, style->font);
673 return nk_combo_begin(ctx, win, size, is_clicked, header);
676nk_combo_begin_symbol_label(
struct nk_context *ctx,
677 const char *selected,
enum nk_symbol_type type,
struct nk_vec2 size)
679 return nk_combo_begin_symbol_text(ctx, selected, nk_strlen(selected), type, size);
682nk_combo_begin_image_label(
struct nk_context *ctx,
685 return nk_combo_begin_image_text(ctx, selected, nk_strlen(selected), img, size);
688nk_combo_item_text(
struct nk_context *ctx,
const char *text,
int len,nk_flags align)
690 return nk_contextual_item_text(ctx, text, len, align);
693nk_combo_item_label(
struct nk_context *ctx,
const char *label, nk_flags align)
695 return nk_contextual_item_label(ctx, label, align);
698nk_combo_item_image_text(
struct nk_context *ctx,
struct nk_image img,
const char *text,
699 int len, nk_flags alignment)
701 return nk_contextual_item_image_text(ctx, img, text, len, alignment);
705 const char *text, nk_flags alignment)
707 return nk_contextual_item_image_label(ctx, img, text, alignment);
710nk_combo_item_symbol_text(
struct nk_context *ctx,
enum nk_symbol_type sym,
711 const char *text,
int len, nk_flags alignment)
713 return nk_contextual_item_symbol_text(ctx, sym, text, len, alignment);
716nk_combo_item_symbol_label(
struct nk_context *ctx,
enum nk_symbol_type sym,
717 const char *label, nk_flags alignment)
719 return nk_contextual_item_symbol_label(ctx, sym, label, alignment);
721NK_API
void nk_combo_end(
struct nk_context *ctx)
723 nk_contextual_end(ctx);
725NK_API
void nk_combo_close(
struct nk_context *ctx)
727 nk_contextual_close(ctx);
730nk_combo(
struct nk_context *ctx,
const char *
const *items,
int count,
731 int selected,
int item_height,
struct nk_vec2 size)
738 NK_ASSERT(ctx->current);
739 if (!ctx || !items ||!count)
742 max_height = nk_combo_calc_max_height(ctx, count, item_height);
743 size.y = NK_MIN(size.y, max_height);
744 if (nk_combo_begin_label(ctx, items[selected], size)) {
745 nk_layout_row_dynamic(ctx, (
float)item_height, 1);
746 for (i = 0; i < count; ++i) {
747 if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT))
755nk_combo_separator(
struct nk_context *ctx,
const char *items_separated_by_separator,
756 int separator,
int selected,
int count,
int item_height,
struct nk_vec2 size)
760 const char *current_item;
765 NK_ASSERT(items_separated_by_separator);
766 if (!ctx || !items_separated_by_separator)
769 max_height = nk_combo_calc_max_height(ctx, count, item_height);
770 size.y = NK_MIN(size.y, max_height);
773 current_item = items_separated_by_separator;
774 for (i = 0; i < count; ++i) {
776 while (*iter && *iter != separator) iter++;
777 length = (int)(iter - current_item);
778 if (i == selected)
break;
779 current_item = iter + 1;
782 if (nk_combo_begin_text(ctx, current_item, length, size)) {
783 current_item = items_separated_by_separator;
784 nk_layout_row_dynamic(ctx, (
float)item_height, 1);
785 for (i = 0; i < count; ++i) {
787 while (*iter && *iter != separator) iter++;
788 length = (int)(iter - current_item);
789 if (nk_combo_item_text(ctx, current_item, length, NK_TEXT_LEFT))
791 current_item = current_item + length + 1;
798nk_combo_string(
struct nk_context *ctx,
const char *items_separated_by_zeros,
799 int selected,
int count,
int item_height,
struct nk_vec2 size)
801 return nk_combo_separator(ctx, items_separated_by_zeros,
'\0', selected, count, item_height, size);
804nk_combo_callback(
struct nk_context *ctx,
void(*item_getter)(
void*,
int,
const char**),
805 void *userdata,
int selected,
int count,
int item_height,
struct nk_vec2 size)
812 NK_ASSERT(item_getter);
813 if (!ctx || !item_getter)
816 max_height = nk_combo_calc_max_height(ctx, count, item_height);
817 size.y = NK_MIN(size.y, max_height);
819 item_getter(userdata, selected, &item);
820 if (nk_combo_begin_label(ctx, item, size)) {
821 nk_layout_row_dynamic(ctx, (
float)item_height, 1);
822 for (i = 0; i < count; ++i) {
823 item_getter(userdata, i, &item);
824 if (nk_combo_item_label(ctx, item, NK_TEXT_LEFT))
831nk_combobox(
struct nk_context *ctx,
const char *
const *items,
int count,
832 int *selected,
int item_height,
struct nk_vec2 size)
835 *selected = nk_combo(ctx, items, count, *selected, item_height, size);
836 return tmp != *selected;
839nk_combobox_string(
struct nk_context *ctx,
const char *items_separated_by_zeros,
840 int *selected,
int count,
int item_height,
struct nk_vec2 size)
843 *selected = nk_combo_string(ctx, items_separated_by_zeros, *selected, count, item_height, size);
844 return tmp != *selected;
847nk_combobox_separator(
struct nk_context *ctx,
const char *items_separated_by_separator,
848 int separator,
int *selected,
int count,
int item_height,
struct nk_vec2 size)
851 *selected = nk_combo_separator(ctx, items_separated_by_separator, separator,
852 *selected, count, item_height, size);
853 return tmp != *selected;
857 void(*item_getter)(
void* data,
int id,
const char **out_text),
858 void *userdata,
int *selected,
int count,
int item_height,
struct nk_vec2 size)
861 *selected = nk_combo_callback(ctx, item_getter, userdata, *selected, count, item_height, size);
862 return tmp != *selected;