Added checkbox alignment right
This commit is contained in:
parent
141d3cf9c6
commit
f187c39283
@ -41,7 +41,7 @@ overview(struct nk_context *ctx)
|
||||
show_app_about = nk_true;
|
||||
nk_progress(ctx, &prog, 100, NK_MODIFIABLE);
|
||||
nk_slider_int(ctx, 0, &slider, 16, 1);
|
||||
nk_checkbox_label(ctx, "check", &check);
|
||||
nk_checkbox_label(ctx, "check", &check, NK_WIDGET_LEFT);
|
||||
nk_menu_end(ctx);
|
||||
}
|
||||
/* menu #2 */
|
||||
@ -100,7 +100,7 @@ overview(struct nk_context *ctx)
|
||||
nk_layout_row_push(ctx, 70);
|
||||
nk_progress(ctx, &mprog, 100, NK_MODIFIABLE);
|
||||
nk_slider_int(ctx, 0, &mslider, 16, 1);
|
||||
nk_checkbox_label(ctx, "check", &mcheck);
|
||||
nk_checkbox_label(ctx, "check", &mcheck, NK_WIDGET_LEFT);
|
||||
nk_menubar_end(ctx);
|
||||
}
|
||||
|
||||
@ -121,14 +121,14 @@ overview(struct nk_context *ctx)
|
||||
/* window flags */
|
||||
if (nk_tree_push(ctx, NK_TREE_TAB, "Window", NK_MINIMIZED)) {
|
||||
nk_layout_row_dynamic(ctx, 30, 2);
|
||||
nk_checkbox_label(ctx, "Menu", &show_menu);
|
||||
nk_checkbox_flags_label(ctx, "Titlebar", &window_flags, NK_WINDOW_TITLE);
|
||||
nk_checkbox_flags_label(ctx, "Border", &window_flags, NK_WINDOW_BORDER);
|
||||
nk_checkbox_flags_label(ctx, "Resizable", &window_flags, NK_WINDOW_SCALABLE);
|
||||
nk_checkbox_flags_label(ctx, "Movable", &window_flags, NK_WINDOW_MOVABLE);
|
||||
nk_checkbox_flags_label(ctx, "No Scrollbar", &window_flags, NK_WINDOW_NO_SCROLLBAR);
|
||||
nk_checkbox_flags_label(ctx, "Minimizable", &window_flags, NK_WINDOW_MINIMIZABLE);
|
||||
nk_checkbox_flags_label(ctx, "Scale Left", &window_flags, NK_WINDOW_SCALE_LEFT);
|
||||
nk_checkbox_label(ctx, "Menu", &show_menu, NK_WIDGET_LEFT);
|
||||
nk_checkbox_flags_label(ctx, "Titlebar", &window_flags, NK_WINDOW_TITLE, NK_WIDGET_LEFT);
|
||||
nk_checkbox_flags_label(ctx, "Border", &window_flags, NK_WINDOW_BORDER, NK_WIDGET_LEFT);
|
||||
nk_checkbox_flags_label(ctx, "Resizable", &window_flags, NK_WINDOW_SCALABLE, NK_WIDGET_LEFT);
|
||||
nk_checkbox_flags_label(ctx, "Movable", &window_flags, NK_WINDOW_MOVABLE, NK_WIDGET_LEFT);
|
||||
nk_checkbox_flags_label(ctx, "No Scrollbar", &window_flags, NK_WINDOW_NO_SCROLLBAR, NK_WIDGET_LEFT);
|
||||
nk_checkbox_flags_label(ctx, "Minimizable", &window_flags, NK_WINDOW_MINIMIZABLE, NK_WIDGET_LEFT);
|
||||
nk_checkbox_flags_label(ctx, "Scale Left", &window_flags, NK_WINDOW_SCALE_LEFT, NK_WIDGET_LEFT);
|
||||
nk_tree_pop(ctx);
|
||||
}
|
||||
|
||||
@ -201,8 +201,8 @@ overview(struct nk_context *ctx)
|
||||
static int range_int_max = 4096;
|
||||
static const float ratio[] = {120, 150};
|
||||
|
||||
nk_layout_row_static(ctx, 30, 100, 1);
|
||||
nk_checkbox_label(ctx, "Checkbox", &checkbox);
|
||||
nk_layout_row_dynamic(ctx, 0, 1);
|
||||
nk_checkbox_label(ctx, "HTESTH", &checkbox, NK_WIDGET_RIGHT);
|
||||
|
||||
nk_layout_row_static(ctx, 30, 80, 3);
|
||||
option = nk_option_label(ctx, "optionA", option == A) ? A : option;
|
||||
@ -244,7 +244,7 @@ overview(struct nk_context *ctx)
|
||||
{
|
||||
static int inactive = 1;
|
||||
nk_layout_row_dynamic(ctx, 30, 1);
|
||||
nk_checkbox_label(ctx, "Inactive", &inactive);
|
||||
nk_checkbox_label(ctx, "Inactive", &inactive, NK_WIDGET_LEFT);
|
||||
|
||||
nk_layout_row_static(ctx, 30, 80, 1);
|
||||
if (inactive) {
|
||||
@ -404,10 +404,10 @@ overview(struct nk_context *ctx)
|
||||
sprintf(buffer, "%lu", sum);
|
||||
if (nk_combo_begin_label(ctx, buffer, nk_vec2(200,200))) {
|
||||
nk_layout_row_dynamic(ctx, 30, 1);
|
||||
nk_checkbox_label(ctx, weapons[0], &check_values[0]);
|
||||
nk_checkbox_label(ctx, weapons[1], &check_values[1]);
|
||||
nk_checkbox_label(ctx, weapons[2], &check_values[2]);
|
||||
nk_checkbox_label(ctx, weapons[3], &check_values[3]);
|
||||
nk_checkbox_label(ctx, weapons[0], &check_values[0], NK_WIDGET_LEFT);
|
||||
nk_checkbox_label(ctx, weapons[1], &check_values[1], NK_WIDGET_LEFT);
|
||||
nk_checkbox_label(ctx, weapons[2], &check_values[2], NK_WIDGET_LEFT);
|
||||
nk_checkbox_label(ctx, weapons[3], &check_values[3], NK_WIDGET_LEFT);
|
||||
nk_combo_end(ctx);
|
||||
}
|
||||
|
||||
@ -716,7 +716,7 @@ overview(struct nk_context *ctx)
|
||||
static int slider = 10;
|
||||
|
||||
nk_layout_row_dynamic(ctx, 25, 1);
|
||||
nk_checkbox_label(ctx, "Menu", &show_menu);
|
||||
nk_checkbox_label(ctx, "Menu", &show_menu, NK_WIDGET_LEFT);
|
||||
nk_progress(ctx, &prog, 100, NK_MODIFIABLE);
|
||||
nk_slider_int(ctx, 0, &slider, 16, 1);
|
||||
if (nk_contextual_item_label(ctx, "About", NK_TEXT_CENTERED))
|
||||
@ -883,9 +883,9 @@ overview(struct nk_context *ctx)
|
||||
if (group_titlebar) group_flags |= NK_WINDOW_TITLE;
|
||||
|
||||
nk_layout_row_dynamic(ctx, 30, 3);
|
||||
nk_checkbox_label(ctx, "Titlebar", &group_titlebar);
|
||||
nk_checkbox_label(ctx, "Border", &group_border);
|
||||
nk_checkbox_label(ctx, "No Scrollbar", &group_no_scrollbar);
|
||||
nk_checkbox_label(ctx, "Titlebar", &group_titlebar, NK_WIDGET_LEFT);
|
||||
nk_checkbox_label(ctx, "Border", &group_border, NK_WIDGET_LEFT);
|
||||
nk_checkbox_label(ctx, "No Scrollbar", &group_no_scrollbar, NK_WIDGET_LEFT);
|
||||
|
||||
nk_layout_row_begin(ctx, NK_STATIC, 22, 3);
|
||||
nk_layout_row_push(ctx, 50);
|
||||
|
105
nuklear.h
105
nuklear.h
@ -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
|
||||
|
@ -2068,6 +2068,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
|
||||
@ -2965,14 +2980,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
|
||||
|
@ -255,9 +255,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);
|
||||
|
@ -26,7 +26,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;
|
||||
@ -47,6 +47,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);
|
||||
@ -57,11 +62,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,
|
||||
@ -110,9 +110,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;
|
||||
@ -127,6 +128,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;
|
||||
@ -145,11 +153,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;
|
||||
@ -159,7 +173,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);
|
||||
}
|
||||
@ -173,7 +187,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;
|
||||
@ -197,25 +211,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);
|
||||
@ -223,12 +237,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);
|
||||
@ -237,30 +251,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);
|
||||
}
|
||||
/*----------------------------------------------------------------
|
||||
*
|
||||
@ -292,7 +306,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user