[zr] add menu bar

This commit is contained in:
radius 2016-03-01 23:19:36 -05:00
parent 0b78b07573
commit 1b1b59692b
3 changed files with 103 additions and 27 deletions

View File

@ -11035,6 +11035,47 @@ zr_menu_text_begin(struct zr_context *ctx, struct zr_panel *layout,
return zr_menu_begin(layout, ctx, win, title, is_clicked, header, width); return zr_menu_begin(layout, ctx, win, title, is_clicked, header, width);
} }
int
zr_menu_text_begin_align(struct zr_context *ctx, struct zr_panel *layout,
const char *title, float width, int horizontal_alignment, int vertical_alignment)
{
struct zr_window *win;
const struct zr_input *in;
struct zr_rect header;
int is_clicked = zr_false;
enum zr_widget_status state;
ZR_ASSERT(ctx);
ZR_ASSERT(ctx->current);
ZR_ASSERT(ctx->current->layout);
if (!ctx || !ctx->current || !ctx->current->layout)
return 0;
{
/* execute menu text button for open/closing the popup */
struct zr_button_text button;
zr_zero(&button, sizeof(button));
if (!zr_button(&button.base, &header, ctx, ZR_BUTTON_NORMAL))
return 0;
win = ctx->current;
button.base.rounding = 0;
button.base.border_width = 0;
button.base.border = ctx->style.colors[ZR_COLOR_WINDOW];
button.base.normal = ctx->style.colors[ZR_COLOR_WINDOW];
button.base.active = ctx->style.colors[ZR_COLOR_WINDOW];
button.alignment = horizontal_alignment|vertical_alignment;
button.normal = ctx->style.colors[ZR_COLOR_TEXT];
button.active = ctx->style.colors[ZR_COLOR_TEXT];
button.hover = ctx->style.colors[ZR_COLOR_TEXT];
in = (win->layout->flags & ZR_WINDOW_ROM) ? 0: &ctx->input;
if (zr_do_button_text(&state, &win->buffer, header,
title, ZR_BUTTON_DEFAULT, &button, in, &ctx->style.font))
is_clicked = zr_true;
}
return zr_menu_begin(layout, ctx, win, title, is_clicked, header, width);
}
int int
zr_menu_icon_begin(struct zr_context *ctx, struct zr_panel *layout, zr_menu_icon_begin(struct zr_context *ctx, struct zr_panel *layout,
const char *id, struct zr_image img, float width) const char *id, struct zr_image img, float width)

View File

@ -1611,6 +1611,9 @@ void zr_menubar_end(struct zr_context*);
int zr_menu_text_begin(struct zr_context*, struct zr_panel*, int zr_menu_text_begin(struct zr_context*, struct zr_panel*,
const char *title, float width); const char *title, float width);
int zr_menu_text_begin_align(struct zr_context*, struct zr_panel*,
const char *title, float width,
int horizontal_alignment, int vertical_alignment);
int zr_menu_icon_begin(struct zr_context*, struct zr_panel*, const char *id, int zr_menu_icon_begin(struct zr_context*, struct zr_panel*, const char *id,
struct zr_image, float width); struct zr_image, float width);
int zr_menu_symbol_begin(struct zr_context*, struct zr_panel*, const char *id, int zr_menu_symbol_begin(struct zr_context*, struct zr_panel*, const char *id,

View File

@ -158,7 +158,7 @@ static void zrmenu_set_style(struct zr_context *ctx, enum zr_theme theme)
ctx->style.colors[ZR_COLOR_TEXT_ACTIVE] = zr_rgba(200, 200, 200, 255); ctx->style.colors[ZR_COLOR_TEXT_ACTIVE] = zr_rgba(200, 200, 200, 255);
ctx->style.colors[ZR_COLOR_WINDOW] = zr_rgba(202, 212, 214, 215); ctx->style.colors[ZR_COLOR_WINDOW] = zr_rgba(202, 212, 214, 215);
ctx->style.colors[ZR_COLOR_HEADER] = zr_rgba(137, 182, 224, 220); ctx->style.colors[ZR_COLOR_HEADER] = zr_rgba(137, 182, 224, 220);
ctx->style.colors[ZR_COLOR_BORDER] = zr_rgba(140, 159, 173, 255); ctx->style.colors[ZR_COLOR_BORDER] = zr_rgba(140, 159, 173, 0);
ctx->style.colors[ZR_COLOR_BUTTON] = zr_rgba(137, 182, 224, 255); ctx->style.colors[ZR_COLOR_BUTTON] = zr_rgba(137, 182, 224, 255);
ctx->style.colors[ZR_COLOR_BUTTON_HOVER] = zr_rgba(142, 187, 229, 255); ctx->style.colors[ZR_COLOR_BUTTON_HOVER] = zr_rgba(142, 187, 229, 255);
ctx->style.colors[ZR_COLOR_BUTTON_ACTIVE] = zr_rgba(147, 192, 234, 255); ctx->style.colors[ZR_COLOR_BUTTON_ACTIVE] = zr_rgba(147, 192, 234, 255);
@ -204,8 +204,8 @@ static void zrmenu_set_style(struct zr_context *ctx, enum zr_theme theme)
ctx->style.colors[ZR_COLOR_TEXT_HOVERING] = zr_rgba(195, 195, 195, 255); ctx->style.colors[ZR_COLOR_TEXT_HOVERING] = zr_rgba(195, 195, 195, 255);
ctx->style.colors[ZR_COLOR_TEXT_ACTIVE] = zr_rgba(200, 200, 200, 255); ctx->style.colors[ZR_COLOR_TEXT_ACTIVE] = zr_rgba(200, 200, 200, 255);
ctx->style.colors[ZR_COLOR_WINDOW] = zr_rgba(45, 53, 56, 215); ctx->style.colors[ZR_COLOR_WINDOW] = zr_rgba(45, 53, 56, 215);
ctx->style.colors[ZR_COLOR_HEADER] = zr_rgba(46, 46, 46, 220); ctx->style.colors[ZR_COLOR_HEADER] = zr_rgba(46, 46, 46, 255);
ctx->style.colors[ZR_COLOR_BORDER] = zr_rgba(46, 46, 46, 255); ctx->style.colors[ZR_COLOR_BORDER] = zr_rgba(46, 46, 46, 0);
ctx->style.colors[ZR_COLOR_BUTTON] = zr_rgba(48, 83, 111, 255); ctx->style.colors[ZR_COLOR_BUTTON] = zr_rgba(48, 83, 111, 255);
ctx->style.colors[ZR_COLOR_BUTTON_HOVER] = zr_rgba(53, 88, 116, 255); ctx->style.colors[ZR_COLOR_BUTTON_HOVER] = zr_rgba(53, 88, 116, 255);
ctx->style.colors[ZR_COLOR_BUTTON_ACTIVE] = zr_rgba(58, 93, 121, 255); ctx->style.colors[ZR_COLOR_BUTTON_ACTIVE] = zr_rgba(58, 93, 121, 255);
@ -249,13 +249,67 @@ static void zrmenu_set_style(struct zr_context *ctx, enum zr_theme theme)
} }
} }
static void zrmenu_wnd_main(struct zr_context *ctx, int width, int height, struct zrmenu *gui)
{
settings_t *settings = config_get_ptr();
struct zr_panel layout;
if (zr_begin(ctx, &layout, "", zr_rect(-1, -1, width + 1, height + 1),
ZR_WINDOW_NO_SCROLLBAR))
{
/* context menu */
struct zr_panel node, context_menu;
if (zr_contextual_begin(ctx, &context_menu, 0, zr_vec2(100, 220), zr_window_get_bounds(ctx))) {
zr_layout_row_dynamic(ctx, 25, 1);
if (zr_contextual_item(ctx, "Test 1", ZR_TEXT_CENTERED))
printf("test \n");
if (zr_contextual_item(ctx, "Test 2",ZR_TEXT_CENTERED))
printf("test \n");
zr_contextual_end(ctx);
}
/* main menu */
struct zr_panel menu;
zr_menubar_begin(ctx);
zr_layout_row_begin(ctx, ZR_STATIC, 25, 4);
zr_layout_row_push(ctx, 100);
if (zr_menu_text_begin_align(ctx, &menu, "Menu", 120, ZR_TEXT_LEFT, ZR_TEXT_MIDDLE))
{
zr_layout_row_dynamic(ctx, 25, 1);
if (zr_menu_item(ctx, ZR_TEXT_LEFT, "Test"))
printf("test \n");
if (zr_menu_item(ctx, ZR_TEXT_LEFT, "About"))
printf("test \n");
if (zr_menu_item(ctx, ZR_TEXT_LEFT, "Exit"))
printf("test \n");
zr_menu_end(ctx);
}
if (zr_menu_text_begin_align(ctx, &menu, "Window", 120, ZR_TEXT_LEFT, ZR_TEXT_MIDDLE))
{
zr_layout_row_dynamic(ctx, 25, 1);
if (zr_menu_item(ctx, ZR_TEXT_LEFT, "Test"))
printf("test \n");
zr_menu_end(ctx);
}
zr_layout_row_push(ctx, 60);
zr_menubar_end(ctx);
}
zr_end(ctx);
}
static int zrmenu_wnd_control(struct zr_context *ctx, static int zrmenu_wnd_control(struct zr_context *ctx,
int width, int height, struct zrmenu *gui) int width, int height, struct zrmenu *gui)
{ {
int i; int i;
struct zr_panel layout; struct zr_panel layout;
if (zr_begin(ctx, &layout, "Control", zr_rect(900, 10, 350, 520), if (zr_begin(ctx, &layout, "Control", zr_rect(900, 60, 350, 520),
ZR_WINDOW_CLOSABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_MOVABLE| ZR_WINDOW_CLOSABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_MOVABLE|
ZR_WINDOW_SCALABLE|ZR_WINDOW_BORDER)) ZR_WINDOW_SCALABLE|ZR_WINDOW_BORDER))
{ {
@ -346,7 +400,7 @@ static void zrmenu_wnd_demo(struct zr_context *ctx, int width, int height, struc
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
struct zr_panel layout; struct zr_panel layout;
if (zr_begin(ctx, &layout, "Demo Window", zr_rect(10, 10, width/2, 400), if (zr_begin(ctx, &layout, "Demo Window", zr_rect(10, 90, 500, 400),
ZR_WINDOW_CLOSABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_MOVABLE| ZR_WINDOW_CLOSABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_MOVABLE|
ZR_WINDOW_SCALABLE|ZR_WINDOW_BORDER)) ZR_WINDOW_SCALABLE|ZR_WINDOW_BORDER))
{ {
@ -392,28 +446,6 @@ static void zrmenu_wnd_demo(struct zr_context *ctx, int width, int height, struc
zr_end(ctx); zr_end(ctx);
} }
static void zrmenu_wnd_main(struct zr_context *ctx, int width, int height, struct zrmenu *gui)
{
settings_t *settings = config_get_ptr();
struct zr_panel layout;
if (zr_begin(ctx, &layout, "", zr_rect(0, 0, width, height),
ZR_WINDOW_MINIMIZABLE))
{
struct zr_panel node, menu;
/* context menu */
if (zr_contextual_begin(ctx, &menu, 0, zr_vec2(100, 220), zr_window_get_bounds(ctx))) {
zr_layout_row_dynamic(ctx, 25, 1);
if (zr_contextual_item(ctx, "Test 1", ZR_TEXT_CENTERED))
printf("test \n");
if (zr_contextual_item(ctx, "Test 2",ZR_TEXT_CENTERED))
printf("test \n");
zr_contextual_end(ctx);
}
}
zr_end(ctx);
}
static void zrmenu_frame(struct zrmenu *gui, int width, int height) static void zrmenu_frame(struct zrmenu *gui, int width, int height)
{ {
struct zr_context *ctx = &gui->ctx; struct zr_context *ctx = &gui->ctx;