Skip to content

Commit

Permalink
Added additional button text alignments
Browse files Browse the repository at this point in the history
  • Loading branch information
rswinkle committed Mar 11, 2020
1 parent 58a46db commit 6d34a41
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions demo/style_configurator.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,45 @@ style_button(struct nk_context* ctx, struct nk_style_button* out_style, struct n
style_vec2(ctx, "Image Padding:", &button.image_padding);
style_vec2(ctx, "Touch Padding:", &button.touch_padding);

/*
enum nk_text_align {
NK_TEXT_ALIGN_LEFT = 0x01,
NK_TEXT_ALIGN_CENTERED = 0x02,
NK_TEXT_ALIGN_RIGHT = 0x04,
NK_TEXT_ALIGN_TOP = 0x08,
NK_TEXT_ALIGN_MIDDLE = 0x10,
NK_TEXT_ALIGN_BOTTOM = 0x20
const char* alignments[] =
{
"LEFT",
"CENTERED",
"RIGHT",
"TOP LEFT",
"TOP CENTERED",
"TOP_RIGHT",
"BOTTOM LEFT",
"BOTTOM CENTERED",
"BOTTOM RIGHT"
};
enum nk_text_alignment {
NK_TEXT_LEFT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_LEFT,
NK_TEXT_CENTERED = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_CENTERED,
NK_TEXT_RIGHT = NK_TEXT_ALIGN_MIDDLE|NK_TEXT_ALIGN_RIGHT

#define TOP_LEFT NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_LEFT
#define TOP_CENTER NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_CENTERED
#define TOP_RIGHT NK_TEXT_ALIGN_TOP|NK_TEXT_ALIGN_RIGHT
#define BOTTOM_LEFT NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_LEFT
#define BOTTOM_CENTER NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_CENTERED
#define BOTTOM_RIGHT NK_TEXT_ALIGN_BOTTOM|NK_TEXT_ALIGN_RIGHT

int aligns[] =
{
NK_TEXT_LEFT,
NK_TEXT_CENTERED,
NK_TEXT_RIGHT,
TOP_LEFT,
TOP_CENTER,
TOP_RIGHT,
BOTTOM_LEFT,
BOTTOM_CENTER,
BOTTOM_RIGHT
};
*/
// TODO support combining with TOP/MIDDLE/BOTTOM .. separate combo?
const char* alignments[] = { "LEFT", "CENTERED", "RIGHT" };
int aligns[3] = { NK_TEXT_LEFT, NK_TEXT_CENTERED, NK_TEXT_RIGHT };

int cur_align;
if (button.text_alignment == NK_TEXT_LEFT) {
cur_align = 0;
} else if (button.text_alignment == NK_TEXT_CENTERED) {
cur_align = 1;
} else {
cur_align = 2;
for (int i=0; i<NK_LEN(aligns); ++i) {
if (button.text_alignment == aligns[i]) {
cur_align = i;
break;
}
}
nk_label(ctx, "Text Alignment:", NK_TEXT_LEFT);
cur_align = nk_combo(ctx, alignments, NK_LEN(alignments), cur_align, 25, nk_vec2(200,200));
Expand Down Expand Up @@ -363,7 +377,6 @@ style_scrollbars(struct nk_context* ctx, struct nk_style_scrollbar* out_style, s

//nk_layout_row_dynamic(ctx, 30, 1);
if (nk_tree_push(ctx, NK_TREE_TAB, "Scrollbar Buttons", NK_MINIMIZED)) {
// TODO best way to handle correctly with duplicate styles
struct nk_style_button* dups[3] = { &ctx->style.scrollh.dec_button,
&ctx->style.scrollv.inc_button,
&ctx->style.scrollv.dec_button };
Expand Down Expand Up @@ -407,9 +420,6 @@ style_edit(struct nk_context* ctx, struct nk_style_edit* out_style)
style_vec2(ctx, "Scrollbar Size:", &edit.scrollbar_size);
style_vec2(ctx, "Padding:", &edit.padding);

// TODO subtree?
//edit->scrollbar = style->scrollv;

nk_property_float(ctx, "#Row Padding:", -100.0f, &edit.row_padding, 100.0f, 1,0.5f);
nk_property_float(ctx, "#Cursor Size:", -100.0f, &edit.cursor_size, 100.0f, 1,0.5f);
nk_property_float(ctx, "#Border:", -100.0f, &edit.border, 100.0f, 1,0.5f);
Expand Down Expand Up @@ -572,6 +582,7 @@ style_window_header(struct nk_context* ctx, struct nk_style_window_header* out_s
nk_layout_row_dynamic(ctx, 30, 2);
nk_label(ctx, "Button Alignment:", NK_TEXT_LEFT);
header.align = nk_combo(ctx, alignments, NUM_ALIGNS, header.align, 25, nk_vec2(200,200));
#undef NUM_ALIGNS

nk_label(ctx, "Close Symbol:", NK_TEXT_LEFT);
header.close_symbol = nk_combo(ctx, symbols, NK_SYMBOL_MAX, header.close_symbol, 25, nk_vec2(200,200));
Expand Down

0 comments on commit 6d34a41

Please sign in to comment.