fixed menu text symbol/icon button

This commit is contained in:
vurtun 2015-12-06 20:35:18 +01:00
parent 80faad49fe
commit 37df97bee1
2 changed files with 57 additions and 26 deletions

View File

@ -24,7 +24,6 @@ struct demo {
struct zr_window metrics; struct zr_window metrics;
enum theme theme; enum theme theme;
size_t w, h; size_t w, h;
}; };
static void static void
@ -64,7 +63,8 @@ zr_labelf(struct zr_context *panel, enum zr_text_align align, const char *fmt, .
} }
static int static int
show_test_window(struct zr_window *window, struct zr_style *config, enum theme *theme) show_test_window(struct zr_window *window, struct zr_style *config, enum theme *theme,
struct demo *demo)
{ {
zr_flags ret; zr_flags ret;
struct zr_context layout; struct zr_context layout;
@ -121,36 +121,66 @@ show_test_window(struct zr_window *window, struct zr_style *config, enum theme *
if (show_menu) if (show_menu)
{ {
/* menubar */ /* menubar */
enum menu_states {MENU_DEFAULT, MENU_TEST};
struct zr_context menu; struct zr_context menu;
static int file_state = ZR_MINIMIZED; static int file_state = ZR_MINIMIZED;
static zr_size mprog = 60; static zr_size mprog = 60;
static int mslider = 10; static int mslider = 10;
static int mcheck = zr_true; static int mcheck = zr_true;
static int menu_state = MENU_DEFAULT;
zr_menubar_begin(&layout); zr_menubar_begin(&layout);
zr_layout_row_begin(&layout, ZR_STATIC, 25, 2); zr_layout_row_begin(&layout, ZR_STATIC, 25, 2);
zr_layout_row_push(&layout, 45); zr_layout_row_push(&layout, 45);
zr_menu_begin(&layout, &menu, "MENU", 100, &file_state); zr_menu_begin(&layout, &menu, "MENU", 120, &file_state);
{ {
static size_t prog = 40;
static int slider = 10;
static int check = zr_true;
zr_layout_row_dynamic(&menu, 25, 1); zr_layout_row_dynamic(&menu, 25, 1);
zr_progress(&menu, &prog, 100, ZR_MODIFIABLE); switch (menu_state) {
zr_slider_int(&menu, 0, &slider, 16, 1); default:
zr_checkbox(&menu, "check", &check); case MENU_DEFAULT: {
if (zr_menu_item(&menu, ZR_TEXT_CENTERED, "Hide")) { static size_t prog = 40;
show_menu = zr_false; static int slider = 10;
zr_menu_close(&menu, &file_state); static int check = zr_true;
} zr_progress(&menu, &prog, 100, ZR_MODIFIABLE);
if (zr_menu_item(&menu, ZR_TEXT_CENTERED, "About")) { zr_slider_int(&menu, 0, &slider, 16, 1);
show_app_about = zr_true; zr_checkbox(&menu, "check", &check);
zr_menu_close(&menu, &file_state); if (zr_menu_item(&menu, ZR_TEXT_CENTERED, "Hide")) {
} show_menu = zr_false;
if (zr_menu_item(&menu, ZR_TEXT_CENTERED, "Quit")) { zr_menu_close(&menu, &file_state);
show_close_popup = zr_true; }
zr_menu_close(&menu, &file_state); if (zr_menu_item(&menu, ZR_TEXT_CENTERED, "About")) {
show_app_about = zr_true;
zr_menu_close(&menu, &file_state);
}
if (zr_menu_item_symbol(&menu, ZR_SYMBOL_TRIANGLE_RIGHT, "Windows", ZR_TEXT_LEFT))
menu_state = MENU_TEST;
if (zr_menu_item(&menu, ZR_TEXT_CENTERED, "Quit")) {
show_close_popup = zr_true;
zr_menu_close(&menu, &file_state);
}
} break;
case MENU_TEST: {
if (zr_menu_item_symbol(&menu, (demo->sub.flags & ZR_WINDOW_HIDDEN)?
ZR_SYMBOL_RECT : ZR_SYMBOL_RECT_FILLED, "Demo", ZR_TEXT_RIGHT)) {
menu_state = MENU_DEFAULT;
if (demo->sub.flags & ZR_WINDOW_HIDDEN)
demo->sub.flags &= ~(unsigned)ZR_WINDOW_HIDDEN;
else demo->sub.flags |= ZR_WINDOW_HIDDEN;
zr_menu_close(&menu, &file_state);
}
if (zr_menu_item_symbol(&menu, (demo->metrics.flags & ZR_WINDOW_HIDDEN)?
ZR_SYMBOL_RECT : ZR_SYMBOL_RECT_FILLED, "Metrics", ZR_TEXT_RIGHT)) {
menu_state = MENU_DEFAULT;
if (demo->metrics.flags & ZR_WINDOW_HIDDEN)
demo->metrics.flags &= ~(unsigned)ZR_WINDOW_HIDDEN;
else demo->metrics.flags |= ZR_WINDOW_HIDDEN;
zr_menu_close(&menu, &file_state);
}
if (zr_menu_item_symbol(&menu, ZR_SYMBOL_TRIANGLE_LEFT, "BACK", ZR_TEXT_RIGHT))
menu_state = MENU_DEFAULT;
} break;
} }
} }
zr_menu_end(&layout, &menu); zr_menu_end(&layout, &menu);
@ -1025,11 +1055,11 @@ init_demo(struct demo *gui)
&gui->queue, &gui->config_black, &gui->input); &gui->queue, &gui->config_black, &gui->input);
zr_window_init(&gui->sub, zr_rect(400, 50, 220, 180), zr_window_init(&gui->sub, zr_rect(400, 50, 220, 180),
ZR_WINDOW_BORDER|ZR_WINDOW_MOVEABLE|ZR_WINDOW_SCALEABLE| ZR_WINDOW_BORDER|ZR_WINDOW_MOVEABLE|ZR_WINDOW_SCALEABLE|
ZR_WINDOW_CLOSEABLE|ZR_WINDOW_MINIMIZABLE, ZR_WINDOW_CLOSEABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_HIDDEN,
&gui->queue, &gui->config_black, &gui->input); &gui->queue, &gui->config_black, &gui->input);
zr_window_init(&gui->metrics, zr_rect(200, 400, 250, 300), zr_window_init(&gui->metrics, zr_rect(200, 400, 250, 300),
ZR_WINDOW_BORDER|ZR_WINDOW_MOVEABLE|ZR_WINDOW_SCALEABLE| ZR_WINDOW_BORDER|ZR_WINDOW_MOVEABLE|ZR_WINDOW_SCALEABLE|
ZR_WINDOW_CLOSEABLE|ZR_WINDOW_MINIMIZABLE, ZR_WINDOW_CLOSEABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_HIDDEN,
&gui->queue, &gui->config_black, &gui->input); &gui->queue, &gui->config_black, &gui->input);
} }
@ -1039,7 +1069,7 @@ run_demo(struct demo *gui)
{ {
struct zr_context layout; struct zr_context layout;
struct zr_style *current = (gui->theme == THEME_BLACK) ? &gui->config_black : &gui->config_white; struct zr_style *current = (gui->theme == THEME_BLACK) ? &gui->config_black : &gui->config_white;
gui->running = show_test_window(&gui->panel, current, &gui->theme); gui->running = show_test_window(&gui->panel, current, &gui->theme, gui);
/* ussage example */ /* ussage example */
gui->sub.style = current; gui->sub.style = current;

View File

@ -4574,7 +4574,7 @@ zr_do_button_text_symbol(enum zr_widget_states *state,
tri.x = (r.x + r.w) - (2 * b->base.padding.x + tri.w); tri.x = (r.x + r.w) - (2 * b->base.padding.x + tri.w);
tri.x = MAX(tri.x, 0); tri.x = MAX(tri.x, 0);
} else tri.x = r.x + 2 * b->base.padding.x; } else tri.x = r.x + 2 * b->base.padding.x;
zr_draw_symbol(out, symbol, tri, background, color, b->base.border_width, f); zr_draw_symbol(out, symbol, tri, background, color, 1.0f, f);
return ret; return ret;
} }
@ -5241,8 +5241,7 @@ zr_edit_box_handle_input(struct zr_edit_box *box, const struct zr_input *in, int
box->cursor = min; box->cursor = min;
} }
if (enter) zr_edit_box_add(box, "\n", 1); if (enter) zr_edit_box_add(box, "\n", 1);
else if (tab) else if (tab) zr_edit_box_add(box, " ", 4);
zr_edit_box_add(box, " ", 4);
else zr_edit_box_buffer_input(box, in); else zr_edit_box_buffer_input(box, in);
box->sel.begin = box->cursor; box->sel.begin = box->cursor;
box->sel.end = box->cursor; box->sel.end = box->cursor;
@ -8884,6 +8883,7 @@ zr_contextual_button_symbol(struct zr_context *layout, enum zr_symbol symbol,
i = (state == ZR_WIDGET_ROM || layout->flags & ZR_WINDOW_ROM) ? 0 : layout->input; i = (state == ZR_WIDGET_ROM || layout->flags & ZR_WINDOW_ROM) ? 0 : layout->input;
config = layout->style; config = layout->style;
button.alignment = ZR_TEXT_CENTERED;
button.base.border_width = 0; button.base.border_width = 0;
button.base.normal = config->colors[ZR_COLOR_WINDOW]; button.base.normal = config->colors[ZR_COLOR_WINDOW];
button.base.border = config->colors[ZR_COLOR_WINDOW]; button.base.border = config->colors[ZR_COLOR_WINDOW];
@ -8910,6 +8910,7 @@ zr_contextual_button_icon(struct zr_context *layout, struct zr_image img,
i = (state == ZR_WIDGET_ROM || layout->flags & ZR_WINDOW_ROM) ? 0 : layout->input; i = (state == ZR_WIDGET_ROM || layout->flags & ZR_WINDOW_ROM) ? 0 : layout->input;
config = layout->style; config = layout->style;
button.alignment = ZR_TEXT_CENTERED;
button.base.border_width = 0; button.base.border_width = 0;
button.base.normal = config->colors[ZR_COLOR_WINDOW]; button.base.normal = config->colors[ZR_COLOR_WINDOW];
button.base.border = config->colors[ZR_COLOR_WINDOW]; button.base.border = config->colors[ZR_COLOR_WINDOW];