2#include "nuklear_internal.h"
13 const struct nk_rect *icon,
const struct nk_image *img,
enum nk_symbol_type sym,
14 const char *
string,
int len, nk_flags align,
const struct nk_user_font *font)
18 text.padding = style->padding;
23 background = &style->pressed;
24 text.text = style->text_pressed;
26 background = &style->hover;
27 text.text = style->text_hover;
29 background = &style->normal;
30 text.text = style->text_normal;
34 background = &style->pressed_active;
35 text.text = style->text_pressed_active;
37 background = &style->hover_active;
38 text.text = style->text_hover_active;
40 background = &style->normal_active;
41 text.text = style->text_normal_active;
45 text.text = nk_rgb_factor(text.text, style->color_factor);
48 switch (background->type) {
49 case NK_STYLE_ITEM_IMAGE:
50 text.background = nk_rgba(0, 0, 0, 0);
51 nk_draw_image(out, *bounds, &background->data.image, nk_rgb_factor(nk_white, style->color_factor));
53 case NK_STYLE_ITEM_NINE_SLICE:
54 text.background = nk_rgba(0, 0, 0, 0);
55 nk_draw_nine_slice(out, *bounds, &background->data.slice, nk_rgb_factor(nk_white, style->color_factor));
57 case NK_STYLE_ITEM_COLOR:
58 text.background = background->data.color;
59 nk_fill_rect(out, *bounds, style->rounding, background->data.color);
63 if (img)
nk_draw_image(out, *icon, img, nk_rgb_factor(nk_white, style->color_factor));
64 else nk_draw_symbol(out, sym, *icon, text.background, text.text, 1, font);
66 nk_widget_text(out, *bounds,
string, len, &text, align, font);
70 struct nk_rect bounds,
const char *str,
int len, nk_flags align, nk_bool *value,
85 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
89 touch.x = bounds.x - style->touch_padding.x;
90 touch.y = bounds.y - style->touch_padding.y;
91 touch.w = bounds.w + style->touch_padding.x * 2;
92 touch.h = bounds.h + style->touch_padding.y * 2;
95 if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT))
99 if (style->draw_begin) style->draw_begin(out, style->userdata);
100 nk_draw_selectable(out, *state, style, *value, &bounds, 0,0,NK_SYMBOL_NONE, str, len, align, font);
101 if (style->draw_end) style->draw_end(out, style->userdata);
102 return old_value != *value;
106 struct nk_rect bounds,
const char *str,
int len, nk_flags align, nk_bool *value,
122 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
126 touch.x = bounds.x - style->touch_padding.x;
127 touch.y = bounds.y - style->touch_padding.y;
128 touch.w = bounds.w + style->touch_padding.x * 2;
129 touch.h = bounds.h + style->touch_padding.y * 2;
130 if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT))
133 icon.y = bounds.y + style->padding.y;
134 icon.w = icon.h = bounds.h - 2 * style->padding.y;
135 if (align & NK_TEXT_ALIGN_LEFT) {
136 icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w);
137 icon.x = NK_MAX(icon.x, 0);
138 }
else icon.x = bounds.x + 2 * style->padding.x;
140 icon.x += style->image_padding.x;
141 icon.y += style->image_padding.y;
142 icon.w -= 2 * style->image_padding.x;
143 icon.h -= 2 * style->image_padding.y;
146 if (style->draw_begin) style->draw_begin(out, style->userdata);
147 nk_draw_selectable(out, *state, style, *value, &bounds, &icon, img, NK_SYMBOL_NONE, str, len, align, font);
148 if (style->draw_end) style->draw_end(out, style->userdata);
149 return old_value != *value;
153 struct nk_rect bounds,
const char *str,
int len, nk_flags align, nk_bool *value,
169 if (!state || !out || !str || !len || !value || !style || !font)
return 0;
173 touch.x = bounds.x - style->touch_padding.x;
174 touch.y = bounds.y - style->touch_padding.y;
175 touch.w = bounds.w + style->touch_padding.x * 2;
176 touch.h = bounds.h + style->touch_padding.y * 2;
177 if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT))
180 icon.y = bounds.y + style->padding.y;
181 icon.w = icon.h = bounds.h - 2 * style->padding.y;
182 if (align & NK_TEXT_ALIGN_LEFT) {
183 icon.x = (bounds.x + bounds.w) - (2 * style->padding.x + icon.w);
184 icon.x = NK_MAX(icon.x, 0);
185 }
else icon.x = bounds.x + 2 * style->padding.x;
187 icon.x += style->image_padding.x;
188 icon.y += style->image_padding.y;
189 icon.w -= 2 * style->image_padding.x;
190 icon.h -= 2 * style->image_padding.y;
193 if (style->draw_begin) style->draw_begin(out, style->userdata);
194 nk_draw_selectable(out, *state, style, *value, &bounds, &icon, 0, sym, str, len, align, font);
195 if (style->draw_end) style->draw_end(out, style->userdata);
196 return old_value != *value;
200nk_selectable_text(
struct nk_context *ctx,
const char *str,
int len,
201 nk_flags align, nk_bool *value)
213 NK_ASSERT(ctx->current);
214 NK_ASSERT(ctx->current->layout);
215 if (!ctx || !ctx->current || !ctx->current->layout || !value)
219 layout = win->layout;
222 state = nk_widget(&bounds, ctx);
223 if (!state)
return 0;
225 return nk_do_selectable(&ctx->last_widget_state, &win->buffer, bounds,
226 str, len, align, value, &style->selectable, in, style->font);
230 const char *str,
int len, nk_flags align, nk_bool *value)
242 NK_ASSERT(ctx->current);
243 NK_ASSERT(ctx->current->layout);
244 if (!ctx || !ctx->current || !ctx->current->layout || !value)
248 layout = win->layout;
251 state = nk_widget(&bounds, ctx);
252 if (!state)
return 0;
254 return nk_do_selectable_image(&ctx->last_widget_state, &win->buffer, bounds,
255 str, len, align, value, &img, &style->selectable, in, style->font);
258nk_selectable_symbol_text(
struct nk_context *ctx,
enum nk_symbol_type sym,
259 const char *str,
int len, nk_flags align, nk_bool *value)
271 NK_ASSERT(ctx->current);
272 NK_ASSERT(ctx->current->layout);
273 if (!ctx || !ctx->current || !ctx->current->layout || !value)
277 layout = win->layout;
280 state = nk_widget(&bounds, ctx);
281 if (!state)
return 0;
283 return nk_do_selectable_symbol(&ctx->last_widget_state, &win->buffer, bounds,
284 str, len, align, value, sym, &style->selectable, in, style->font);
287nk_selectable_symbol_label(
struct nk_context *ctx,
enum nk_symbol_type sym,
288 const char *title, nk_flags align, nk_bool *value)
290 return nk_selectable_symbol_text(ctx, sym, title, nk_strlen(title), align, value);
292NK_API nk_bool nk_select_text(
struct nk_context *ctx,
const char *str,
int len,
293 nk_flags align, nk_bool value)
295 nk_selectable_text(ctx, str, len, align, &value);
return value;
297NK_API nk_bool nk_selectable_label(
struct nk_context *ctx,
const char *str, nk_flags align, nk_bool *value)
299 return nk_selectable_text(ctx, str, nk_strlen(str), align, value);
302 const char *str, nk_flags align, nk_bool *value)
304 return nk_selectable_image_text(ctx, img, str, nk_strlen(str), align, value);
306NK_API nk_bool nk_select_label(
struct nk_context *ctx,
const char *str, nk_flags align, nk_bool value)
308 nk_selectable_text(ctx, str, nk_strlen(str), align, &value);
return value;
311 const char *str, nk_flags align, nk_bool value)
313 nk_selectable_image_text(ctx, img, str, nk_strlen(str), align, &value);
return value;
316 const char *str,
int len, nk_flags align, nk_bool value)
318 nk_selectable_image_text(ctx, img, str, len, align, &value);
return value;
321nk_select_symbol_text(
struct nk_context *ctx,
enum nk_symbol_type sym,
322 const char *title,
int title_len, nk_flags align, nk_bool value)
324 nk_selectable_symbol_text(ctx, sym, title, title_len, align, &value);
return value;
327nk_select_symbol_label(
struct nk_context *ctx,
enum nk_symbol_type sym,
328 const char *title, nk_flags align, nk_bool value)
330 return nk_select_symbol_text(ctx, sym, title, nk_strlen(title), align, value);
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_ACTIVED
!< widget is being hovered
@ NK_WIDGET_STATE_HOVER
!< widget has been hovered on the current frame
@ 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.