2#include "nuklear_internal.h"
11 nk_flags *state, nk_bool active)
13 nk_widget_state_reset(state);
14 if (nk_button_behavior(state, select, in, NK_BUTTON_DEFAULT)) {
20 else if (nk_input_is_mouse_prev_hovering_rect(in, select))
28 const struct nk_rect *cursors,
const char *
string,
int len,
29 const struct nk_user_font *font, nk_flags text_alignment)
37 background = &style->hover;
38 cursor = &style->cursor_hover;
39 text.text = style->text_hover;
41 background = &style->hover;
42 cursor = &style->cursor_hover;
43 text.text = style->text_active;
45 background = &style->normal;
46 cursor = &style->cursor_normal;
47 text.text = style->text_normal;
50 text.text = nk_rgb_factor(text.text, style->color_factor);
53 text.background = style->text_background;
54 nk_widget_text(out, *label,
string, len, &text, text_alignment, font);
57 if (background->type == NK_STYLE_ITEM_COLOR) {
58 nk_fill_rect(out, *selector, 0, nk_rgb_factor(style->border_color, style->color_factor));
59 nk_fill_rect(out, nk_shrink_rect(*selector, style->border), 0, nk_rgb_factor(background->data.color, style->color_factor));
60 }
else nk_draw_image(out, *selector, &background->data.image, nk_rgb_factor(nk_white, style->color_factor));
62 if (cursor->type == NK_STYLE_ITEM_IMAGE)
63 nk_draw_image(out, *cursors, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor));
71 const struct nk_rect *cursors,
const char *
string,
int len,
72 const struct nk_user_font *font, nk_flags text_alignment)
80 background = &style->hover;
81 cursor = &style->cursor_hover;
82 text.text = style->text_hover;
84 background = &style->hover;
85 cursor = &style->cursor_hover;
86 text.text = style->text_active;
88 background = &style->normal;
89 cursor = &style->cursor_normal;
90 text.text = style->text_normal;
93 text.text = nk_rgb_factor(text.text, style->color_factor);
96 text.background = style->text_background;
97 nk_widget_text(out, *label,
string, len, &text, text_alignment, font);
100 if (background->type == NK_STYLE_ITEM_COLOR) {
101 nk_fill_circle(out, *selector, nk_rgb_factor(style->border_color, style->color_factor));
102 nk_fill_circle(out, nk_shrink_rect(*selector, style->border), nk_rgb_factor(background->data.color, style->color_factor));
103 }
else nk_draw_image(out, *selector, &background->data.image, nk_rgb_factor(nk_white, style->color_factor));
105 if (cursor->type == NK_STYLE_ITEM_IMAGE)
106 nk_draw_image(out, *cursors, &cursor->data.image, nk_rgb_factor(nk_white, style->color_factor));
107 else nk_fill_circle(out, *cursors, cursor->data.color);
111nk_do_toggle(nk_flags *state,
113 nk_bool *active,
const char *str,
int len,
enum nk_toggle_type type,
115 const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment)
126 if (!out || !style || !font || !active)
129 r.w = NK_MAX(r.w, font->
height + 2 * style->padding.x);
130 r.h = NK_MAX(r.h, font->
height + 2 * style->padding.y);
133 bounds.x = r.x - style->touch_padding.x;
134 bounds.y = r.y - style->touch_padding.y;
135 bounds.w = r.w + 2 * style->touch_padding.x;
136 bounds.h = r.h + 2 * style->touch_padding.y;
142 if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) {
143 select.x = r.x + r.w - font->
height;
147 label.w = r.w - select.w - style->spacing * 2;
148 }
else if (widget_alignment & NK_WIDGET_ALIGN_CENTERED) {
149 select.x = r.x + (r.w - select.w) / 2;
153 label.w = (r.w - select.w - style->spacing * 2) / 2;
158 label.x = select.x + select.w + style->spacing;
159 label.w = NK_MAX(r.x + r.w, label.x) - label.x;
162 if (widget_alignment & NK_WIDGET_ALIGN_TOP) {
164 }
else if (widget_alignment & NK_WIDGET_ALIGN_BOTTOM) {
165 select.y = r.y + r.h - select.h - 2 * style->padding.y;
167 select.y = r.y + r.h/2.0f - select.h/2.0f;
174 cursor.x = select.x + style->padding.x + style->border;
175 cursor.y = select.y + style->padding.y + style->border;
176 cursor.w = select.w - (2 * style->padding.x + 2 * style->border);
177 cursor.h = select.h - (2 * style->padding.y + 2 * style->border);
180 was_active = *active;
181 *active = nk_toggle_behavior(in, bounds, state, *active);
184 if (style->draw_begin)
185 style->draw_begin(out, style->userdata);
186 if (type == NK_TOGGLE_CHECK) {
187 nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font, text_alignment);
189 nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, text_alignment);
192 style->draw_end(out, style->userdata);
193 return (was_active != *active);
201nk_check_text(
struct nk_context *ctx,
const char *text,
int len, nk_bool active)
212 NK_ASSERT(ctx->current);
213 NK_ASSERT(ctx->current->layout);
214 if (!ctx || !ctx->current || !ctx->current->layout)
219 layout = win->layout;
221 state = nk_widget(&bounds, ctx);
222 if (!state)
return active;
224 nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active,
225 text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font, NK_WIDGET_LEFT, NK_TEXT_LEFT);
229nk_check_text_align(
struct nk_context *ctx,
const char *text,
int len, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment)
240 NK_ASSERT(ctx->current);
241 NK_ASSERT(ctx->current->layout);
242 if (!ctx || !ctx->current || !ctx->current->layout)
247 layout = win->layout;
249 state = nk_widget(&bounds, ctx);
250 if (!state)
return active;
252 nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active,
253 text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font, widget_alignment, text_alignment);
257nk_check_flags_text(
struct nk_context *ctx,
const char *text,
int len,
258 unsigned int flags,
unsigned int value)
263 if (!ctx || !text)
return flags;
264 old_active = (int)((flags & value) & value);
265 if (nk_check_text(ctx, text, len, old_active))
267 else flags &= ~value;
271nk_checkbox_text(
struct nk_context *ctx,
const char *text,
int len, nk_bool *active)
277 if (!ctx || !text || !active)
return 0;
279 *active = nk_check_text(ctx, text, len, *active);
280 return old_val != *active;
283nk_checkbox_text_align(
struct nk_context *ctx,
const char *text,
int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment)
289 if (!ctx || !text || !active)
return 0;
291 *active = nk_check_text_align(ctx, text, len, *active, widget_alignment, text_alignment);
292 return old_val != *active;
295nk_checkbox_flags_text(
struct nk_context *ctx,
const char *text,
int len,
296 unsigned int *flags,
unsigned int value)
302 if (!ctx || !text || !flags)
return 0;
304 active = (int)((*flags & value) & value);
305 if (nk_checkbox_text(ctx, text, len, &active)) {
306 if (active) *flags |= value;
307 else *flags &= ~value;
312NK_API nk_bool nk_check_label(
struct nk_context *ctx,
const char *label, nk_bool active)
314 return nk_check_text(ctx, label, nk_strlen(label), active);
316NK_API
unsigned int nk_check_flags_label(
struct nk_context *ctx,
const char *label,
317 unsigned int flags,
unsigned int value)
319 return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value);
321NK_API nk_bool nk_checkbox_label(
struct nk_context *ctx,
const char *label, nk_bool *active)
323 return nk_checkbox_text(ctx, label, nk_strlen(label), active);
325NK_API nk_bool nk_checkbox_label_align(
struct nk_context *ctx,
const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment)
327 return nk_checkbox_text_align(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment);
329NK_API nk_bool nk_checkbox_flags_label(
struct nk_context *ctx,
const char *label,
330 unsigned int *flags,
unsigned int value)
332 return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value);
340nk_option_text(
struct nk_context *ctx,
const char *text,
int len, nk_bool is_active)
351 NK_ASSERT(ctx->current);
352 NK_ASSERT(ctx->current->layout);
353 if (!ctx || !ctx->current || !ctx->current->layout)
358 layout = win->layout;
360 state = nk_widget(&bounds, ctx);
361 if (!state)
return (
int)state;
363 nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &is_active,
364 text, len, NK_TOGGLE_OPTION, &style->option, in, style->font, NK_WIDGET_LEFT, NK_TEXT_LEFT);
368nk_option_text_align(
struct nk_context *ctx,
const char *text,
int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment)
379 NK_ASSERT(ctx->current);
380 NK_ASSERT(ctx->current->layout);
381 if (!ctx || !ctx->current || !ctx->current->layout)
386 layout = win->layout;
388 state = nk_widget(&bounds, ctx);
389 if (!state)
return (
int)state;
391 nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &is_active,
392 text, len, NK_TOGGLE_OPTION, &style->option, in, style->font, widget_alignment, text_alignment);
396nk_radio_text(
struct nk_context *ctx,
const char *text,
int len, nk_bool *active)
402 if (!ctx || !text || !active)
return 0;
404 *active = nk_option_text(ctx, text, len, old_value);
405 return old_value != *active;
408nk_radio_text_align(
struct nk_context *ctx,
const char *text,
int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment)
414 if (!ctx || !text || !active)
return 0;
416 *active = nk_option_text_align(ctx, text, len, old_value, widget_alignment, text_alignment);
417 return old_value != *active;
420nk_option_label(
struct nk_context *ctx,
const char *label, nk_bool active)
422 return nk_option_text(ctx, label, nk_strlen(label), active);
425nk_option_label_align(
struct nk_context *ctx,
const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment)
427 return nk_option_text_align(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment);
430nk_radio_label(
struct nk_context *ctx,
const char *label, nk_bool *active)
432 return nk_radio_text(ctx, label, nk_strlen(label), active);
435nk_radio_label_align(
struct nk_context *ctx,
const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment)
437 return nk_radio_text_align(ctx, label, nk_strlen(label), active, widget_alignment, 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_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