|
|
@@ -2290,6 +2290,21 @@ NK_API void nk_rule_horizontal(struct nk_context *ctx, struct nk_color color, nk
|
|
|
/// nk_layout_space_rect_to_screen | Converts rectangle from nk_layout_space coordinate space into screen space
|
|
|
/// nk_layout_space_rect_to_local | Converts rectangle from screen space into nk_layout_space coordinates
|
|
|
*/
|
|
|
+
|
|
|
+enum nk_widget_align {
|
|
|
+ NK_WIDGET_ALIGN_LEFT = 0x01,
|
|
|
+ NK_WIDGET_ALIGN_CENTERED = 0x02,
|
|
|
+ NK_WIDGET_ALIGN_RIGHT = 0x04,
|
|
|
+ NK_WIDGET_ALIGN_TOP = 0x08,
|
|
|
+ NK_WIDGET_ALIGN_MIDDLE = 0x10,
|
|
|
+ NK_WIDGET_ALIGN_BOTTOM = 0x20
|
|
|
+};
|
|
|
+enum nk_widget_alignment {
|
|
|
+ NK_WIDGET_LEFT = NK_WIDGET_ALIGN_MIDDLE|NK_WIDGET_ALIGN_LEFT,
|
|
|
+ NK_WIDGET_CENTERED = NK_WIDGET_ALIGN_MIDDLE|NK_WIDGET_ALIGN_CENTERED,
|
|
|
+ NK_WIDGET_RIGHT = NK_WIDGET_ALIGN_MIDDLE|NK_WIDGET_ALIGN_RIGHT
|
|
|
+};
|
|
|
+
|
|
|
/*/// #### nk_layout_set_min_row_height
|
|
|
/// Sets the currently used minimum row height.
|
|
|
/// !!! WARNING
|
|
|
@@ -3187,14 +3202,14 @@ NK_API nk_bool nk_button_pop_behavior(struct nk_context*);
|
|
|
* CHECKBOX
|
|
|
*
|
|
|
* ============================================================================= */
|
|
|
-NK_API nk_bool nk_check_label(struct nk_context*, const char*, nk_bool active);
|
|
|
-NK_API nk_bool nk_check_text(struct nk_context*, const char*, int, nk_bool active);
|
|
|
-NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value);
|
|
|
-NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value);
|
|
|
-NK_API nk_bool nk_checkbox_label(struct nk_context*, const char*, nk_bool *active);
|
|
|
-NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active);
|
|
|
-NK_API nk_bool nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value);
|
|
|
-NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value);
|
|
|
+NK_API nk_bool nk_check_label(struct nk_context*, const char*, nk_bool active, nk_flags alignment);
|
|
|
+NK_API nk_bool nk_check_text(struct nk_context*, const char*, int, nk_bool active, nk_flags alignment);
|
|
|
+NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value, nk_flags alignment);
|
|
|
+NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value, nk_flags alignment);
|
|
|
+NK_API nk_bool nk_checkbox_label(struct nk_context*, const char*, nk_bool *active, nk_flags alignment);
|
|
|
+NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags alignment);
|
|
|
+NK_API nk_bool nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value, nk_flags alignment);
|
|
|
+NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value, nk_flags alignment);
|
|
|
/* =============================================================================
|
|
|
*
|
|
|
* RADIO BUTTON
|
|
|
@@ -6030,9 +6045,9 @@ enum nk_toggle_type {
|
|
|
NK_TOGGLE_OPTION
|
|
|
};
|
|
|
NK_LIB nk_bool nk_toggle_behavior(const struct nk_input *in, struct nk_rect select, nk_flags *state, nk_bool active);
|
|
|
-NK_LIB void nk_draw_checkbox(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, nk_bool active, const struct nk_rect *label, const struct nk_rect *selector, const struct nk_rect *cursors, const char *string, int len, const struct nk_user_font *font);
|
|
|
+NK_LIB void nk_draw_checkbox(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, nk_bool active, const struct nk_rect *label, const struct nk_rect *selector, const struct nk_rect *cursors, const char *string, int len, const struct nk_user_font *font, nk_flags alignment);
|
|
|
NK_LIB void nk_draw_option(struct nk_command_buffer *out, nk_flags state, const struct nk_style_toggle *style, nk_bool active, const struct nk_rect *label, const struct nk_rect *selector, const struct nk_rect *cursors, const char *string, int len, const struct nk_user_font *font);
|
|
|
-NK_LIB nk_bool nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, nk_bool *active, const char *str, int len, enum nk_toggle_type type, const struct nk_style_toggle *style, const struct nk_input *in, const struct nk_user_font *font);
|
|
|
+NK_LIB nk_bool nk_do_toggle(nk_flags *state, struct nk_command_buffer *out, struct nk_rect r, nk_bool *active, const char *str, int len, enum nk_toggle_type type, const struct nk_style_toggle *style, const struct nk_input *in, const struct nk_user_font *font, nk_flags alignment);
|
|
|
|
|
|
/* progress */
|
|
|
NK_LIB nk_size nk_progress_behavior(nk_flags *state, struct nk_input *in, struct nk_rect r, struct nk_rect cursor, nk_size max, nk_size value, nk_bool modifiable);
|
|
|
@@ -24464,7 +24479,7 @@ nk_draw_checkbox(struct nk_command_buffer *out,
|
|
|
nk_flags state, const struct nk_style_toggle *style, nk_bool active,
|
|
|
const struct nk_rect *label, const struct nk_rect *selector,
|
|
|
const struct nk_rect *cursors, const char *string, int len,
|
|
|
- const struct nk_user_font *font)
|
|
|
+ const struct nk_user_font *font, nk_flags alignment)
|
|
|
{
|
|
|
const struct nk_style_item *background;
|
|
|
const struct nk_style_item *cursor;
|
|
|
@@ -24485,6 +24500,11 @@ nk_draw_checkbox(struct nk_command_buffer *out,
|
|
|
text.text = style->text_normal;
|
|
|
}
|
|
|
|
|
|
+ text.padding.x = 0;
|
|
|
+ text.padding.y = 0;
|
|
|
+ text.background = style->text_background;
|
|
|
+ nk_widget_text(out, *label, string, len, &text, alignment, font);
|
|
|
+
|
|
|
/* draw background and cursor */
|
|
|
if (background->type == NK_STYLE_ITEM_COLOR) {
|
|
|
nk_fill_rect(out, *selector, 0, style->border_color);
|
|
|
@@ -24495,11 +24515,6 @@ nk_draw_checkbox(struct nk_command_buffer *out,
|
|
|
nk_draw_image(out, *cursors, &cursor->data.image, nk_white);
|
|
|
else nk_fill_rect(out, *cursors, 0, cursor->data.color);
|
|
|
}
|
|
|
-
|
|
|
- text.padding.x = 0;
|
|
|
- text.padding.y = 0;
|
|
|
- text.background = style->text_background;
|
|
|
- nk_widget_text(out, *label, string, len, &text, NK_TEXT_LEFT, font);
|
|
|
}
|
|
|
NK_LIB void
|
|
|
nk_draw_option(struct nk_command_buffer *out,
|
|
|
@@ -24548,9 +24563,10 @@ nk_do_toggle(nk_flags *state,
|
|
|
struct nk_command_buffer *out, struct nk_rect r,
|
|
|
nk_bool *active, const char *str, int len, enum nk_toggle_type type,
|
|
|
const struct nk_style_toggle *style, const struct nk_input *in,
|
|
|
- const struct nk_user_font *font)
|
|
|
+ const struct nk_user_font *font, nk_flags alignment)
|
|
|
{
|
|
|
int was_active;
|
|
|
+ struct nk_rect allocated_space;
|
|
|
struct nk_rect bounds;
|
|
|
struct nk_rect select;
|
|
|
struct nk_rect cursor;
|
|
|
@@ -24565,6 +24581,13 @@ nk_do_toggle(nk_flags *state,
|
|
|
r.w = NK_MAX(r.w, font->height + 2 * style->padding.x);
|
|
|
r.h = NK_MAX(r.h, font->height + 2 * style->padding.y);
|
|
|
|
|
|
+ allocated_space = r;
|
|
|
+
|
|
|
+ if (alignment & NK_WIDGET_ALIGN_RIGHT) {
|
|
|
+ r.x = r.x + r.w - font->height - style->padding.x;
|
|
|
+ r.w = font->height;
|
|
|
+ }
|
|
|
+
|
|
|
/* add additional touch padding for touch screen devices */
|
|
|
bounds.x = r.x - style->touch_padding.x;
|
|
|
bounds.y = r.y - style->touch_padding.y;
|
|
|
@@ -24583,11 +24606,17 @@ nk_do_toggle(nk_flags *state,
|
|
|
cursor.w = select.w - (2 * style->padding.x + 2 * style->border);
|
|
|
cursor.h = select.h - (2 * style->padding.y + 2 * style->border);
|
|
|
|
|
|
- /* label behind the selector */
|
|
|
- label.x = select.x + select.w + style->spacing;
|
|
|
label.y = select.y;
|
|
|
- label.w = NK_MAX(r.x + r.w, label.x) - label.x;
|
|
|
label.h = select.w;
|
|
|
+ if (alignment & NK_WIDGET_ALIGN_LEFT) {
|
|
|
+ /* label behind the selector */
|
|
|
+ label.x = select.x + select.w + style->spacing;
|
|
|
+ label.w = NK_MAX(r.x + r.w, label.x) - label.x;
|
|
|
+ } else {
|
|
|
+ /* label in front of the selector */
|
|
|
+ label.x = allocated_space.x;
|
|
|
+ label.w = allocated_space.w - select.w - style->spacing * 2;
|
|
|
+ }
|
|
|
|
|
|
/* update selector */
|
|
|
was_active = *active;
|
|
|
@@ -24597,7 +24626,7 @@ nk_do_toggle(nk_flags *state,
|
|
|
if (style->draw_begin)
|
|
|
style->draw_begin(out, style->userdata);
|
|
|
if (type == NK_TOGGLE_CHECK) {
|
|
|
- nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font);
|
|
|
+ nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font, alignment);
|
|
|
} else {
|
|
|
nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font);
|
|
|
}
|
|
|
@@ -24611,7 +24640,7 @@ nk_do_toggle(nk_flags *state,
|
|
|
*
|
|
|
* --------------------------------------------------------------*/
|
|
|
NK_API nk_bool
|
|
|
-nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active)
|
|
|
+nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active, nk_flags alignment)
|
|
|
{
|
|
|
struct nk_window *win;
|
|
|
struct nk_panel *layout;
|
|
|
@@ -24635,25 +24664,25 @@ nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active)
|
|
|
if (!state) return active;
|
|
|
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
|
|
|
nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active,
|
|
|
- text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font);
|
|
|
+ text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font, alignment);
|
|
|
return active;
|
|
|
}
|
|
|
NK_API unsigned int
|
|
|
nk_check_flags_text(struct nk_context *ctx, const char *text, int len,
|
|
|
- unsigned int flags, unsigned int value)
|
|
|
+ unsigned int flags, unsigned int value, nk_flags alignment)
|
|
|
{
|
|
|
int old_active;
|
|
|
NK_ASSERT(ctx);
|
|
|
NK_ASSERT(text);
|
|
|
if (!ctx || !text) return flags;
|
|
|
old_active = (int)((flags & value) & value);
|
|
|
- if (nk_check_text(ctx, text, len, old_active))
|
|
|
+ if (nk_check_text(ctx, text, len, old_active, alignment))
|
|
|
flags |= value;
|
|
|
else flags &= ~value;
|
|
|
return flags;
|
|
|
}
|
|
|
NK_API nk_bool
|
|
|
-nk_checkbox_text(struct nk_context *ctx, const char *text, int len, nk_bool *active)
|
|
|
+nk_checkbox_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags alignment)
|
|
|
{
|
|
|
int old_val;
|
|
|
NK_ASSERT(ctx);
|
|
|
@@ -24661,12 +24690,12 @@ nk_checkbox_text(struct nk_context *ctx, const char *text, int len, nk_bool *act
|
|
|
NK_ASSERT(active);
|
|
|
if (!ctx || !text || !active) return 0;
|
|
|
old_val = *active;
|
|
|
- *active = nk_check_text(ctx, text, len, *active);
|
|
|
+ *active = nk_check_text(ctx, text, len, *active, alignment);
|
|
|
return old_val != *active;
|
|
|
}
|
|
|
NK_API nk_bool
|
|
|
nk_checkbox_flags_text(struct nk_context *ctx, const char *text, int len,
|
|
|
- unsigned int *flags, unsigned int value)
|
|
|
+ unsigned int *flags, unsigned int value, nk_flags alignment)
|
|
|
{
|
|
|
nk_bool active;
|
|
|
NK_ASSERT(ctx);
|
|
|
@@ -24675,30 +24704,30 @@ nk_checkbox_flags_text(struct nk_context *ctx, const char *text, int len,
|
|
|
if (!ctx || !text || !flags) return 0;
|
|
|
|
|
|
active = (int)((*flags & value) & value);
|
|
|
- if (nk_checkbox_text(ctx, text, len, &active)) {
|
|
|
+ if (nk_checkbox_text(ctx, text, len, &active, alignment)) {
|
|
|
if (active) *flags |= value;
|
|
|
else *flags &= ~value;
|
|
|
return 1;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-NK_API nk_bool nk_check_label(struct nk_context *ctx, const char *label, nk_bool active)
|
|
|
+NK_API nk_bool nk_check_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags alignment)
|
|
|
{
|
|
|
- return nk_check_text(ctx, label, nk_strlen(label), active);
|
|
|
+ return nk_check_text(ctx, label, nk_strlen(label), active, alignment);
|
|
|
}
|
|
|
NK_API unsigned int nk_check_flags_label(struct nk_context *ctx, const char *label,
|
|
|
- unsigned int flags, unsigned int value)
|
|
|
+ unsigned int flags, unsigned int value, nk_flags alignment)
|
|
|
{
|
|
|
- return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value);
|
|
|
+ return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value, alignment);
|
|
|
}
|
|
|
-NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active)
|
|
|
+NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags alignment)
|
|
|
{
|
|
|
- return nk_checkbox_text(ctx, label, nk_strlen(label), active);
|
|
|
+ return nk_checkbox_text(ctx, label, nk_strlen(label), active, alignment);
|
|
|
}
|
|
|
NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label,
|
|
|
- unsigned int *flags, unsigned int value)
|
|
|
+ unsigned int *flags, unsigned int value, nk_flags alignment)
|
|
|
{
|
|
|
- return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value);
|
|
|
+ return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value, alignment);
|
|
|
}
|
|
|
/*----------------------------------------------------------------
|
|
|
*
|
|
|
@@ -24730,7 +24759,7 @@ nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_act
|
|
|
if (!state) return (int)state;
|
|
|
in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input;
|
|
|
nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &is_active,
|
|
|
- text, len, NK_TOGGLE_OPTION, &style->option, in, style->font);
|
|
|
+ text, len, NK_TOGGLE_OPTION, &style->option, in, style->font, NK_WIDGET_LEFT);
|
|
|
return is_active;
|
|
|
}
|
|
|
NK_API nk_bool
|