From f187c39283c6b2abc89faf47808836df191c52b6 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Fri, 24 Nov 2023 16:24:20 +0100 Subject: [PATCH 01/16] Added checkbox alignment right --- demo/common/overview.c | 42 ++++++++--------- nuklear.h | 105 ++++++++++++++++++++++++++--------------- src/nuklear.h | 31 ++++++++---- src/nuklear_internal.h | 4 +- src/nuklear_toggle.c | 70 ++++++++++++++++----------- 5 files changed, 155 insertions(+), 97 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index ab66c84..8c7972c 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -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); diff --git a/nuklear.h b/nuklear.h index baac97f..7dfe23d 100644 --- a/nuklear.h +++ b/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 diff --git a/src/nuklear.h b/src/nuklear.h index 0b829c4..5527d04 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -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 diff --git a/src/nuklear_internal.h b/src/nuklear_internal.h index 4f71f30..f99a3bf 100644 --- a/src/nuklear_internal.h +++ b/src/nuklear_internal.h @@ -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); diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index 0644a80..02e12b5 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -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 From e782760da3e0cee98fe0e6211f556eb6ac9fa3aa Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Fri, 24 Nov 2023 16:33:16 +0100 Subject: [PATCH 02/16] Added option alignment right --- demo/common/overview.c | 15 ++++++++------- nuklear.h | 40 ++++++++++++++++++++-------------------- src/nuklear.h | 8 ++++---- src/nuklear_internal.h | 2 +- src/nuklear_toggle.c | 30 +++++++++++++++--------------- 5 files changed, 48 insertions(+), 47 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index 8c7972c..fc6fff2 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -201,13 +201,14 @@ overview(struct nk_context *ctx) static int range_int_max = 4096; static const float ratio[] = {120, 150}; - nk_layout_row_dynamic(ctx, 0, 1); - nk_checkbox_label(ctx, "HTESTH", &checkbox, NK_WIDGET_RIGHT); + nk_layout_row_dynamic(ctx, 0, 2); + nk_checkbox_label(ctx, "Checkbox Left", &checkbox, NK_WIDGET_LEFT); + nk_checkbox_label(ctx, "Checkbox Right", &checkbox, NK_WIDGET_RIGHT); nk_layout_row_static(ctx, 30, 80, 3); - option = nk_option_label(ctx, "optionA", option == A) ? A : option; - option = nk_option_label(ctx, "optionB", option == B) ? B : option; - option = nk_option_label(ctx, "optionC", option == C) ? C : option; + option = nk_option_label(ctx, "optionA", option == A, NK_WIDGET_LEFT) ? A : option; + option = nk_option_label(ctx, "optionB", option == B, NK_WIDGET_LEFT) ? B : option; + option = nk_option_label(ctx, "optionC", option == C, NK_WIDGET_LEFT) ? C : option; nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); nk_labelf(ctx, NK_TEXT_LEFT, "Slider int"); @@ -367,8 +368,8 @@ overview(struct nk_context *ctx) #endif nk_layout_row_dynamic(ctx, 25, 2); - col_mode = nk_option_label(ctx, "RGB", col_mode == COL_RGB) ? COL_RGB : col_mode; - col_mode = nk_option_label(ctx, "HSV", col_mode == COL_HSV) ? COL_HSV : col_mode; + col_mode = nk_option_label(ctx, "RGB", col_mode == COL_RGB, NK_WIDGET_LEFT) ? COL_RGB : col_mode; + col_mode = nk_option_label(ctx, "HSV", col_mode == COL_HSV, NK_WIDGET_LEFT) ? COL_HSV : col_mode; nk_layout_row_dynamic(ctx, 25, 1); if (col_mode == COL_RGB) { diff --git a/nuklear.h b/nuklear.h index 7dfe23d..5b76d43 100644 --- a/nuklear.h +++ b/nuklear.h @@ -3215,10 +3215,10 @@ NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsi * RADIO BUTTON * * ============================================================================= */ -NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active); -NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active); -NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active); -NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active); +NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags alignment); +NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags alignment); +NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags alignment); +NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags alignment); /* ============================================================================= * * SELECTABLE @@ -6046,7 +6046,7 @@ enum nk_toggle_type { }; 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_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 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_flags alignment); 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 */ @@ -24521,7 +24521,7 @@ 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) + const struct nk_user_font *font, nk_flags alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -24542,6 +24542,11 @@ nk_draw_option(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_circle(out, *selector, style->border_color); @@ -24552,11 +24557,6 @@ nk_draw_option(struct nk_command_buffer *out, nk_draw_image(out, *cursors, &cursor->data.image, nk_white); else nk_fill_circle(out, *cursors, 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 nk_bool nk_do_toggle(nk_flags *state, @@ -24628,7 +24628,7 @@ nk_do_toggle(nk_flags *state, if (type == NK_TOGGLE_CHECK) { 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); + nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, alignment); } if (style->draw_end) style->draw_end(out, style->userdata); @@ -24735,7 +24735,7 @@ NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label * * --------------------------------------------------------------*/ NK_API nk_bool -nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active) +nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags alignment) { struct nk_window *win; struct nk_panel *layout; @@ -24759,11 +24759,11 @@ 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, NK_WIDGET_LEFT); + text, len, NK_TOGGLE_OPTION, &style->option, in, style->font, alignment); return is_active; } NK_API nk_bool -nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active) +nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags alignment) { int old_value; NK_ASSERT(ctx); @@ -24771,18 +24771,18 @@ nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active NK_ASSERT(active); if (!ctx || !text || !active) return 0; old_value = *active; - *active = nk_option_text(ctx, text, len, old_value); + *active = nk_option_text(ctx, text, len, old_value, alignment); return old_value != *active; } NK_API nk_bool -nk_option_label(struct nk_context *ctx, const char *label, nk_bool active) +nk_option_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags alignment) { - return nk_option_text(ctx, label, nk_strlen(label), active); + return nk_option_text(ctx, label, nk_strlen(label), active, alignment); } NK_API nk_bool -nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active) +nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags alignment) { - return nk_radio_text(ctx, label, nk_strlen(label), active); + return nk_radio_text(ctx, label, nk_strlen(label), active, alignment); } diff --git a/src/nuklear.h b/src/nuklear.h index 5527d04..bac3243 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -2993,10 +2993,10 @@ NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsi * RADIO BUTTON * * ============================================================================= */ -NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active); -NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active); -NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active); -NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active); +NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags alignment); +NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags alignment); +NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags alignment); +NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags alignment); /* ============================================================================= * * SELECTABLE diff --git a/src/nuklear_internal.h b/src/nuklear_internal.h index f99a3bf..9f6a6dc 100644 --- a/src/nuklear_internal.h +++ b/src/nuklear_internal.h @@ -256,7 +256,7 @@ enum nk_toggle_type { }; 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_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 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_flags alignment); 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 */ diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index 02e12b5..ccf5a08 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -68,7 +68,7 @@ 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) + const struct nk_user_font *font, nk_flags alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -89,6 +89,11 @@ nk_draw_option(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_circle(out, *selector, style->border_color); @@ -99,11 +104,6 @@ nk_draw_option(struct nk_command_buffer *out, nk_draw_image(out, *cursors, &cursor->data.image, nk_white); else nk_fill_circle(out, *cursors, 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 nk_bool nk_do_toggle(nk_flags *state, @@ -175,7 +175,7 @@ nk_do_toggle(nk_flags *state, if (type == NK_TOGGLE_CHECK) { 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); + nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, alignment); } if (style->draw_end) style->draw_end(out, style->userdata); @@ -282,7 +282,7 @@ NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label * * --------------------------------------------------------------*/ NK_API nk_bool -nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active) +nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags alignment) { struct nk_window *win; struct nk_panel *layout; @@ -306,11 +306,11 @@ 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, NK_WIDGET_LEFT); + text, len, NK_TOGGLE_OPTION, &style->option, in, style->font, alignment); return is_active; } NK_API nk_bool -nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active) +nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags alignment) { int old_value; NK_ASSERT(ctx); @@ -318,17 +318,17 @@ nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active NK_ASSERT(active); if (!ctx || !text || !active) return 0; old_value = *active; - *active = nk_option_text(ctx, text, len, old_value); + *active = nk_option_text(ctx, text, len, old_value, alignment); return old_value != *active; } NK_API nk_bool -nk_option_label(struct nk_context *ctx, const char *label, nk_bool active) +nk_option_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags alignment) { - return nk_option_text(ctx, label, nk_strlen(label), active); + return nk_option_text(ctx, label, nk_strlen(label), active, alignment); } NK_API nk_bool -nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active) +nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags alignment) { - return nk_radio_text(ctx, label, nk_strlen(label), active); + return nk_radio_text(ctx, label, nk_strlen(label), active, alignment); } From 060dbf96410db76e03cb5183aa3ab6987984924e Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Fri, 24 Nov 2023 16:57:50 +0100 Subject: [PATCH 03/16] Fixed the overview example for option & checkbox alignment right --- demo/common/overview.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index fc6fff2..d01cdf4 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -135,8 +135,10 @@ overview(struct nk_context *ctx) if (nk_tree_push(ctx, NK_TREE_TAB, "Widgets", NK_MINIMIZED)) { enum options {A,B,C}; - static int checkbox; - static int option; + static int checkbox_left; + static int checkbox_right; + static int option_left; + static int option_right; if (nk_tree_push(ctx, NK_TREE_NODE, "Text", NK_MINIMIZED)) { /* Text Widgets */ @@ -201,14 +203,19 @@ overview(struct nk_context *ctx) static int range_int_max = 4096; static const float ratio[] = {120, 150}; - nk_layout_row_dynamic(ctx, 0, 2); - nk_checkbox_label(ctx, "Checkbox Left", &checkbox, NK_WIDGET_LEFT); - nk_checkbox_label(ctx, "Checkbox Right", &checkbox, NK_WIDGET_RIGHT); + nk_layout_row_dynamic(ctx, 0, 1); + nk_checkbox_label(ctx, "Checkbox Left", &checkbox_left, NK_WIDGET_LEFT); + nk_checkbox_label(ctx, "Checkbox Right", &checkbox_right, NK_WIDGET_RIGHT); nk_layout_row_static(ctx, 30, 80, 3); - option = nk_option_label(ctx, "optionA", option == A, NK_WIDGET_LEFT) ? A : option; - option = nk_option_label(ctx, "optionB", option == B, NK_WIDGET_LEFT) ? B : option; - option = nk_option_label(ctx, "optionC", option == C, NK_WIDGET_LEFT) ? C : option; + option_left = nk_option_label(ctx, "optionA", option_left == A, NK_WIDGET_LEFT) ? A : option_left; + option_left = nk_option_label(ctx, "optionB", option_left == B, NK_WIDGET_LEFT) ? B : option_left; + option_left = nk_option_label(ctx, "optionC", option_left == C, NK_WIDGET_LEFT) ? C : option_left; + + nk_layout_row_static(ctx, 30, 80, 3); + option_right = nk_option_label(ctx, "optionA", option_right == A, NK_WIDGET_RIGHT) ? A : option_right; + option_right = nk_option_label(ctx, "optionB", option_right == B, NK_WIDGET_RIGHT) ? B : option_right; + option_right = nk_option_label(ctx, "optionC", option_right == C, NK_WIDGET_RIGHT) ? C : option_right; nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); nk_labelf(ctx, NK_TEXT_LEFT, "Slider int"); From c5ee9a58ed065536c52b8af9d97fe63661f33546 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Sun, 26 Nov 2023 10:25:36 +0100 Subject: [PATCH 04/16] Added text alignment to toggleables --- demo/common/overview.c | 68 ++++++++++++++------------- nuklear.h | 104 ++++++++++++++++++++--------------------- src/nuklear.h | 24 +++++----- src/nuklear_internal.h | 6 +-- src/nuklear_toggle.c | 74 ++++++++++++++--------------- 5 files changed, 140 insertions(+), 136 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index 2907aa4..dff9796 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -43,7 +43,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_WIDGET_LEFT); + nk_checkbox_label(ctx, "check", &check, NK_WIDGET_LEFT, NK_TEXT_LEFT); nk_menu_end(ctx); } /* menu #2 */ @@ -102,7 +102,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_WIDGET_LEFT); + nk_checkbox_label(ctx, "check", &mcheck, NK_WIDGET_LEFT, NK_TEXT_LEFT); nk_menubar_end(ctx); } @@ -123,15 +123,15 @@ 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_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_checkbox_label(ctx, "Disable widgets", &disable_widgets, NK_WIDGET_LEFT); + nk_checkbox_label(ctx, "Menu", &show_menu, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_flags_label(ctx, "Titlebar", &window_flags, NK_WINDOW_TITLE, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_flags_label(ctx, "Border", &window_flags, NK_WINDOW_BORDER, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_flags_label(ctx, "Resizable", &window_flags, NK_WINDOW_SCALABLE, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_flags_label(ctx, "Movable", &window_flags, NK_WINDOW_MOVABLE, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_flags_label(ctx, "No Scrollbar", &window_flags, NK_WINDOW_NO_SCROLLBAR, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_flags_label(ctx, "Minimizable", &window_flags, NK_WINDOW_MINIMIZABLE, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_flags_label(ctx, "Scale Left", &window_flags, NK_WINDOW_SCALE_LEFT, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Disable widgets", &disable_widgets, NK_WIDGET_LEFT, NK_TEXT_LEFT); nk_tree_pop(ctx); } @@ -141,8 +141,10 @@ overview(struct nk_context *ctx) if (nk_tree_push(ctx, NK_TREE_TAB, "Widgets", NK_MINIMIZED)) { enum options {A,B,C}; - static int checkbox_left; - static int checkbox_right; + static int checkbox_left_text_left; + static int checkbox_left_text_right; + static int checkbox_right_text_right; + static int checkbox_right_text_left; static int option_left; static int option_right; if (nk_tree_push(ctx, NK_TREE_NODE, "Text", NK_MINIMIZED)) @@ -211,18 +213,20 @@ overview(struct nk_context *ctx) static const float ratio[] = {120, 150}; nk_layout_row_dynamic(ctx, 0, 1); - nk_checkbox_label(ctx, "Checkbox Left", &checkbox_left, NK_WIDGET_LEFT); - nk_checkbox_label(ctx, "Checkbox Right", &checkbox_right, NK_WIDGET_RIGHT); + nk_checkbox_label(ctx, "Checkbox Left Text Left", &checkbox_left_text_left, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Checkbox Left Text Right", &checkbox_left_text_right, NK_WIDGET_LEFT, NK_TEXT_RIGHT); + nk_checkbox_label(ctx, "Checkbox Right Text Right", &checkbox_right_text_right, NK_WIDGET_RIGHT, NK_TEXT_RIGHT); + nk_checkbox_label(ctx, "Checkbox Right Text Left", &checkbox_right_text_left, NK_WIDGET_RIGHT, NK_TEXT_LEFT); nk_layout_row_static(ctx, 30, 80, 3); - option_left = nk_option_label(ctx, "optionA", option_left == A, NK_WIDGET_LEFT) ? A : option_left; - option_left = nk_option_label(ctx, "optionB", option_left == B, NK_WIDGET_LEFT) ? B : option_left; - option_left = nk_option_label(ctx, "optionC", option_left == C, NK_WIDGET_LEFT) ? C : option_left; + option_left = nk_option_label(ctx, "optionA", option_left == A, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? A : option_left; + option_left = nk_option_label(ctx, "optionB", option_left == B, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? B : option_left; + option_left = nk_option_label(ctx, "optionC", option_left == C, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? C : option_left; nk_layout_row_static(ctx, 30, 80, 3); - option_right = nk_option_label(ctx, "optionA", option_right == A, NK_WIDGET_RIGHT) ? A : option_right; - option_right = nk_option_label(ctx, "optionB", option_right == B, NK_WIDGET_RIGHT) ? B : option_right; - option_right = nk_option_label(ctx, "optionC", option_right == C, NK_WIDGET_RIGHT) ? C : option_right; + option_right = nk_option_label(ctx, "optionA", option_right == A, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? A : option_right; + option_right = nk_option_label(ctx, "optionB", option_right == B, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? B : option_right; + option_right = nk_option_label(ctx, "optionC", option_right == C, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? C : option_right; nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); nk_labelf(ctx, NK_TEXT_LEFT, "Slider int"); @@ -259,7 +263,7 @@ overview(struct nk_context *ctx) { static int inactive = 1; nk_layout_row_dynamic(ctx, 30, 1); - nk_checkbox_label(ctx, "Inactive", &inactive, NK_WIDGET_LEFT); + nk_checkbox_label(ctx, "Inactive", &inactive, NK_WIDGET_LEFT, NK_TEXT_LEFT); nk_layout_row_static(ctx, 30, 80, 1); if (inactive) { @@ -375,8 +379,8 @@ overview(struct nk_context *ctx) #endif nk_layout_row_dynamic(ctx, 25, 2); - col_mode = nk_option_label(ctx, "RGB", col_mode == COL_RGB, NK_WIDGET_LEFT) ? COL_RGB : col_mode; - col_mode = nk_option_label(ctx, "HSV", col_mode == COL_HSV, NK_WIDGET_LEFT) ? COL_HSV : col_mode; + col_mode = nk_option_label(ctx, "RGB", col_mode == COL_RGB, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? COL_RGB : col_mode; + col_mode = nk_option_label(ctx, "HSV", col_mode == COL_HSV, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? COL_HSV : col_mode; nk_layout_row_dynamic(ctx, 25, 1); if (col_mode == COL_RGB) { @@ -412,10 +416,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_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_checkbox_label(ctx, weapons[0], &check_values[0], NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, weapons[1], &check_values[1], NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, weapons[2], &check_values[2], NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, weapons[3], &check_values[3], NK_WIDGET_LEFT, NK_TEXT_LEFT); nk_combo_end(ctx); } @@ -724,7 +728,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_WIDGET_LEFT); + nk_checkbox_label(ctx, "Menu", &show_menu, NK_WIDGET_LEFT, NK_TEXT_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)) @@ -891,9 +895,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_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_checkbox_label(ctx, "Titlebar", &group_titlebar, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Border", &group_border, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "No Scrollbar", &group_no_scrollbar, NK_WIDGET_LEFT, NK_TEXT_LEFT); nk_layout_row_begin(ctx, NK_STATIC, 22, 3); nk_layout_row_push(ctx, 50); diff --git a/nuklear.h b/nuklear.h index b062073..b2a3f51 100644 --- a/nuklear.h +++ b/nuklear.h @@ -3205,23 +3205,23 @@ 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_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); +NK_API nk_bool nk_check_label(struct nk_context*, const char*, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_check_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); +NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); /* ============================================================================= * * RADIO BUTTON * * ============================================================================= */ -NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags alignment); -NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags alignment); -NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags alignment); -NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags alignment); +NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); /* ============================================================================= * * SELECTABLE @@ -6078,9 +6078,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_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_flags alignment); -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); +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 widget_alignment, nk_flags text_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_flags widget_alignment, nk_flags text_alignment); +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 widget_alignment, nk_flags text_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); @@ -24722,7 +24722,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, nk_flags alignment) + const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -24747,7 +24747,7 @@ nk_draw_checkbox(struct nk_command_buffer *out, text.padding.x = 0; text.padding.y = 0; text.background = style->text_background; - nk_widget_text(out, *label, string, len, &text, alignment, font); + nk_widget_text(out, *label, string, len, &text, text_alignment, font); /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { @@ -24765,7 +24765,7 @@ 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_flags alignment) + const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -24790,7 +24790,7 @@ nk_draw_option(struct nk_command_buffer *out, text.padding.x = 0; text.padding.y = 0; text.background = style->text_background; - nk_widget_text(out, *label, string, len, &text, alignment, font); + nk_widget_text(out, *label, string, len, &text, text_alignment, font); /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { @@ -24808,7 +24808,7 @@ 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) + const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment) { int was_active; struct nk_rect allocated_space; @@ -24828,7 +24828,7 @@ nk_do_toggle(nk_flags *state, allocated_space = r; - if (alignment & NK_WIDGET_ALIGN_RIGHT) { + if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) { r.x = r.x + r.w - font->height - style->padding.x; r.w = font->height; } @@ -24853,14 +24853,14 @@ nk_do_toggle(nk_flags *state, label.y = select.y; 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 { + if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) { /* label in front of the selector */ label.x = allocated_space.x; label.w = allocated_space.w - select.w - style->spacing * 2; + } else { + /* label behind the selector */ + label.x = select.x + select.w + style->spacing; + label.w = NK_MAX(r.x + r.w, label.x) - label.x; } /* update selector */ @@ -24871,9 +24871,9 @@ 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, alignment); + nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font, widget_alignment, text_alignment); } else { - nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, alignment); + nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, widget_alignment, text_alignment); } if (style->draw_end) style->draw_end(out, style->userdata); @@ -24885,7 +24885,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_flags alignment) +nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) { struct nk_window *win; struct nk_panel *layout; @@ -24909,25 +24909,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 || state == NK_WIDGET_DISABLED || 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, alignment); + text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font, widget_alignment, text_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, nk_flags alignment) + unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_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, alignment)) + if (nk_check_text(ctx, text, len, old_active, widget_alignment, text_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_flags alignment) +nk_checkbox_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { int old_val; NK_ASSERT(ctx); @@ -24935,12 +24935,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, alignment); + *active = nk_check_text(ctx, text, len, *active, widget_alignment, text_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, nk_flags alignment) + unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) { nk_bool active; NK_ASSERT(ctx); @@ -24949,30 +24949,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, alignment)) { + if (nk_checkbox_text(ctx, text, len, &active, widget_alignment, text_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_flags alignment) +NK_API nk_bool nk_check_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_check_text(ctx, label, nk_strlen(label), active, alignment); + return nk_check_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } NK_API unsigned int nk_check_flags_label(struct nk_context *ctx, const char *label, - unsigned int flags, unsigned int value, nk_flags alignment) + unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value, alignment); + return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value, widget_alignment, text_alignment); } -NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags alignment) +NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_checkbox_text(ctx, label, nk_strlen(label), active, alignment); + return nk_checkbox_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label, - unsigned int *flags, unsigned int value, nk_flags alignment) + unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value, alignment); + return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value, widget_alignment, text_alignment); } /*---------------------------------------------------------------- * @@ -24980,7 +24980,7 @@ NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label * * --------------------------------------------------------------*/ NK_API nk_bool -nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags alignment) +nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment) { struct nk_window *win; struct nk_panel *layout; @@ -25004,11 +25004,11 @@ 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 || state == NK_WIDGET_DISABLED || 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, alignment); + text, len, NK_TOGGLE_OPTION, &style->option, in, style->font, widget_alignment, text_alignment); return is_active; } NK_API nk_bool -nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags alignment) +nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { int old_value; NK_ASSERT(ctx); @@ -25016,18 +25016,18 @@ nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active NK_ASSERT(active); if (!ctx || !text || !active) return 0; old_value = *active; - *active = nk_option_text(ctx, text, len, old_value, alignment); + *active = nk_option_text(ctx, text, len, old_value, widget_alignment, text_alignment); return old_value != *active; } NK_API nk_bool -nk_option_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags alignment) +nk_option_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_option_text(ctx, label, nk_strlen(label), active, alignment); + return nk_option_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } NK_API nk_bool -nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags alignment) +nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_radio_text(ctx, label, nk_strlen(label), active, alignment); + return nk_radio_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } diff --git a/src/nuklear.h b/src/nuklear.h index 26c3b4f..d7a6ad2 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -2983,23 +2983,23 @@ 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_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); +NK_API nk_bool nk_check_label(struct nk_context*, const char*, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_check_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); +NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); /* ============================================================================= * * RADIO BUTTON * * ============================================================================= */ -NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags alignment); -NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags alignment); -NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags alignment); -NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags alignment); +NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); /* ============================================================================= * * SELECTABLE diff --git a/src/nuklear_internal.h b/src/nuklear_internal.h index 9f6a6dc..31689db 100644 --- a/src/nuklear_internal.h +++ b/src/nuklear_internal.h @@ -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_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_flags alignment); -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); +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 widget_alignment, nk_flags text_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_flags widget_alignment, nk_flags text_alignment); +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 widget_alignment, nk_flags text_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); diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index 930ac33..92f032c 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -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, nk_flags alignment) + const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -51,7 +51,7 @@ nk_draw_checkbox(struct nk_command_buffer *out, text.padding.x = 0; text.padding.y = 0; text.background = style->text_background; - nk_widget_text(out, *label, string, len, &text, alignment, font); + nk_widget_text(out, *label, string, len, &text, text_alignment, font); /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { @@ -69,7 +69,7 @@ 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_flags alignment) + const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -94,7 +94,7 @@ nk_draw_option(struct nk_command_buffer *out, text.padding.x = 0; text.padding.y = 0; text.background = style->text_background; - nk_widget_text(out, *label, string, len, &text, alignment, font); + nk_widget_text(out, *label, string, len, &text, text_alignment, font); /* draw background and cursor */ if (background->type == NK_STYLE_ITEM_COLOR) { @@ -112,7 +112,7 @@ 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) + const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment) { int was_active; struct nk_rect allocated_space; @@ -132,7 +132,7 @@ nk_do_toggle(nk_flags *state, allocated_space = r; - if (alignment & NK_WIDGET_ALIGN_RIGHT) { + if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) { r.x = r.x + r.w - font->height - style->padding.x; r.w = font->height; } @@ -157,14 +157,14 @@ nk_do_toggle(nk_flags *state, label.y = select.y; 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 { + if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) { /* label in front of the selector */ label.x = allocated_space.x; label.w = allocated_space.w - select.w - style->spacing * 2; + } else { + /* label behind the selector */ + label.x = select.x + select.w + style->spacing; + label.w = NK_MAX(r.x + r.w, label.x) - label.x; } /* update selector */ @@ -175,9 +175,9 @@ 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, alignment); + nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font, widget_alignment, text_alignment); } else { - nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, alignment); + nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, widget_alignment, text_alignment); } if (style->draw_end) style->draw_end(out, style->userdata); @@ -189,7 +189,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_flags alignment) +nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) { struct nk_window *win; struct nk_panel *layout; @@ -213,25 +213,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 || state == NK_WIDGET_DISABLED || 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, alignment); + text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font, widget_alignment, text_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, nk_flags alignment) + unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_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, alignment)) + if (nk_check_text(ctx, text, len, old_active, widget_alignment, text_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_flags alignment) +nk_checkbox_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { int old_val; NK_ASSERT(ctx); @@ -239,12 +239,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, alignment); + *active = nk_check_text(ctx, text, len, *active, widget_alignment, text_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, nk_flags alignment) + unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) { nk_bool active; NK_ASSERT(ctx); @@ -253,30 +253,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, alignment)) { + if (nk_checkbox_text(ctx, text, len, &active, widget_alignment, text_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_flags alignment) +NK_API nk_bool nk_check_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_check_text(ctx, label, nk_strlen(label), active, alignment); + return nk_check_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } NK_API unsigned int nk_check_flags_label(struct nk_context *ctx, const char *label, - unsigned int flags, unsigned int value, nk_flags alignment) + unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value, alignment); + return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value, widget_alignment, text_alignment); } -NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags alignment) +NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_checkbox_text(ctx, label, nk_strlen(label), active, alignment); + return nk_checkbox_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label, - unsigned int *flags, unsigned int value, nk_flags alignment) + unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value, alignment); + return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value, widget_alignment, text_alignment); } /*---------------------------------------------------------------- * @@ -284,7 +284,7 @@ NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label * * --------------------------------------------------------------*/ NK_API nk_bool -nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags alignment) +nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment) { struct nk_window *win; struct nk_panel *layout; @@ -308,11 +308,11 @@ 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 || state == NK_WIDGET_DISABLED || 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, alignment); + text, len, NK_TOGGLE_OPTION, &style->option, in, style->font, widget_alignment, text_alignment); return is_active; } NK_API nk_bool -nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags alignment) +nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { int old_value; NK_ASSERT(ctx); @@ -320,17 +320,17 @@ nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active NK_ASSERT(active); if (!ctx || !text || !active) return 0; old_value = *active; - *active = nk_option_text(ctx, text, len, old_value, alignment); + *active = nk_option_text(ctx, text, len, old_value, widget_alignment, text_alignment); return old_value != *active; } NK_API nk_bool -nk_option_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags alignment) +nk_option_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_option_text(ctx, label, nk_strlen(label), active, alignment); + return nk_option_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } NK_API nk_bool -nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags alignment) +nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_radio_text(ctx, label, nk_strlen(label), active, alignment); + return nk_radio_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } From 2a528263928535a02c09ec7dd80bb56e50693484 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Sun, 26 Nov 2023 10:44:37 +0100 Subject: [PATCH 05/16] Removed widget alignment for the draw functions of toggleables --- nuklear.h | 12 ++++++------ src/nuklear_internal.h | 4 ++-- src/nuklear_toggle.c | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/nuklear.h b/nuklear.h index b2a3f51..12696cb 100644 --- a/nuklear.h +++ b/nuklear.h @@ -6078,8 +6078,8 @@ 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_flags widget_alignment, nk_flags text_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_flags widget_alignment, nk_flags text_alignment); +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 text_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_flags text_alignment); 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 widget_alignment, nk_flags text_alignment); /* progress */ @@ -24722,7 +24722,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, nk_flags widget_alignment, nk_flags text_alignment) + const struct nk_user_font *font, nk_flags text_alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -24765,7 +24765,7 @@ 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_flags widget_alignment, nk_flags text_alignment) + const struct nk_user_font *font, nk_flags text_alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -24871,9 +24871,9 @@ 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, widget_alignment, text_alignment); + nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font, text_alignment); } else { - nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, widget_alignment, text_alignment); + nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, text_alignment); } if (style->draw_end) style->draw_end(out, style->userdata); diff --git a/src/nuklear_internal.h b/src/nuklear_internal.h index 31689db..9f20d0d 100644 --- a/src/nuklear_internal.h +++ b/src/nuklear_internal.h @@ -255,8 +255,8 @@ 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_flags widget_alignment, nk_flags text_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_flags widget_alignment, nk_flags text_alignment); +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 text_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_flags text_alignment); 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 widget_alignment, nk_flags text_alignment); /* progress */ diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index 92f032c..9985925 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -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, nk_flags widget_alignment, nk_flags text_alignment) + const struct nk_user_font *font, nk_flags text_alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -69,7 +69,7 @@ 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_flags widget_alignment, nk_flags text_alignment) + const struct nk_user_font *font, nk_flags text_alignment) { const struct nk_style_item *background; const struct nk_style_item *cursor; @@ -175,9 +175,9 @@ 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, widget_alignment, text_alignment); + nk_draw_checkbox(out, *state, style, *active, &label, &select, &cursor, str, len, font, text_alignment); } else { - nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, widget_alignment, text_alignment); + nk_draw_option(out, *state, style, *active, &label, &select, &cursor, str, len, font, text_alignment); } if (style->draw_end) style->draw_end(out, style->userdata); From 6c0f814c4e47d033622011cf3f775682df0fbe73 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Sun, 26 Nov 2023 11:01:02 +0100 Subject: [PATCH 06/16] Applied toggleable alignment to demos --- demo/allegro5/main.c | 4 ++-- demo/d3d11/main.c | 4 ++-- demo/d3d12/main.c | 4 ++-- demo/d3d9/main.c | 4 ++-- demo/gdi/main.c | 4 ++-- demo/gdip/main.c | 4 ++-- demo/glfw_opengl2/main.c | 4 ++-- demo/glfw_opengl3/main.c | 4 ++-- demo/glfw_opengl4/main.c | 4 ++-- demo/glfw_vulkan/main.c | 4 ++-- demo/sdl2surface_rawfb/main.c | 4 ++-- demo/sdl_opengl2/main.c | 4 ++-- demo/sdl_opengl3/main.c | 4 ++-- demo/sdl_opengles2/main.c | 4 ++-- demo/sdl_renderer/main.c | 4 ++-- demo/sfml_opengl2/main.cpp | 4 ++-- demo/sfml_opengl3/main.cpp | 4 ++-- demo/wayland_rawfb/main.c | 4 ++-- demo/x11/main.c | 4 ++-- demo/x11_opengl2/main.c | 4 ++-- demo/x11_opengl3/main.c | 4 ++-- demo/x11_rawfb/main.c | 4 ++-- demo/x11_xft/main.c | 4 ++-- 23 files changed, 46 insertions(+), 46 deletions(-) diff --git a/demo/allegro5/main.c b/demo/allegro5/main.c index ee01de7..ff2228c 100644 --- a/demo/allegro5/main.c +++ b/demo/allegro5/main.c @@ -165,8 +165,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c index 338dde2..63bb495 100644 --- a/demo/d3d11/main.c +++ b/demo/d3d11/main.c @@ -250,8 +250,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/d3d12/main.c b/demo/d3d12/main.c index 57e7bc3..90d8ab9 100644 --- a/demo/d3d12/main.c +++ b/demo/d3d12/main.c @@ -342,8 +342,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/d3d9/main.c b/demo/d3d9/main.c index 638c584..03a9530 100644 --- a/demo/d3d9/main.c +++ b/demo/d3d9/main.c @@ -255,8 +255,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/gdi/main.c b/demo/gdi/main.c index 281f82b..9410e97 100644 --- a/demo/gdi/main.c +++ b/demo/gdi/main.c @@ -164,8 +164,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/gdip/main.c b/demo/gdip/main.c index 7151964..78db5ed 100644 --- a/demo/gdip/main.c +++ b/demo/gdip/main.c @@ -159,8 +159,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/glfw_opengl2/main.c b/demo/glfw_opengl2/main.c index 8d97773..6296a76 100644 --- a/demo/glfw_opengl2/main.c +++ b/demo/glfw_opengl2/main.c @@ -172,8 +172,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/glfw_opengl3/main.c b/demo/glfw_opengl3/main.c index 8eb749d..cbe692e 100644 --- a/demo/glfw_opengl3/main.c +++ b/demo/glfw_opengl3/main.c @@ -158,8 +158,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/glfw_opengl4/main.c b/demo/glfw_opengl4/main.c index 176a1ef..502d1ad 100644 --- a/demo/glfw_opengl4/main.c +++ b/demo/glfw_opengl4/main.c @@ -168,8 +168,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/glfw_vulkan/main.c b/demo/glfw_vulkan/main.c index 555a5aa..0bc17b4 100644 --- a/demo/glfw_vulkan/main.c +++ b/demo/glfw_vulkan/main.c @@ -2148,9 +2148,9 @@ int main(void) { fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); diff --git a/demo/sdl2surface_rawfb/main.c b/demo/sdl2surface_rawfb/main.c index a8b661a..c2238d9 100644 --- a/demo/sdl2surface_rawfb/main.c +++ b/demo/sdl2surface_rawfb/main.c @@ -216,8 +216,8 @@ int main(int argc, char **argv) printf("button pressed\n"); } nk_layout_row_dynamic(&(context->ctx), 40, 2); - if (nk_option_label(&(context->ctx), "easy", op == EASY)) op = EASY; - if (nk_option_label(&(context->ctx), "hard", op == HARD)) op = HARD; + if (nk_option_label(&(context->ctx), "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(&(context->ctx), "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(&(context->ctx), 45, 1); nk_property_int(&(context->ctx), "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/sdl_opengl2/main.c b/demo/sdl_opengl2/main.c index 45c51d2..508d42a 100644 --- a/demo/sdl_opengl2/main.c +++ b/demo/sdl_opengl2/main.c @@ -154,8 +154,8 @@ main(int argc, char *argv[]) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/sdl_opengl3/main.c b/demo/sdl_opengl3/main.c index e039a2f..0483626 100644 --- a/demo/sdl_opengl3/main.c +++ b/demo/sdl_opengl3/main.c @@ -164,8 +164,8 @@ int main(int argc, char *argv[]) if (nk_button_label(ctx, "button")) printf("button pressed!\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/sdl_opengles2/main.c b/demo/sdl_opengles2/main.c index b114159..c527e5f 100644 --- a/demo/sdl_opengles2/main.c +++ b/demo/sdl_opengles2/main.c @@ -128,8 +128,8 @@ MainLoop(void* loopArg){ if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/sdl_renderer/main.c b/demo/sdl_renderer/main.c index 940ea84..a8af16b 100644 --- a/demo/sdl_renderer/main.c +++ b/demo/sdl_renderer/main.c @@ -192,8 +192,8 @@ main(int argc, char *argv[]) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/sfml_opengl2/main.cpp b/demo/sfml_opengl2/main.cpp index 82f8e0f..6594ad3 100644 --- a/demo/sfml_opengl2/main.cpp +++ b/demo/sfml_opengl2/main.cpp @@ -139,8 +139,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/sfml_opengl3/main.cpp b/demo/sfml_opengl3/main.cpp index 22aafcc..8fa6df8 100644 --- a/demo/sfml_opengl3/main.cpp +++ b/demo/sfml_opengl3/main.cpp @@ -146,8 +146,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/wayland_rawfb/main.c b/demo/wayland_rawfb/main.c index cf60eed..baf4cc8 100644 --- a/demo/wayland_rawfb/main.c +++ b/demo/wayland_rawfb/main.c @@ -533,8 +533,8 @@ int main () printf("button pressed\n"); } nk_layout_row_dynamic(&(nk_wayland_ctx.ctx), 30, 2); - if (nk_option_label(&(nk_wayland_ctx.ctx), "easy", op == EASY)) op = EASY; - if (nk_option_label(&(nk_wayland_ctx.ctx), "hard", op == HARD)) op = HARD; + if (nk_option_label(&(nk_wayland_ctx.ctx), "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(&(nk_wayland_ctx.ctx), "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(&(nk_wayland_ctx.ctx), 25, 1); nk_property_int(&(nk_wayland_ctx.ctx), "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/x11/main.c b/demo/x11/main.c index 0d02ad7..4cbf4c4 100644 --- a/demo/x11/main.c +++ b/demo/x11/main.c @@ -192,8 +192,8 @@ main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c index 2dc845e..679f7b1 100644 --- a/demo/x11_opengl2/main.c +++ b/demo/x11_opengl2/main.c @@ -296,8 +296,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c index a4a3008..4553469 100644 --- a/demo/x11_opengl3/main.c +++ b/demo/x11_opengl3/main.c @@ -293,8 +293,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/x11_rawfb/main.c b/demo/x11_rawfb/main.c index 52a1c93..5a19bb3 100644 --- a/demo/x11_rawfb/main.c +++ b/demo/x11_rawfb/main.c @@ -229,8 +229,8 @@ main(void) if (nk_button_label(&rawfb->ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(&rawfb->ctx, 30, 2); - if (nk_option_label(&rawfb->ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(&rawfb->ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(&rawfb->ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(&rawfb->ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(&rawfb->ctx, 25, 1); nk_property_int(&rawfb->ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/x11_xft/main.c b/demo/x11_xft/main.c index 263f43b..b4cc2ca 100644 --- a/demo/x11_xft/main.c +++ b/demo/x11_xft/main.c @@ -196,8 +196,8 @@ main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } From 9614f5f99def2fc73d18f80aa4639cd4c7cdd079 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Sun, 26 Nov 2023 11:04:52 +0100 Subject: [PATCH 07/16] Applied toggleable alignment to example extended --- example/extended.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/example/extended.c b/example/extended.c index 4e1211b..491af60 100644 --- a/example/extended.c +++ b/example/extended.c @@ -201,7 +201,7 @@ grid_demo(struct nk_context *ctx, struct media *media) nk_label(ctx, "Binary:", NK_TEXT_RIGHT); nk_edit_string(ctx, NK_EDIT_FIELD, text[2], &text_len[2], 64, nk_filter_binary); nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT); - nk_checkbox_label(ctx, "Check me", &check); + nk_checkbox_label(ctx, "Check me", &check, NK_WIDGET_LEFT, NK_TEXT_LEFT); nk_label(ctx, "Combobox:", NK_TEXT_RIGHT); if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 25, 1); @@ -433,9 +433,9 @@ basic_demo(struct nk_context *ctx, struct media *media) *------------------------------------------------*/ ui_header(ctx, media, "Checkbox"); ui_widget(ctx, media, 30); - nk_checkbox_label(ctx, "Flag 1", &check0); + nk_checkbox_label(ctx, "Flag 1", &check0, NK_WIDGET_LEFT, NK_TEXT_LEFT); ui_widget(ctx, media, 30); - nk_checkbox_label(ctx, "Flag 2", &check1); + nk_checkbox_label(ctx, "Flag 2", &check1, NK_WIDGET_LEFT, NK_TEXT_LEFT); /*------------------------------------------------ * PROGRESSBAR From aa9959204544f82f4c65c62a86abb701f3326b5a Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Sun, 26 Nov 2023 11:08:05 +0100 Subject: [PATCH 08/16] Applied toggleable alignment to example skinning --- example/skinning.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/example/skinning.c b/example/skinning.c index fab9ce3..fb6c352 100644 --- a/example/skinning.c +++ b/example/skinning.c @@ -754,10 +754,10 @@ int main(int argc, char *argv[]) nk_layout_row_dynamic(&ctx, 20, 1); nk_label(&ctx, "Label", NK_TEXT_LEFT); nk_layout_row_dynamic(&ctx, 30, 2); - nk_check_label(&ctx, "inactive", 0); - nk_check_label(&ctx, "active", 1); - nk_option_label(&ctx, "active", 1); - nk_option_label(&ctx, "inactive", 0); + nk_check_label(&ctx, "inactive", 0, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_check_label(&ctx, "active", 1, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_option_label(&ctx, "active", 1, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_option_label(&ctx, "inactive", 0, NK_WIDGET_LEFT, NK_TEXT_LEFT); nk_layout_row_dynamic(&ctx, 30, 1); nk_slider_int(&ctx, 0, &slider, 16, 1); From 8abee2451313ef58023c028e072f33342bf28366 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Sun, 26 Nov 2023 11:22:28 +0100 Subject: [PATCH 09/16] Added changes to changelog and bumped clib.json --- clib.json | 2 +- src/CHANGELOG | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clib.json b/clib.json index 1cad42b..c9605df 100644 --- a/clib.json +++ b/clib.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "4.11.0", + "version": "5.0.0", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/src/CHANGELOG b/src/CHANGELOG index a4a0ad9..b0376ac 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,6 +7,8 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2023/11/26 (5.0.0) - BREAKING CHANGE: Added alignment to check boxes and radio buttons. They +/// all now require a widget and text alignment parameter. /// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() /// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly From 657e525ff8ac124174d1dcbff1e1e39fa72cef4f Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Sun, 26 Nov 2023 14:29:25 +0100 Subject: [PATCH 10/16] Added all alignments to toggleables --- demo/common/overview.c | 10 ++++---- nuklear.h | 55 +++++++++++++++++++++++++----------------- src/nuklear_toggle.c | 53 +++++++++++++++++++++++----------------- 3 files changed, 69 insertions(+), 49 deletions(-) diff --git a/demo/common/overview.c b/demo/common/overview.c index dff9796..d4c90b1 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -142,7 +142,7 @@ overview(struct nk_context *ctx) { enum options {A,B,C}; static int checkbox_left_text_left; - static int checkbox_left_text_right; + static int checkbox_centered_text_right; static int checkbox_right_text_right; static int checkbox_right_text_left; static int option_left; @@ -213,10 +213,10 @@ overview(struct nk_context *ctx) static const float ratio[] = {120, 150}; nk_layout_row_dynamic(ctx, 0, 1); - nk_checkbox_label(ctx, "Checkbox Left Text Left", &checkbox_left_text_left, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_label(ctx, "Checkbox Left Text Right", &checkbox_left_text_right, NK_WIDGET_LEFT, NK_TEXT_RIGHT); - nk_checkbox_label(ctx, "Checkbox Right Text Right", &checkbox_right_text_right, NK_WIDGET_RIGHT, NK_TEXT_RIGHT); - nk_checkbox_label(ctx, "Checkbox Right Text Left", &checkbox_right_text_left, NK_WIDGET_RIGHT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "CheckLeft TextLeft", &checkbox_left_text_left, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "CheckCenter TextRight", &checkbox_centered_text_right, NK_WIDGET_ALIGN_CENTERED | NK_WIDGET_ALIGN_MIDDLE, NK_TEXT_RIGHT); + nk_checkbox_label(ctx, "CheckRight TextRight", &checkbox_right_text_right, NK_WIDGET_LEFT, NK_TEXT_RIGHT); + nk_checkbox_label(ctx, "CheckRight TextLeft", &checkbox_right_text_left, NK_WIDGET_RIGHT, NK_TEXT_LEFT); nk_layout_row_static(ctx, 30, 80, 3); option_left = nk_option_label(ctx, "optionA", option_left == A, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? A : option_left; diff --git a/nuklear.h b/nuklear.h index 12696cb..4a93bae 100644 --- a/nuklear.h +++ b/nuklear.h @@ -24811,7 +24811,6 @@ nk_do_toggle(nk_flags *state, const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment) { int was_active; - struct nk_rect allocated_space; struct nk_rect bounds; struct nk_rect select; struct nk_rect cursor; @@ -24826,13 +24825,6 @@ 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 (widget_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; @@ -24842,8 +24834,37 @@ nk_do_toggle(nk_flags *state, /* calculate the selector space */ select.w = font->height; select.h = select.w; - select.y = r.y + r.h/2.0f - select.h/2.0f; - select.x = r.x; + + if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) { + select.x = r.x + r.w - font->height; + + /* label in front of the selector */ + label.x = r.x; + label.w = r.w - select.w - style->spacing * 2; + } else if (widget_alignment & NK_WIDGET_ALIGN_CENTERED) { + select.x = (r.x + r.w) / 2; + + /* label in front of selector */ + label.x = r.x; + label.w = r.w / 2 - select.w - style->spacing * 2; + } else { /* Default: NK_WIDGET_ALIGN_LEFT */ + select.x = r.x; + + /* label behind the selector */ + label.x = select.x + select.w + style->spacing; + label.w = NK_MAX(r.x + r.w, label.x) - label.x; + } + + if (widget_alignment & NK_WIDGET_ALIGN_TOP) { + select.y = r.y; + } else if (widget_alignment & NK_WIDGET_ALIGN_BOTTOM) { + select.y = r.y + r.h - select.h - 2 * style->padding.y; + } else { /* Default: NK_WIDGET_ALIGN_MIDDLE */ + select.y = r.y + r.h/2.0f - select.h/2.0f; + } + + label.y = select.y; + label.h = select.w; /* calculate the bounds of the cursor inside the selector */ cursor.x = select.x + style->padding.x + style->border; @@ -24851,18 +24872,6 @@ 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.y = select.y; - label.h = select.w; - if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) { - /* label in front of the selector */ - label.x = allocated_space.x; - label.w = allocated_space.w - select.w - style->spacing * 2; - } else { - /* label behind the selector */ - label.x = select.x + select.w + style->spacing; - label.w = NK_MAX(r.x + r.w, label.x) - label.x; - } - /* update selector */ was_active = *active; *active = nk_toggle_behavior(in, bounds, state, *active); @@ -30013,6 +30022,8 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// +/// - 2023/11/26 (5.0.0) - BREAKING CHANGE: Added alignment to check boxes and radio buttons. They +/// all now require a widget and text alignment parameter. /// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() /// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index 9985925..c4b8159 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -115,7 +115,6 @@ nk_do_toggle(nk_flags *state, const struct nk_user_font *font, nk_flags widget_alignment, nk_flags text_alignment) { int was_active; - struct nk_rect allocated_space; struct nk_rect bounds; struct nk_rect select; struct nk_rect cursor; @@ -130,13 +129,6 @@ 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 (widget_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; @@ -146,8 +138,37 @@ nk_do_toggle(nk_flags *state, /* calculate the selector space */ select.w = font->height; select.h = select.w; - select.y = r.y + r.h/2.0f - select.h/2.0f; - select.x = r.x; + + if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) { + select.x = r.x + r.w - font->height; + + /* label in front of the selector */ + label.x = r.x; + label.w = r.w - select.w - style->spacing * 2; + } else if (widget_alignment & NK_WIDGET_ALIGN_CENTERED) { + select.x = (r.x + r.w) / 2; + + /* label in front of selector */ + label.x = r.x; + label.w = r.w / 2 - select.w - style->spacing * 2; + } else { /* Default: NK_WIDGET_ALIGN_LEFT */ + select.x = r.x; + + /* label behind the selector */ + label.x = select.x + select.w + style->spacing; + label.w = NK_MAX(r.x + r.w, label.x) - label.x; + } + + if (widget_alignment & NK_WIDGET_ALIGN_TOP) { + select.y = r.y; + } else if (widget_alignment & NK_WIDGET_ALIGN_BOTTOM) { + select.y = r.y + r.h - select.h - 2 * style->padding.y; + } else { /* Default: NK_WIDGET_ALIGN_MIDDLE */ + select.y = r.y + r.h/2.0f - select.h/2.0f; + } + + label.y = select.y; + label.h = select.w; /* calculate the bounds of the cursor inside the selector */ cursor.x = select.x + style->padding.x + style->border; @@ -155,18 +176,6 @@ 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.y = select.y; - label.h = select.w; - if (widget_alignment & NK_WIDGET_ALIGN_RIGHT) { - /* label in front of the selector */ - label.x = allocated_space.x; - label.w = allocated_space.w - select.w - style->spacing * 2; - } else { - /* label behind the selector */ - label.x = select.x + select.w + style->spacing; - label.w = NK_MAX(r.x + r.w, label.x) - label.x; - } - /* update selector */ was_active = *active; *active = nk_toggle_behavior(in, bounds, state, *active); From 8af4468cce12acb979024c2778fd07e95a18e6a4 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Sun, 26 Nov 2023 14:45:06 +0100 Subject: [PATCH 11/16] Fixed centered not being quite in the center --- nuklear.h | 4 ++-- src/nuklear_toggle.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nuklear.h b/nuklear.h index 4a93bae..ba03343 100644 --- a/nuklear.h +++ b/nuklear.h @@ -24842,11 +24842,11 @@ nk_do_toggle(nk_flags *state, label.x = r.x; label.w = r.w - select.w - style->spacing * 2; } else if (widget_alignment & NK_WIDGET_ALIGN_CENTERED) { - select.x = (r.x + r.w) / 2; + select.x = r.x + (r.w - select.w) / 2; /* label in front of selector */ label.x = r.x; - label.w = r.w / 2 - select.w - style->spacing * 2; + label.w = (r.w - select.w - style->spacing * 2) / 2; } else { /* Default: NK_WIDGET_ALIGN_LEFT */ select.x = r.x; diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index c4b8159..9cc9271 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -146,11 +146,11 @@ nk_do_toggle(nk_flags *state, label.x = r.x; label.w = r.w - select.w - style->spacing * 2; } else if (widget_alignment & NK_WIDGET_ALIGN_CENTERED) { - select.x = (r.x + r.w) / 2; + select.x = r.x + (r.w - select.w) / 2; /* label in front of selector */ label.x = r.x; - label.w = r.w / 2 - select.w - style->spacing * 2; + label.w = (r.w - select.w - style->spacing * 2) / 2; } else { /* Default: NK_WIDGET_ALIGN_LEFT */ select.x = r.x; From 44bd2385021835b45a1c447aa3e0a9f740ff9de0 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Mon, 27 Nov 2023 16:56:03 +0100 Subject: [PATCH 12/16] Fixed typo --- nuklear.h | 2 +- src/CHANGELOG | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nuklear.h b/nuklear.h index ba03343..c196827 100644 --- a/nuklear.h +++ b/nuklear.h @@ -30022,7 +30022,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2023/11/26 (5.0.0) - BREAKING CHANGE: Added alignment to check boxes and radio buttons. They +/// - 2023/11/26 (5.0.0) - BREAKING CHANGE: Added alignment to checkboxes and radio buttons. They /// all now require a widget and text alignment parameter. /// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() diff --git a/src/CHANGELOG b/src/CHANGELOG index b0376ac..7464b9d 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,7 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2023/11/26 (5.0.0) - BREAKING CHANGE: Added alignment to check boxes and radio buttons. They +/// - 2023/11/26 (5.0.0) - BREAKING CHANGE: Added alignment to checkboxes and radio buttons. They /// all now require a widget and text alignment parameter. /// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() From 9af38697283b2df9b9e360feffdabdb6f7f8215a Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Tue, 28 Nov 2023 09:52:30 +0100 Subject: [PATCH 13/16] Made the PR not break current API --- clib.json | 2 +- demo/allegro5/main.c | 4 +- demo/common/overview.c | 64 ++++++------- demo/d3d11/main.c | 4 +- demo/d3d12/main.c | 4 +- demo/d3d9/main.c | 4 +- demo/gdi/main.c | 4 +- demo/gdip/main.c | 4 +- demo/glfw_opengl2/main.c | 4 +- demo/glfw_opengl3/main.c | 4 +- demo/glfw_opengl4/main.c | 4 +- demo/glfw_vulkan/main.c | 4 +- demo/sdl2surface_rawfb/main.c | 4 +- demo/sdl_opengl2/main.c | 4 +- demo/sdl_opengl3/main.c | 4 +- demo/sdl_opengles2/main.c | 4 +- demo/sdl_renderer/main.c | 4 +- demo/sfml_opengl2/main.cpp | 4 +- demo/sfml_opengl3/main.cpp | 4 +- demo/wayland_rawfb/main.c | 4 +- demo/x11/main.c | 4 +- demo/x11_opengl2/main.c | 4 +- demo/x11_opengl3/main.c | 4 +- demo/x11_rawfb/main.c | 4 +- demo/x11_xft/main.c | 4 +- example/extended.c | 6 +- example/skinning.c | 8 +- nuklear.h | 164 +++++++++++++++++++++++++++------- src/CHANGELOG | 3 +- src/nuklear.h | 23 +++-- src/nuklear_toggle.c | 138 +++++++++++++++++++++++----- 31 files changed, 350 insertions(+), 150 deletions(-) diff --git a/clib.json b/clib.json index c9605df..bf66e59 100644 --- a/clib.json +++ b/clib.json @@ -1,6 +1,6 @@ { "name": "nuklear", - "version": "5.0.0", + "version": "4.12.0", "repo": "Immediate-Mode-UI/Nuklear", "description": "A small ANSI C gui toolkit", "keywords": ["gl", "ui", "toolkit"], diff --git a/demo/allegro5/main.c b/demo/allegro5/main.c index ff2228c..ee01de7 100644 --- a/demo/allegro5/main.c +++ b/demo/allegro5/main.c @@ -165,8 +165,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/common/overview.c b/demo/common/overview.c index d4c90b1..261679c 100644 --- a/demo/common/overview.c +++ b/demo/common/overview.c @@ -43,7 +43,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_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "check", &check); nk_menu_end(ctx); } /* menu #2 */ @@ -102,7 +102,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_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "check", &mcheck); nk_menubar_end(ctx); } @@ -123,15 +123,15 @@ 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_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_flags_label(ctx, "Titlebar", &window_flags, NK_WINDOW_TITLE, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_flags_label(ctx, "Border", &window_flags, NK_WINDOW_BORDER, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_flags_label(ctx, "Resizable", &window_flags, NK_WINDOW_SCALABLE, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_flags_label(ctx, "Movable", &window_flags, NK_WINDOW_MOVABLE, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_flags_label(ctx, "No Scrollbar", &window_flags, NK_WINDOW_NO_SCROLLBAR, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_flags_label(ctx, "Minimizable", &window_flags, NK_WINDOW_MINIMIZABLE, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_flags_label(ctx, "Scale Left", &window_flags, NK_WINDOW_SCALE_LEFT, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_label(ctx, "Disable widgets", &disable_widgets, NK_WIDGET_LEFT, NK_TEXT_LEFT); + 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, "Disable widgets", &disable_widgets); nk_tree_pop(ctx); } @@ -213,20 +213,20 @@ overview(struct nk_context *ctx) static const float ratio[] = {120, 150}; nk_layout_row_dynamic(ctx, 0, 1); - nk_checkbox_label(ctx, "CheckLeft TextLeft", &checkbox_left_text_left, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_label(ctx, "CheckCenter TextRight", &checkbox_centered_text_right, NK_WIDGET_ALIGN_CENTERED | NK_WIDGET_ALIGN_MIDDLE, NK_TEXT_RIGHT); - nk_checkbox_label(ctx, "CheckRight TextRight", &checkbox_right_text_right, NK_WIDGET_LEFT, NK_TEXT_RIGHT); - nk_checkbox_label(ctx, "CheckRight TextLeft", &checkbox_right_text_left, NK_WIDGET_RIGHT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "CheckLeft TextLeft", &checkbox_left_text_left); + nk_checkbox_label_align(ctx, "CheckCenter TextRight", &checkbox_centered_text_right, NK_WIDGET_ALIGN_CENTERED | NK_WIDGET_ALIGN_MIDDLE, NK_TEXT_RIGHT); + nk_checkbox_label_align(ctx, "CheckRight TextRight", &checkbox_right_text_right, NK_WIDGET_LEFT, NK_TEXT_RIGHT); + nk_checkbox_label_align(ctx, "CheckRight TextLeft", &checkbox_right_text_left, NK_WIDGET_RIGHT, NK_TEXT_LEFT); nk_layout_row_static(ctx, 30, 80, 3); - option_left = nk_option_label(ctx, "optionA", option_left == A, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? A : option_left; - option_left = nk_option_label(ctx, "optionB", option_left == B, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? B : option_left; - option_left = nk_option_label(ctx, "optionC", option_left == C, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? C : option_left; + option_left = nk_option_label(ctx, "optionA", option_left == A) ? A : option_left; + option_left = nk_option_label(ctx, "optionB", option_left == B) ? B : option_left; + option_left = nk_option_label(ctx, "optionC", option_left == C) ? C : option_left; nk_layout_row_static(ctx, 30, 80, 3); - option_right = nk_option_label(ctx, "optionA", option_right == A, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? A : option_right; - option_right = nk_option_label(ctx, "optionB", option_right == B, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? B : option_right; - option_right = nk_option_label(ctx, "optionC", option_right == C, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? C : option_right; + option_right = nk_option_label_align(ctx, "optionA", option_right == A, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? A : option_right; + option_right = nk_option_label_align(ctx, "optionB", option_right == B, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? B : option_right; + option_right = nk_option_label_align(ctx, "optionC", option_right == C, NK_WIDGET_RIGHT, NK_TEXT_RIGHT) ? C : option_right; nk_layout_row(ctx, NK_STATIC, 30, 2, ratio); nk_labelf(ctx, NK_TEXT_LEFT, "Slider int"); @@ -263,7 +263,7 @@ overview(struct nk_context *ctx) { static int inactive = 1; nk_layout_row_dynamic(ctx, 30, 1); - nk_checkbox_label(ctx, "Inactive", &inactive, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Inactive", &inactive); nk_layout_row_static(ctx, 30, 80, 1); if (inactive) { @@ -379,8 +379,8 @@ overview(struct nk_context *ctx) #endif nk_layout_row_dynamic(ctx, 25, 2); - col_mode = nk_option_label(ctx, "RGB", col_mode == COL_RGB, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? COL_RGB : col_mode; - col_mode = nk_option_label(ctx, "HSV", col_mode == COL_HSV, NK_WIDGET_LEFT, NK_TEXT_LEFT) ? COL_HSV : col_mode; + col_mode = nk_option_label(ctx, "RGB", col_mode == COL_RGB) ? COL_RGB : col_mode; + col_mode = nk_option_label(ctx, "HSV", col_mode == COL_HSV) ? COL_HSV : col_mode; nk_layout_row_dynamic(ctx, 25, 1); if (col_mode == COL_RGB) { @@ -416,10 +416,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_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_label(ctx, weapons[1], &check_values[1], NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_label(ctx, weapons[2], &check_values[2], NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_label(ctx, weapons[3], &check_values[3], NK_WIDGET_LEFT, NK_TEXT_LEFT); + 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_combo_end(ctx); } @@ -728,7 +728,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_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Menu", &show_menu); 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)) @@ -895,9 +895,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_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_label(ctx, "Border", &group_border, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_checkbox_label(ctx, "No Scrollbar", &group_no_scrollbar, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Titlebar", &group_titlebar); + nk_checkbox_label(ctx, "Border", &group_border); + nk_checkbox_label(ctx, "No Scrollbar", &group_no_scrollbar); nk_layout_row_begin(ctx, NK_STATIC, 22, 3); nk_layout_row_push(ctx, 50); diff --git a/demo/d3d11/main.c b/demo/d3d11/main.c index 63bb495..338dde2 100644 --- a/demo/d3d11/main.c +++ b/demo/d3d11/main.c @@ -250,8 +250,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/d3d12/main.c b/demo/d3d12/main.c index 90d8ab9..57e7bc3 100644 --- a/demo/d3d12/main.c +++ b/demo/d3d12/main.c @@ -342,8 +342,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/d3d9/main.c b/demo/d3d9/main.c index 03a9530..638c584 100644 --- a/demo/d3d9/main.c +++ b/demo/d3d9/main.c @@ -255,8 +255,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/gdi/main.c b/demo/gdi/main.c index 9410e97..281f82b 100644 --- a/demo/gdi/main.c +++ b/demo/gdi/main.c @@ -164,8 +164,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/gdip/main.c b/demo/gdip/main.c index 78db5ed..7151964 100644 --- a/demo/gdip/main.c +++ b/demo/gdip/main.c @@ -159,8 +159,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/glfw_opengl2/main.c b/demo/glfw_opengl2/main.c index 6296a76..8d97773 100644 --- a/demo/glfw_opengl2/main.c +++ b/demo/glfw_opengl2/main.c @@ -172,8 +172,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/glfw_opengl3/main.c b/demo/glfw_opengl3/main.c index cbe692e..8eb749d 100644 --- a/demo/glfw_opengl3/main.c +++ b/demo/glfw_opengl3/main.c @@ -158,8 +158,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/glfw_opengl4/main.c b/demo/glfw_opengl4/main.c index 502d1ad..176a1ef 100644 --- a/demo/glfw_opengl4/main.c +++ b/demo/glfw_opengl4/main.c @@ -168,8 +168,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/glfw_vulkan/main.c b/demo/glfw_vulkan/main.c index 0bc17b4..555a5aa 100644 --- a/demo/glfw_vulkan/main.c +++ b/demo/glfw_vulkan/main.c @@ -2148,9 +2148,9 @@ int main(void) { fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); diff --git a/demo/sdl2surface_rawfb/main.c b/demo/sdl2surface_rawfb/main.c index c2238d9..a8b661a 100644 --- a/demo/sdl2surface_rawfb/main.c +++ b/demo/sdl2surface_rawfb/main.c @@ -216,8 +216,8 @@ int main(int argc, char **argv) printf("button pressed\n"); } nk_layout_row_dynamic(&(context->ctx), 40, 2); - if (nk_option_label(&(context->ctx), "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(&(context->ctx), "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(&(context->ctx), "easy", op == EASY)) op = EASY; + if (nk_option_label(&(context->ctx), "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(&(context->ctx), 45, 1); nk_property_int(&(context->ctx), "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/sdl_opengl2/main.c b/demo/sdl_opengl2/main.c index 508d42a..45c51d2 100644 --- a/demo/sdl_opengl2/main.c +++ b/demo/sdl_opengl2/main.c @@ -154,8 +154,8 @@ main(int argc, char *argv[]) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/sdl_opengl3/main.c b/demo/sdl_opengl3/main.c index 0483626..e039a2f 100644 --- a/demo/sdl_opengl3/main.c +++ b/demo/sdl_opengl3/main.c @@ -164,8 +164,8 @@ int main(int argc, char *argv[]) if (nk_button_label(ctx, "button")) printf("button pressed!\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 22, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/sdl_opengles2/main.c b/demo/sdl_opengles2/main.c index c527e5f..b114159 100644 --- a/demo/sdl_opengles2/main.c +++ b/demo/sdl_opengles2/main.c @@ -128,8 +128,8 @@ MainLoop(void* loopArg){ if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/sdl_renderer/main.c b/demo/sdl_renderer/main.c index a8af16b..940ea84 100644 --- a/demo/sdl_renderer/main.c +++ b/demo/sdl_renderer/main.c @@ -192,8 +192,8 @@ main(int argc, char *argv[]) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/sfml_opengl2/main.cpp b/demo/sfml_opengl2/main.cpp index 6594ad3..82f8e0f 100644 --- a/demo/sfml_opengl2/main.cpp +++ b/demo/sfml_opengl2/main.cpp @@ -139,8 +139,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/sfml_opengl3/main.cpp b/demo/sfml_opengl3/main.cpp index 8fa6df8..22aafcc 100644 --- a/demo/sfml_opengl3/main.cpp +++ b/demo/sfml_opengl3/main.cpp @@ -146,8 +146,8 @@ int main(void) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/wayland_rawfb/main.c b/demo/wayland_rawfb/main.c index baf4cc8..cf60eed 100644 --- a/demo/wayland_rawfb/main.c +++ b/demo/wayland_rawfb/main.c @@ -533,8 +533,8 @@ int main () printf("button pressed\n"); } nk_layout_row_dynamic(&(nk_wayland_ctx.ctx), 30, 2); - if (nk_option_label(&(nk_wayland_ctx.ctx), "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(&(nk_wayland_ctx.ctx), "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(&(nk_wayland_ctx.ctx), "easy", op == EASY)) op = EASY; + if (nk_option_label(&(nk_wayland_ctx.ctx), "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(&(nk_wayland_ctx.ctx), 25, 1); nk_property_int(&(nk_wayland_ctx.ctx), "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/x11/main.c b/demo/x11/main.c index 4cbf4c4..0d02ad7 100644 --- a/demo/x11/main.c +++ b/demo/x11/main.c @@ -192,8 +192,8 @@ main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/x11_opengl2/main.c b/demo/x11_opengl2/main.c index 679f7b1..2dc845e 100644 --- a/demo/x11_opengl2/main.c +++ b/demo/x11_opengl2/main.c @@ -296,8 +296,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/x11_opengl3/main.c b/demo/x11_opengl3/main.c index 4553469..a4a3008 100644 --- a/demo/x11_opengl3/main.c +++ b/demo/x11_opengl3/main.c @@ -293,8 +293,8 @@ int main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); diff --git a/demo/x11_rawfb/main.c b/demo/x11_rawfb/main.c index 5a19bb3..52a1c93 100644 --- a/demo/x11_rawfb/main.c +++ b/demo/x11_rawfb/main.c @@ -229,8 +229,8 @@ main(void) if (nk_button_label(&rawfb->ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(&rawfb->ctx, 30, 2); - if (nk_option_label(&rawfb->ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(&rawfb->ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(&rawfb->ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(&rawfb->ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(&rawfb->ctx, 25, 1); nk_property_int(&rawfb->ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/demo/x11_xft/main.c b/demo/x11_xft/main.c index b4cc2ca..263f43b 100644 --- a/demo/x11_xft/main.c +++ b/demo/x11_xft/main.c @@ -196,8 +196,8 @@ main(void) if (nk_button_label(ctx, "button")) fprintf(stdout, "button pressed\n"); nk_layout_row_dynamic(ctx, 30, 2); - if (nk_option_label(ctx, "easy", op == EASY, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = EASY; - if (nk_option_label(ctx, "hard", op == HARD, NK_WIDGET_LEFT, NK_TEXT_LEFT)) op = HARD; + if (nk_option_label(ctx, "easy", op == EASY)) op = EASY; + if (nk_option_label(ctx, "hard", op == HARD)) op = HARD; nk_layout_row_dynamic(ctx, 25, 1); nk_property_int(ctx, "Compression:", 0, &property, 100, 10, 1); } diff --git a/example/extended.c b/example/extended.c index 491af60..4e1211b 100644 --- a/example/extended.c +++ b/example/extended.c @@ -201,7 +201,7 @@ grid_demo(struct nk_context *ctx, struct media *media) nk_label(ctx, "Binary:", NK_TEXT_RIGHT); nk_edit_string(ctx, NK_EDIT_FIELD, text[2], &text_len[2], 64, nk_filter_binary); nk_label(ctx, "Checkbox:", NK_TEXT_RIGHT); - nk_checkbox_label(ctx, "Check me", &check, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Check me", &check); nk_label(ctx, "Combobox:", NK_TEXT_RIGHT); if (nk_combo_begin_label(ctx, items[selected_item], nk_vec2(nk_widget_width(ctx), 200))) { nk_layout_row_dynamic(ctx, 25, 1); @@ -433,9 +433,9 @@ basic_demo(struct nk_context *ctx, struct media *media) *------------------------------------------------*/ ui_header(ctx, media, "Checkbox"); ui_widget(ctx, media, 30); - nk_checkbox_label(ctx, "Flag 1", &check0, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Flag 1", &check0); ui_widget(ctx, media, 30); - nk_checkbox_label(ctx, "Flag 2", &check1, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_checkbox_label(ctx, "Flag 2", &check1); /*------------------------------------------------ * PROGRESSBAR diff --git a/example/skinning.c b/example/skinning.c index fb6c352..fab9ce3 100644 --- a/example/skinning.c +++ b/example/skinning.c @@ -754,10 +754,10 @@ int main(int argc, char *argv[]) nk_layout_row_dynamic(&ctx, 20, 1); nk_label(&ctx, "Label", NK_TEXT_LEFT); nk_layout_row_dynamic(&ctx, 30, 2); - nk_check_label(&ctx, "inactive", 0, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_check_label(&ctx, "active", 1, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_option_label(&ctx, "active", 1, NK_WIDGET_LEFT, NK_TEXT_LEFT); - nk_option_label(&ctx, "inactive", 0, NK_WIDGET_LEFT, NK_TEXT_LEFT); + nk_check_label(&ctx, "inactive", 0); + nk_check_label(&ctx, "active", 1); + nk_option_label(&ctx, "active", 1); + nk_option_label(&ctx, "inactive", 0); nk_layout_row_dynamic(&ctx, 30, 1); nk_slider_int(&ctx, 0, &slider, 16, 1); diff --git a/nuklear.h b/nuklear.h index c196827..6017837 100644 --- a/nuklear.h +++ b/nuklear.h @@ -3205,23 +3205,30 @@ 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_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_check_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); -NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_checkbox_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); +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 nk_bool nk_check_text_align(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +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_label_align(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active); +NK_API nk_bool nk_checkbox_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +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); /* ============================================================================= * * RADIO BUTTON * * ============================================================================= */ NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_label_align(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_label_align(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_text_align(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment); /* ============================================================================= * * SELECTABLE @@ -24894,7 +24901,35 @@ 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_flags widget_alignment, nk_flags text_alignment) +nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return active; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return active; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || 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, NK_WIDGET_LEFT, NK_TEXT_LEFT); + return active; +} +NK_API nk_bool +nk_check_text_align(struct nk_context *ctx, const char *text, int len, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) { struct nk_window *win; struct nk_panel *layout; @@ -24923,20 +24958,20 @@ nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active, } NK_API unsigned int nk_check_flags_text(struct nk_context *ctx, const char *text, int len, - unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) + unsigned int flags, unsigned int value) { 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, widget_alignment, text_alignment)) + if (nk_check_text(ctx, text, len, old_active)) 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_flags widget_alignment, nk_flags text_alignment) +nk_checkbox_text(struct nk_context *ctx, const char *text, int len, nk_bool *active) { int old_val; NK_ASSERT(ctx); @@ -24944,12 +24979,24 @@ 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, widget_alignment, text_alignment); + *active = nk_check_text(ctx, text, len, *active); + return old_val != *active; +} +NK_API nk_bool +nk_checkbox_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +{ + int old_val; + NK_ASSERT(ctx); + NK_ASSERT(text); + NK_ASSERT(active); + if (!ctx || !text || !active) return 0; + old_val = *active; + *active = nk_check_text_align(ctx, text, len, *active, widget_alignment, text_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, nk_flags widget_alignment, nk_flags text_alignment) + unsigned int *flags, unsigned int value) { nk_bool active; NK_ASSERT(ctx); @@ -24958,30 +25005,34 @@ 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, widget_alignment, text_alignment)) { + if (nk_checkbox_text(ctx, text, len, &active)) { 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_flags widget_alignment, nk_flags text_alignment) +NK_API nk_bool nk_check_label(struct nk_context *ctx, const char *label, nk_bool active) { - return nk_check_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); + return nk_check_text(ctx, label, nk_strlen(label), active); } NK_API unsigned int nk_check_flags_label(struct nk_context *ctx, const char *label, - unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) + unsigned int flags, unsigned int value) { - return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value, widget_alignment, text_alignment); + return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value); } -NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active) { - return nk_checkbox_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); + return nk_checkbox_text(ctx, label, nk_strlen(label), active); +} +NK_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) +{ + return nk_checkbox_text_align(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label, - unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) + unsigned int *flags, unsigned int value) { - return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value, widget_alignment, text_alignment); + return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value); } /*---------------------------------------------------------------- * @@ -24989,7 +25040,35 @@ NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label * * --------------------------------------------------------------*/ NK_API nk_bool -nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment) +nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return is_active; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return (int)state; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || 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, NK_WIDGET_LEFT, NK_TEXT_LEFT); + return is_active; +} +NK_API nk_bool +nk_option_text_align(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment) { struct nk_window *win; struct nk_panel *layout; @@ -25017,7 +25096,7 @@ nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_act return is_active; } NK_API nk_bool -nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active) { int old_value; NK_ASSERT(ctx); @@ -25025,18 +25104,40 @@ nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active NK_ASSERT(active); if (!ctx || !text || !active) return 0; old_value = *active; - *active = nk_option_text(ctx, text, len, old_value, widget_alignment, text_alignment); + *active = nk_option_text(ctx, text, len, old_value); return old_value != *active; } NK_API nk_bool -nk_option_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) +nk_radio_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_option_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); + int old_value; + NK_ASSERT(ctx); + NK_ASSERT(text); + NK_ASSERT(active); + if (!ctx || !text || !active) return 0; + old_value = *active; + *active = nk_option_text_align(ctx, text, len, old_value, widget_alignment, text_alignment); + return old_value != *active; } NK_API nk_bool -nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +nk_option_label(struct nk_context *ctx, const char *label, nk_bool active) { - return nk_radio_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); + return nk_option_text(ctx, label, nk_strlen(label), active); +} +NK_API nk_bool +nk_option_label_align(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) +{ + return nk_option_text_align(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); +} +NK_API nk_bool +nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active) +{ + return nk_radio_text(ctx, label, nk_strlen(label), active); +} +NK_API nk_bool +nk_radio_label_align(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +{ + return nk_radio_text_align(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } @@ -30022,8 +30123,7 @@ nk_tooltipfv(struct nk_context *ctx, const char *fmt, va_list args) /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2023/11/26 (5.0.0) - BREAKING CHANGE: Added alignment to checkboxes and radio buttons. They -/// all now require a widget and text alignment parameter. +/// - 2023/11/26 (4.12.0) - Added an alignment option to checkboxes and radio buttons. /// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() /// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly diff --git a/src/CHANGELOG b/src/CHANGELOG index 7464b9d..b4114f8 100644 --- a/src/CHANGELOG +++ b/src/CHANGELOG @@ -7,8 +7,7 @@ /// - [y]: Minor version with non-breaking API and library changes /// - [z]: Patch version with no direct changes to the API /// -/// - 2023/11/26 (5.0.0) - BREAKING CHANGE: Added alignment to checkboxes and radio buttons. They -/// all now require a widget and text alignment parameter. +/// - 2023/11/26 (4.12.0) - Added an alignment option to checkboxes and radio buttons. /// - 2023/10/11 (4.11.0) - Added nk_widget_disable_begin() and nk_widget_disable_end() /// - 2022/12/23 (4.10.6) - Fix incorrect glyph index in nk_font_bake() /// - 2022/12/17 (4.10.5) - Fix nk_font_bake_pack() using TTC font offset incorrectly diff --git a/src/nuklear.h b/src/nuklear.h index d7a6ad2..ba05180 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -2983,23 +2983,30 @@ 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_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_check_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API unsigned nk_check_flags_label(struct nk_context*, const char*, unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); -NK_API unsigned nk_check_flags_text(struct nk_context*, const char*, int, unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_checkbox_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_checkbox_flags_label(struct nk_context*, const char*, unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment); +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 nk_bool nk_check_text_align(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +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_label_align(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_checkbox_text(struct nk_context*, const char*, int, nk_bool *active); +NK_API nk_bool nk_checkbox_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +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); /* ============================================================================= * * RADIO BUTTON * * ============================================================================= */ NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_label_align(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_label_align(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_text_align(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment); /* ============================================================================= * * SELECTABLE diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index 9cc9271..a7c7f2a 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -198,7 +198,35 @@ 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_flags widget_alignment, nk_flags text_alignment) +nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return active; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return active; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || 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, NK_WIDGET_LEFT, NK_TEXT_LEFT); + return active; +} +NK_API nk_bool +nk_check_text_align(struct nk_context *ctx, const char *text, int len, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) { struct nk_window *win; struct nk_panel *layout; @@ -227,20 +255,20 @@ nk_check_text(struct nk_context *ctx, const char *text, int len, nk_bool active, } NK_API unsigned int nk_check_flags_text(struct nk_context *ctx, const char *text, int len, - unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) + unsigned int flags, unsigned int value) { 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, widget_alignment, text_alignment)) + if (nk_check_text(ctx, text, len, old_active)) 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_flags widget_alignment, nk_flags text_alignment) +nk_checkbox_text(struct nk_context *ctx, const char *text, int len, nk_bool *active) { int old_val; NK_ASSERT(ctx); @@ -248,12 +276,24 @@ 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, widget_alignment, text_alignment); + *active = nk_check_text(ctx, text, len, *active); + return old_val != *active; +} +NK_API nk_bool +nk_checkbox_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +{ + int old_val; + NK_ASSERT(ctx); + NK_ASSERT(text); + NK_ASSERT(active); + if (!ctx || !text || !active) return 0; + old_val = *active; + *active = nk_check_text_align(ctx, text, len, *active, widget_alignment, text_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, nk_flags widget_alignment, nk_flags text_alignment) + unsigned int *flags, unsigned int value) { nk_bool active; NK_ASSERT(ctx); @@ -262,30 +302,34 @@ 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, widget_alignment, text_alignment)) { + if (nk_checkbox_text(ctx, text, len, &active)) { 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_flags widget_alignment, nk_flags text_alignment) +NK_API nk_bool nk_check_label(struct nk_context *ctx, const char *label, nk_bool active) { - return nk_check_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); + return nk_check_text(ctx, label, nk_strlen(label), active); } NK_API unsigned int nk_check_flags_label(struct nk_context *ctx, const char *label, - unsigned int flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) + unsigned int flags, unsigned int value) { - return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value, widget_alignment, text_alignment); + return nk_check_flags_text(ctx, label, nk_strlen(label), flags, value); } -NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +NK_API nk_bool nk_checkbox_label(struct nk_context *ctx, const char *label, nk_bool *active) { - return nk_checkbox_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); + return nk_checkbox_text(ctx, label, nk_strlen(label), active); +} +NK_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) +{ + return nk_checkbox_text_align(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label, - unsigned int *flags, unsigned int value, nk_flags widget_alignment, nk_flags text_alignment) + unsigned int *flags, unsigned int value) { - return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value, widget_alignment, text_alignment); + return nk_checkbox_flags_text(ctx, label, nk_strlen(label), flags, value); } /*---------------------------------------------------------------- * @@ -293,7 +337,35 @@ NK_API nk_bool nk_checkbox_flags_label(struct nk_context *ctx, const char *label * * --------------------------------------------------------------*/ NK_API nk_bool -nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment) +nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_active) +{ + struct nk_window *win; + struct nk_panel *layout; + const struct nk_input *in; + const struct nk_style *style; + + struct nk_rect bounds; + enum nk_widget_layout_states state; + + NK_ASSERT(ctx); + NK_ASSERT(ctx->current); + NK_ASSERT(ctx->current->layout); + if (!ctx || !ctx->current || !ctx->current->layout) + return is_active; + + win = ctx->current; + style = &ctx->style; + layout = win->layout; + + state = nk_widget(&bounds, ctx); + if (!state) return (int)state; + in = (state == NK_WIDGET_ROM || state == NK_WIDGET_DISABLED || 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, NK_WIDGET_LEFT, NK_TEXT_LEFT); + return is_active; +} +NK_API nk_bool +nk_option_text_align(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment) { struct nk_window *win; struct nk_panel *layout; @@ -321,7 +393,7 @@ nk_option_text(struct nk_context *ctx, const char *text, int len, nk_bool is_act return is_active; } NK_API nk_bool -nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active) { int old_value; NK_ASSERT(ctx); @@ -329,17 +401,39 @@ nk_radio_text(struct nk_context *ctx, const char *text, int len, nk_bool *active NK_ASSERT(active); if (!ctx || !text || !active) return 0; old_value = *active; - *active = nk_option_text(ctx, text, len, old_value, widget_alignment, text_alignment); + *active = nk_option_text(ctx, text, len, old_value); return old_value != *active; } NK_API nk_bool -nk_option_label(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) +nk_radio_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) { - return nk_option_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); + int old_value; + NK_ASSERT(ctx); + NK_ASSERT(text); + NK_ASSERT(active); + if (!ctx || !text || !active) return 0; + old_value = *active; + *active = nk_option_text_align(ctx, text, len, old_value, widget_alignment, text_alignment); + return old_value != *active; } NK_API nk_bool -nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +nk_option_label(struct nk_context *ctx, const char *label, nk_bool active) { - return nk_radio_text(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); + return nk_option_text(ctx, label, nk_strlen(label), active); +} +NK_API nk_bool +nk_option_label_align(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment) +{ + return nk_option_text_align(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); +} +NK_API nk_bool +nk_radio_label(struct nk_context *ctx, const char *label, nk_bool *active) +{ + return nk_radio_text(ctx, label, nk_strlen(label), active); +} +NK_API nk_bool +nk_radio_label_align(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment) +{ + return nk_radio_text_align(ctx, label, nk_strlen(label), active, widget_alignment, text_alignment); } From 0a7b4eec8ee7aba11ec2bc46b8581e29a07567cb Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Tue, 28 Nov 2023 09:58:43 +0100 Subject: [PATCH 14/16] Fixed missed removed alignment params --- nuklear.h | 8 ++++---- src/nuklear.h | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/nuklear.h b/nuklear.h index 6017837..bf41ea6 100644 --- a/nuklear.h +++ b/nuklear.h @@ -3221,13 +3221,13 @@ NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsi * RADIO BUTTON * * ============================================================================= */ -NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active); NK_API nk_bool nk_radio_label_align(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active); NK_API nk_bool nk_radio_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active); NK_API nk_bool nk_option_label_align(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active); NK_API nk_bool nk_option_text_align(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment); /* ============================================================================= * diff --git a/src/nuklear.h b/src/nuklear.h index ba05180..7a4514b 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -2999,13 +2999,13 @@ NK_API nk_bool nk_checkbox_flags_text(struct nk_context*, const char*, int, unsi * RADIO BUTTON * * ============================================================================= */ -NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_label(struct nk_context*, const char*, nk_bool *active); NK_API nk_bool nk_radio_label_align(struct nk_context *ctx, const char *label, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_radio_text(struct nk_context*, const char*, int, nk_bool *active); NK_API nk_bool nk_radio_text_align(struct nk_context *ctx, const char *text, int len, nk_bool *active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_label(struct nk_context*, const char*, nk_bool active); NK_API nk_bool nk_option_label_align(struct nk_context *ctx, const char *label, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); -NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active, nk_flags widget_alignment, nk_flags text_alignment); +NK_API nk_bool nk_option_text(struct nk_context*, const char*, int, nk_bool active); NK_API nk_bool nk_option_text_align(struct nk_context *ctx, const char *text, int len, nk_bool is_active, nk_flags widget_alignment, nk_flags text_alignment); /* ============================================================================= * From de3bf05b40b8ebadaa228cee47a35de1cbbfdd26 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Tue, 12 Dec 2023 15:30:13 +0100 Subject: [PATCH 15/16] Replaced tabs with spaces --- src/nuklear_internal.h | 8 ++++---- src/nuklear_toggle.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/nuklear_internal.h b/src/nuklear_internal.h index 9f20d0d..a1c00bc 100644 --- a/src/nuklear_internal.h +++ b/src/nuklear_internal.h @@ -350,14 +350,14 @@ NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_prop #ifndef STBTT_malloc static void* nk_stbtt_malloc(nk_size size, void *user_data) { - struct nk_allocator *alloc = (struct nk_allocator *) user_data; - return alloc->alloc(alloc->userdata, 0, size); + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + return alloc->alloc(alloc->userdata, 0, size); } static void nk_stbtt_free(void *ptr, void *user_data) { - struct nk_allocator *alloc = (struct nk_allocator *) user_data; - alloc->free(alloc->userdata, ptr); + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + alloc->free(alloc->userdata, ptr); } #define STBTT_malloc(x,u) nk_stbtt_malloc(x,u) diff --git a/src/nuklear_toggle.c b/src/nuklear_toggle.c index a7c7f2a..cb9e56a 100644 --- a/src/nuklear_toggle.c +++ b/src/nuklear_toggle.c @@ -47,7 +47,7 @@ nk_draw_checkbox(struct nk_command_buffer *out, text.text = style->text_normal; } - text.text = nk_rgb_factor(text.text, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor); text.padding.x = 0; text.padding.y = 0; text.background = style->text_background; @@ -90,7 +90,7 @@ nk_draw_option(struct nk_command_buffer *out, text.text = style->text_normal; } - text.text = nk_rgb_factor(text.text, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor); text.padding.x = 0; text.padding.y = 0; text.background = style->text_background; From 319f79f177214e582a51871f4068e00108fca313 Mon Sep 17 00:00:00 2001 From: Jacob Ahnstedt Date: Tue, 12 Dec 2023 16:35:38 +0100 Subject: [PATCH 16/16] Built nuklear.h --- nuklear.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/nuklear.h b/nuklear.h index bf41ea6..4abcbc1 100644 --- a/nuklear.h +++ b/nuklear.h @@ -6180,14 +6180,14 @@ NK_LIB void nk_property(struct nk_context *ctx, const char *name, struct nk_prop #ifndef STBTT_malloc static void* nk_stbtt_malloc(nk_size size, void *user_data) { - struct nk_allocator *alloc = (struct nk_allocator *) user_data; - return alloc->alloc(alloc->userdata, 0, size); + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + return alloc->alloc(alloc->userdata, 0, size); } static void nk_stbtt_free(void *ptr, void *user_data) { - struct nk_allocator *alloc = (struct nk_allocator *) user_data; - alloc->free(alloc->userdata, ptr); + struct nk_allocator *alloc = (struct nk_allocator *) user_data; + alloc->free(alloc->userdata, ptr); } #define STBTT_malloc(x,u) nk_stbtt_malloc(x,u) @@ -24750,7 +24750,7 @@ nk_draw_checkbox(struct nk_command_buffer *out, text.text = style->text_normal; } - text.text = nk_rgb_factor(text.text, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor); text.padding.x = 0; text.padding.y = 0; text.background = style->text_background; @@ -24793,7 +24793,7 @@ nk_draw_option(struct nk_command_buffer *out, text.text = style->text_normal; } - text.text = nk_rgb_factor(text.text, style->color_factor); + text.text = nk_rgb_factor(text.text, style->color_factor); text.padding.x = 0; text.padding.y = 0; text.background = style->text_background;