Added option alignment right

This commit is contained in:
Jacob Ahnstedt 2023-11-24 16:33:16 +01:00
parent f187c39283
commit e782760da3
5 changed files with 48 additions and 47 deletions

View File

@ -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) {

View File

@ -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);
}

View File

@ -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

View File

@ -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 */

View File

@ -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);
}