changed menu api
This commit is contained in:
parent
4bf1e4d0ca
commit
3a48acfe69
48
demo/demo.c
48
demo/demo.c
|
@ -758,40 +758,26 @@ run_demo(struct demo_gui *gui)
|
|||
/* menubar */
|
||||
zr_menubar_begin(&layout);
|
||||
{
|
||||
zr_size i = 0;
|
||||
zr_layout_row_begin(&layout, ZR_STATIC, 18, 2);
|
||||
{
|
||||
zr_int sel;
|
||||
zr_layout_row_push(&layout, config->font.width(config->font.userdata, "__FILE__", 8));
|
||||
sel = zr_menu(&layout, "FILE", file_items, LEN(file_items), 25, 100,
|
||||
&state->file_open);
|
||||
switch (sel) {
|
||||
case MENU_FILE_OPEN:
|
||||
fprintf(stdout, "[Menu:File] open clicked!\n"); break;
|
||||
case MENU_FILE_CLOSE:
|
||||
fprintf(stdout, "[Menu:File] close clicked!\n"); break;
|
||||
case MENU_FILE_QUIT:
|
||||
fprintf(stdout, "[Menu:File] quit clicked!\n"); break;
|
||||
case ZR_NONE:
|
||||
default: break;
|
||||
}
|
||||
zr_layout_row_push(&layout, 45);
|
||||
|
||||
zr_layout_row_push(&layout, config->font.width(config->font.userdata, "__EDIT__", 8));
|
||||
sel = zr_menu(&layout, "EDIT", edit_items, LEN(edit_items), 25, 100,
|
||||
&state->edit_open);
|
||||
switch (sel) {
|
||||
case MENU_EDIT_COPY:
|
||||
fprintf(stdout, "[Menu:Edit] copy clicked!\n"); break;
|
||||
case MENU_EDIT_CUT:
|
||||
fprintf(stdout, "[Menu:Edit] cut clicked!\n"); break;
|
||||
case MENU_EDIT_DELETE:
|
||||
fprintf(stdout, "[Menu:Edit] delete clicked!\n"); break;
|
||||
case MENU_EDIT_PASTE:
|
||||
fprintf(stdout, "[Menu:Edit] paste clicked!\n"); break;
|
||||
case ZR_NONE:
|
||||
default: break;
|
||||
}
|
||||
zr_menu_begin(&layout, &tab, "FILE", 100, &state->file_open);
|
||||
zr_layout_row_dynamic(&tab, 25, 1);
|
||||
for (i = 0; i < LEN(file_items); ++i) {
|
||||
if (zr_menu_item(&tab, ZR_TEXT_LEFT, file_items[i]))
|
||||
fprintf(stdout, "[Menu:File] %s clicked!\n", file_items[i]);
|
||||
}
|
||||
zr_layout_row_end(&layout);
|
||||
state->file_open = zr_menu_end(&layout, &tab);
|
||||
|
||||
zr_layout_row_push(&layout, 45);
|
||||
zr_menu_begin(&layout, &tab, "EDIT", 100, &state->edit_open);
|
||||
zr_layout_row_dynamic(&tab, 25, 1);
|
||||
for (i = 0; i < LEN(edit_items); ++i) {
|
||||
if (zr_menu_item(&tab, ZR_TEXT_LEFT, edit_items[i]))
|
||||
fprintf(stdout, "[Menu:Edit] %s clicked!\n", edit_items[i]);
|
||||
}
|
||||
state->edit_open = zr_menu_end(&layout, &tab);
|
||||
}
|
||||
zr_menubar_end(&layout);
|
||||
|
||||
|
|
56
zahnrad.c
56
zahnrad.c
|
@ -6601,7 +6601,7 @@ zr_button_text_image(struct zr_context *layout, struct zr_image img,
|
|||
behavior, &button, &config->font, i);
|
||||
}
|
||||
|
||||
zr_bool
|
||||
static zr_bool
|
||||
zr_button_fitting(struct zr_context *layout, const char *text,
|
||||
enum zr_text_align align, enum zr_button_behavior behavior)
|
||||
{
|
||||
|
@ -7576,55 +7576,39 @@ failed:
|
|||
menu->queue = parent->queue;
|
||||
}
|
||||
|
||||
zr_bool
|
||||
zr_menu_item(struct zr_context *menu, enum zr_text_align align, const char *title)
|
||||
{
|
||||
if (zr_button_fitting(menu, title, align, ZR_BUTTON_DEFAULT)) {
|
||||
zr_menu_close(menu);
|
||||
return zr_true;
|
||||
}
|
||||
return zr_false;
|
||||
}
|
||||
|
||||
void
|
||||
zr_menu_close(struct zr_context *menu)
|
||||
{
|
||||
ZR_ASSERT(menu);
|
||||
if (!menu) return;
|
||||
zr_popup_close(menu);
|
||||
menu->flags |= ZR_WINDOW_HIDDEN;
|
||||
}
|
||||
|
||||
struct zr_vec2
|
||||
zr_state
|
||||
zr_menu_end(struct zr_context *parent, struct zr_context *menu)
|
||||
{
|
||||
ZR_ASSERT(parent);
|
||||
ZR_ASSERT(menu);
|
||||
if (!parent || !menu) return zr_vec2(0,0);
|
||||
if (!parent->valid)
|
||||
return menu->offset;
|
||||
if (!parent || !menu) return zr_false;
|
||||
if (!parent->valid) return zr_false;
|
||||
if ((!parent->valid || !menu->valid) && !(menu->flags & ZR_WINDOW_HIDDEN))
|
||||
return zr_false;
|
||||
zr_popup_nonblocking_end(parent, menu);
|
||||
return menu->offset;
|
||||
if (menu->flags & ZR_WINDOW_HIDDEN)
|
||||
return zr_false;
|
||||
return zr_true;
|
||||
}
|
||||
|
||||
zr_int
|
||||
zr_menu(struct zr_context *layout, const char *title,
|
||||
const char **entries, zr_size count, zr_size row_height,
|
||||
zr_float width, zr_state *active)
|
||||
{
|
||||
zr_size i;
|
||||
zr_int sel = -1;
|
||||
struct zr_context menu;
|
||||
|
||||
ZR_ASSERT(layout);
|
||||
ZR_ASSERT(entries);
|
||||
ZR_ASSERT(title);
|
||||
ZR_ASSERT(active);
|
||||
if (!layout || !layout->valid || !entries || !title || !active) return -1;
|
||||
if (!count) return -1;
|
||||
|
||||
zr_menu_begin(layout, &menu, title, width, active);
|
||||
zr_layout_row_dynamic(&menu, (zr_float)row_height, 1);
|
||||
for (i = 0; i < count; ++i) {
|
||||
if (zr_button_fitting(&menu, entries[i], ZR_TEXT_LEFT, ZR_BUTTON_DEFAULT)) {
|
||||
zr_combo_close(&menu);
|
||||
*active = zr_false;
|
||||
sel = (zr_int)i;
|
||||
}
|
||||
}
|
||||
zr_menu_end(layout, &menu);
|
||||
return sel;
|
||||
}
|
||||
|
||||
/*
|
||||
* -------------------------------------------------------------
|
||||
*
|
||||
|
|
37
zahnrad.h
37
zahnrad.h
|
@ -3389,17 +3389,6 @@ zr_bool zr_button_text_image(struct zr_context *layout, struct zr_image img,
|
|||
- zr_true if the button was transistioned from unpressed to pressed with
|
||||
default button behavior or pressed if repeater behavior.
|
||||
*/
|
||||
zr_bool zr_button_fitting(struct zr_context *layout, const char *text,
|
||||
enum zr_text_align align, enum zr_button_behavior behavior);
|
||||
/* this function creates a fitting button without border
|
||||
Input:
|
||||
- button label describing the button
|
||||
- text alignment with either left, centered or right alignment
|
||||
- button behavior with either default or repeater behavior
|
||||
Output:
|
||||
- zr_true if the button was transistioned from unpressed to pressed with
|
||||
default button behavior or pressed if repeater behavior.
|
||||
*/
|
||||
zr_bool zr_button_toggle(struct zr_context*, const char*,zr_bool value);
|
||||
/* this function creates a toggle button which is either active or inactive
|
||||
Input:
|
||||
|
@ -3788,21 +3777,6 @@ void zr_combo_end(struct zr_context *parent, struct zr_context *combo);
|
|||
zr_menu_end -- ends the menu item build up process
|
||||
zr_menu -- shorthand retain mode array version
|
||||
*/
|
||||
#define ZR_NONE (-1)
|
||||
zr_int zr_menu(struct zr_context*, const zr_char *title,
|
||||
const char **entries, zr_size count, zr_size row_height,
|
||||
zr_float width, zr_state *active);
|
||||
/* this function creates a standart text based combobox
|
||||
Input:
|
||||
- parent window layout the combo box will be placed into
|
||||
- string array of all items inside the menu
|
||||
- number of menu items inside the string array
|
||||
- the height of every widget inside the combobox
|
||||
- the current state of the menu
|
||||
Output:
|
||||
- updated state of the menu
|
||||
- index of the selected menu item or -1 otherwise
|
||||
*/
|
||||
void zr_menu_begin(struct zr_context *parent,
|
||||
struct zr_context *menu, const char *title,
|
||||
zr_float width, zr_state *active);
|
||||
|
@ -3813,11 +3787,16 @@ void zr_menu_begin(struct zr_context *parent,
|
|||
- title of the menu to
|
||||
- the current state of the menu with either zr_true (open) or zr_false else
|
||||
*/
|
||||
|
||||
zr_bool zr_menu_item(struct zr_context *menu, enum zr_text_align align, const char*);
|
||||
/* this function execute a menu item
|
||||
Input:
|
||||
- title of the item
|
||||
Output
|
||||
- `zr_true` if has been clicked `zr_false` otherwise
|
||||
*/
|
||||
void zr_menu_close(struct zr_context *menu);
|
||||
/* this function closes a opened menu */
|
||||
struct zr_vec2 zr_menu_end(struct zr_context *parent,
|
||||
struct zr_context *menu);
|
||||
zr_state zr_menu_end(struct zr_context *parent, struct zr_context *menu);
|
||||
/* this function ends the menu build up process */
|
||||
/*
|
||||
* --------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue