mirror of https://github.com/vurtun/nuklear.git
Fixed #677 contextual right-click behavior
Closing a contextual menu by right click caused invalid behavior and bocking. In addition having consecutive contextual menus and closing an earlier menu will wrongfully open a following menu. Both are now fixed.pull/685/head
parent
b91a815c82
commit
0981c1a321
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
static int
|
static int
|
||||||
overview(struct nk_context *ctx)
|
overview(struct nk_context *ctx)
|
||||||
{
|
{
|
||||||
|
@ -221,7 +220,6 @@ overview(struct nk_context *ctx)
|
||||||
option = nk_option_label(ctx, "optionB", option == B) ? B : option;
|
option = nk_option_label(ctx, "optionB", option == B) ? B : option;
|
||||||
option = nk_option_label(ctx, "optionC", option == C) ? C : option;
|
option = nk_option_label(ctx, "optionC", option == C) ? C : option;
|
||||||
|
|
||||||
|
|
||||||
nk_layout_row(ctx, NK_STATIC, 30, 2, ratio);
|
nk_layout_row(ctx, NK_STATIC, 30, 2, ratio);
|
||||||
nk_labelf(ctx, NK_TEXT_LEFT, "Slider int");
|
nk_labelf(ctx, NK_TEXT_LEFT, "Slider int");
|
||||||
nk_slider_int(ctx, 0, &int_slider, 10, 1);
|
nk_slider_int(ctx, 0, &int_slider, 10, 1);
|
||||||
|
@ -253,6 +251,32 @@ overview(struct nk_context *ctx)
|
||||||
nk_tree_pop(ctx);
|
nk_tree_pop(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nk_tree_push(ctx, NK_TREE_NODE, "Inactive", NK_MINIMIZED))
|
||||||
|
{
|
||||||
|
static int inactive = 1;
|
||||||
|
nk_layout_row_dynamic(ctx, 30, 1);
|
||||||
|
nk_checkbox_label(ctx, "Inactive", &inactive);
|
||||||
|
|
||||||
|
nk_layout_row_static(ctx, 30, 80, 1);
|
||||||
|
if (inactive) {
|
||||||
|
struct nk_style_button button;
|
||||||
|
button = ctx->style.button;
|
||||||
|
ctx->style.button.normal = nk_style_item_color(nk_rgb(40,40,40));
|
||||||
|
ctx->style.button.hover = nk_style_item_color(nk_rgb(40,40,40));
|
||||||
|
ctx->style.button.active = nk_style_item_color(nk_rgb(40,40,40));
|
||||||
|
ctx->style.button.border_color = nk_rgb(60,60,60);
|
||||||
|
ctx->style.button.text_background = nk_rgb(60,60,60);
|
||||||
|
ctx->style.button.text_normal = nk_rgb(60,60,60);
|
||||||
|
ctx->style.button.text_hover = nk_rgb(60,60,60);
|
||||||
|
ctx->style.button.text_active = nk_rgb(60,60,60);
|
||||||
|
nk_button_label(ctx, "button");
|
||||||
|
ctx->style.button = button;
|
||||||
|
} else if (nk_button_label(ctx, "button"))
|
||||||
|
fprintf(stdout, "button pressed\n");
|
||||||
|
nk_tree_pop(ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (nk_tree_push(ctx, NK_TREE_NODE, "Selectable", NK_MINIMIZED))
|
if (nk_tree_push(ctx, NK_TREE_NODE, "Selectable", NK_MINIMIZED))
|
||||||
{
|
{
|
||||||
if (nk_tree_push(ctx, NK_TREE_NODE, "List", NK_MINIMIZED))
|
if (nk_tree_push(ctx, NK_TREE_NODE, "List", NK_MINIMIZED))
|
||||||
|
|
11
nuklear.h
11
nuklear.h
|
@ -5170,6 +5170,7 @@ NK_API struct nk_style_item nk_style_item_hide(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum nk_panel_type {
|
enum nk_panel_type {
|
||||||
|
NK_PANEL_NONE = 0,
|
||||||
NK_PANEL_WINDOW = NK_FLAG(0),
|
NK_PANEL_WINDOW = NK_FLAG(0),
|
||||||
NK_PANEL_GROUP = NK_FLAG(1),
|
NK_PANEL_GROUP = NK_FLAG(1),
|
||||||
NK_PANEL_POPUP = NK_FLAG(2),
|
NK_PANEL_POPUP = NK_FLAG(2),
|
||||||
|
@ -16902,9 +16903,8 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
|
||||||
struct nk_window *popup;
|
struct nk_window *popup;
|
||||||
struct nk_rect body;
|
struct nk_rect body;
|
||||||
|
|
||||||
NK_STORAGE const struct nk_rect null_rect = {0,0,0,0};
|
NK_STORAGE const struct nk_rect null_rect = {-1,-1,0,0};
|
||||||
int is_clicked = 0;
|
int is_clicked = 0;
|
||||||
int is_active = 0;
|
|
||||||
int is_open = 0;
|
int is_open = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
@ -16913,11 +16913,11 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
|
||||||
NK_ASSERT(ctx->current->layout);
|
NK_ASSERT(ctx->current->layout);
|
||||||
if (!ctx || !ctx->current || !ctx->current->layout)
|
if (!ctx || !ctx->current || !ctx->current->layout)
|
||||||
return 0;
|
return 0;
|
||||||
if (ctx->current != ctx->active)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
win = ctx->current;
|
win = ctx->current;
|
||||||
++win->popup.con_count;
|
++win->popup.con_count;
|
||||||
|
if (ctx->current != ctx->active)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* check if currently active contextual is active */
|
/* check if currently active contextual is active */
|
||||||
popup = win->popup.win;
|
popup = win->popup.win;
|
||||||
|
@ -16925,7 +16925,7 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
|
||||||
is_clicked = nk_input_mouse_clicked(&ctx->input, NK_BUTTON_RIGHT, trigger_bounds);
|
is_clicked = nk_input_mouse_clicked(&ctx->input, NK_BUTTON_RIGHT, trigger_bounds);
|
||||||
if (win->popup.active_con && win->popup.con_count != win->popup.active_con)
|
if (win->popup.active_con && win->popup.con_count != win->popup.active_con)
|
||||||
return 0;
|
return 0;
|
||||||
if ((is_clicked && is_open && !is_active) || (!is_open && !is_active && !is_clicked))
|
if ((!is_open && !is_clicked))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* calculate contextual position on click */
|
/* calculate contextual position on click */
|
||||||
|
@ -16946,6 +16946,7 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
|
||||||
if (ret) win->popup.type = NK_PANEL_CONTEXTUAL;
|
if (ret) win->popup.type = NK_PANEL_CONTEXTUAL;
|
||||||
else {
|
else {
|
||||||
win->popup.active_con = 0;
|
win->popup.active_con = 0;
|
||||||
|
win->popup.type = NK_PANEL_NONE;
|
||||||
if (win->popup.win)
|
if (win->popup.win)
|
||||||
win->popup.win->flags = 0;
|
win->popup.win->flags = 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4954,6 +4954,7 @@ NK_API struct nk_style_item nk_style_item_hide(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum nk_panel_type {
|
enum nk_panel_type {
|
||||||
|
NK_PANEL_NONE = 0,
|
||||||
NK_PANEL_WINDOW = NK_FLAG(0),
|
NK_PANEL_WINDOW = NK_FLAG(0),
|
||||||
NK_PANEL_GROUP = NK_FLAG(1),
|
NK_PANEL_GROUP = NK_FLAG(1),
|
||||||
NK_PANEL_POPUP = NK_FLAG(2),
|
NK_PANEL_POPUP = NK_FLAG(2),
|
||||||
|
|
|
@ -14,9 +14,8 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
|
||||||
struct nk_window *popup;
|
struct nk_window *popup;
|
||||||
struct nk_rect body;
|
struct nk_rect body;
|
||||||
|
|
||||||
NK_STORAGE const struct nk_rect null_rect = {0,0,0,0};
|
NK_STORAGE const struct nk_rect null_rect = {-1,-1,0,0};
|
||||||
int is_clicked = 0;
|
int is_clicked = 0;
|
||||||
int is_active = 0;
|
|
||||||
int is_open = 0;
|
int is_open = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
@ -25,11 +24,11 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
|
||||||
NK_ASSERT(ctx->current->layout);
|
NK_ASSERT(ctx->current->layout);
|
||||||
if (!ctx || !ctx->current || !ctx->current->layout)
|
if (!ctx || !ctx->current || !ctx->current->layout)
|
||||||
return 0;
|
return 0;
|
||||||
if (ctx->current != ctx->active)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
win = ctx->current;
|
win = ctx->current;
|
||||||
++win->popup.con_count;
|
++win->popup.con_count;
|
||||||
|
if (ctx->current != ctx->active)
|
||||||
|
return 0;
|
||||||
|
|
||||||
/* check if currently active contextual is active */
|
/* check if currently active contextual is active */
|
||||||
popup = win->popup.win;
|
popup = win->popup.win;
|
||||||
|
@ -37,7 +36,7 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
|
||||||
is_clicked = nk_input_mouse_clicked(&ctx->input, NK_BUTTON_RIGHT, trigger_bounds);
|
is_clicked = nk_input_mouse_clicked(&ctx->input, NK_BUTTON_RIGHT, trigger_bounds);
|
||||||
if (win->popup.active_con && win->popup.con_count != win->popup.active_con)
|
if (win->popup.active_con && win->popup.con_count != win->popup.active_con)
|
||||||
return 0;
|
return 0;
|
||||||
if ((is_clicked && is_open && !is_active) || (!is_open && !is_active && !is_clicked))
|
if ((!is_open && !is_clicked))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* calculate contextual position on click */
|
/* calculate contextual position on click */
|
||||||
|
@ -58,6 +57,7 @@ nk_contextual_begin(struct nk_context *ctx, nk_flags flags, struct nk_vec2 size,
|
||||||
if (ret) win->popup.type = NK_PANEL_CONTEXTUAL;
|
if (ret) win->popup.type = NK_PANEL_CONTEXTUAL;
|
||||||
else {
|
else {
|
||||||
win->popup.active_con = 0;
|
win->popup.active_con = 0;
|
||||||
|
win->popup.type = NK_PANEL_NONE;
|
||||||
if (win->popup.win)
|
if (win->popup.win)
|
||||||
win->popup.win->flags = 0;
|
win->popup.win->flags = 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue