added non-blocking popup menu

This commit is contained in:
vurtun 2015-08-31 17:35:37 +02:00
parent ffa28e08ea
commit 2b6817be84
2 changed files with 83 additions and 12 deletions

56
gui.c
View File

@ -4100,6 +4100,17 @@ gui_layout_row_space_push(struct gui_context *layout, struct gui_rect rect)
layout->row.item = rect;
}
struct gui_rect
gui_layout_row_space_bounds(struct gui_context *ctx)
{
struct gui_rect ret;
ret.x = ctx->clip.x;
ret.y = ctx->clip.y;
ret.w = ctx->clip.w;
ret.h = ctx->row.height;
return ret;
}
struct gui_vec2
gui_layout_row_space_to_screen(struct gui_context *layout, struct gui_vec2 ret)
{
@ -5450,7 +5461,7 @@ gui_popup_end(struct gui_context *parent, struct gui_context *popup)
}
static gui_bool
gui_popup_nonblock_begin(struct gui_context *parent,
gui_popup_nonblocking_begin(struct gui_context *parent,
struct gui_context *popup, gui_flags flags, gui_state *active, gui_state is_active,
struct gui_rect body)
{
@ -5486,7 +5497,7 @@ gui_popup_nonblock_begin(struct gui_context *parent,
}
static void
gui_popup_nonblock_end(struct gui_context *parent,
gui_popup_nonblocking_end(struct gui_context *parent,
struct gui_context *popup)
{
GUI_ASSERT(parent);
@ -5497,6 +5508,39 @@ gui_popup_nonblock_end(struct gui_context *parent,
gui_popup_end(parent, popup);
}
void
gui_popup_nonblock_begin(struct gui_context *parent, struct gui_context *popup,
gui_flags flags, gui_state *active, struct gui_rect body)
{
GUI_ASSERT(parent);
GUI_ASSERT(popup);
GUI_ASSERT(active);
if (!parent || !popup || !active) return;
gui_popup_nonblocking_begin(parent, popup, flags, active, *active, body);
}
gui_state
gui_popup_nonblock_close(struct gui_context *popup)
{
GUI_ASSERT(popup);
if (!popup) return GUI_INACTIVE;
gui_popup_close(popup);
popup->flags |= GUI_WINDOW_HIDDEN;
return GUI_INACTIVE;
}
void
gui_popup_nonblock_end(struct gui_context *parent, struct gui_context *popup)
{
GUI_ASSERT(parent);
GUI_ASSERT(popup);
if (!parent || !popup) return;
if ((!parent->valid || !popup->valid) && !(popup->flags & GUI_WINDOW_HIDDEN))
return;
gui_popup_nonblocking_end(parent, popup);
return;
}
/*
* -------------------------------------------------------------
*
@ -5581,7 +5625,7 @@ gui_combo_begin(struct gui_context *parent, struct gui_context *combo,
body.w = header.w;
body.y = header.y + header.h;
body.h = gui_null_rect.h;
if (!gui_popup_nonblock_begin(parent,combo,GUI_WINDOW_NO_SCROLLBAR, active,is_active,body))
if (!gui_popup_nonblocking_begin(parent,combo,GUI_WINDOW_NO_SCROLLBAR, active,is_active,body))
goto failed;
combo->flags |= GUI_WINDOW_COMBO_MENU;
}
@ -5603,7 +5647,7 @@ gui_combo_end(struct gui_context *parent, struct gui_context *combo)
if (!parent || !combo) return;
if ((!parent->valid || !combo->valid) && !(combo->flags & GUI_WINDOW_HIDDEN))
return;
gui_popup_nonblock_end(parent, combo);
gui_popup_nonblocking_end(parent, combo);
return;
}
@ -5694,7 +5738,7 @@ gui_menu_begin(struct gui_context *parent, struct gui_context *menu,
body.w = width;
body.y = header.y + header.h;
body.h = (parent->bounds.y + parent->bounds.h) - body.y;
if (!gui_popup_nonblock_begin(parent, menu, GUI_WINDOW_NO_SCROLLBAR, active,
if (!gui_popup_nonblocking_begin(parent, menu, GUI_WINDOW_NO_SCROLLBAR, active,
is_active, body)) goto failed;
menu->flags |= GUI_WINDOW_COMBO_MENU;
}
@ -5724,7 +5768,7 @@ gui_menu_end(struct gui_context *parent, struct gui_context *menu)
if (!parent || !menu) return gui_vec2(0,0);
if (!parent->valid)
return menu->offset;
gui_popup_nonblock_end(parent, menu);
gui_popup_nonblocking_end(parent, menu);
return menu->offset;
}

33
gui.h
View File

@ -2322,6 +2322,8 @@ void gui_layout_row_space_begin(struct gui_context*,
- height of the row and therefore each widget inside
- number of widget that will be added into that space
*/
struct gui_rect gui_layout_row_space_bounds(struct gui_context*);
/* this functions returns the complete bounds of the space in the panel */
void gui_layout_row_space_push(struct gui_context*, struct gui_rect);
/* this functions pushes the position and size of the next widget that will
be added into the previously allocated window space
@ -2744,10 +2746,15 @@ struct gui_vec2 gui_shelf_end(struct gui_context*, struct gui_context*);
care of the closing process. Finally if the popup window was completly created
the `gui_popup_end` function finializes the popup.
window popup API
window blocking popup API
gui_popup_begin -- adds a popup inside a window
gui_popup_close -- closes the popup window
gui_popup_end -- ends the popup building process
window non-blocking popup API
gui_popup_menu_begin -- begin a popup context menu
gui_popup_menu_close -- closes a popup context menu
gui_popup_menu_end -- ends the popup building process
*/
enum gui_popup_type {
GUI_POPUP_STATIC, /* static fixed height non growing popup */
@ -2756,10 +2763,12 @@ enum gui_popup_type {
gui_flags gui_popup_begin(struct gui_context *parent,
struct gui_context *popup, enum gui_popup_type,
gui_flags, struct gui_rect bounds, struct gui_vec2 offset);
/* this function adds a grouped child window into the parent window
/* this function adds a overlapping blocking popup menu
Input:
- type of the popup as either growing or static
- additonal popup window flags
- popup position and size of the popup (NOTE: local position)
- scrollbar pixel offsets for the popup
- scrollbar offset of wanted
Output:
- popup layout to fill with widgets
*/
@ -2771,6 +2780,24 @@ struct gui_vec2 gui_popup_end(struct gui_context *parent,
Output:
- The from user input updated popup scrollbar pixel offset
*/
void gui_popup_nonblock_begin(struct gui_context *parent, struct gui_context *popup,
gui_flags flags, gui_state *active, struct gui_rect body);
/* this function adds a context menu popup
Input:
- type of the popup as either growing or static
- additonal popup window flags
- popup position and size of the popup (NOTE: local position)
- scrollbar offset of wanted
Output:
- popup layout to fill with widgets
*/
gui_state gui_popup_nonblock_close(struct gui_context *popup);
/* this functions closes the context menu
Output:
- update state of the context menu
*/
void gui_popup_nonblock_end(struct gui_context *parent, struct gui_context *popup);
/* this functions closes a previously opened context menu */
/*
* -------------------------------------------------------------
* GRAPH