comparison nuklear_ui/nuklear.h @ 1855:92532eb6986d

Make combo boxes keyboard navigable
author Michael Pavone <pavone@retrodev.com>
date Sat, 27 Apr 2019 11:23:35 -0700
parents 58b6f5d918f4
children 374a5ae694e8 579fe3f6fe76
comparison
equal deleted inserted replaced
1854:58b6f5d918f4 1855:92532eb6986d
20373 return NK_WIDGET_INVALID; 20373 return NK_WIDGET_INVALID;
20374 20374
20375 win = ctx->current; 20375 win = ctx->current;
20376 style = &ctx->style; 20376 style = &ctx->style;
20377 layout = win->layout; 20377 layout = win->layout;
20378 state = nk_widget(bounds, ctx); 20378 state = nk_keynav_widget(bounds, ctx);
20379 20379
20380 panel_padding = nk_panel_get_padding(style, layout->type); 20380 panel_padding = nk_panel_get_padding(style, layout->type);
20381 if (layout->row.index == 1) { 20381 if (layout->row.index == 1) {
20382 bounds->w += panel_padding.x; 20382 bounds->w += panel_padding.x;
20383 bounds->x -= panel_padding.x; 20383 bounds->x -= panel_padding.x;
22774 struct nk_vec2 padding = nk_panel_get_padding(&ctx->style, panel->type); 22774 struct nk_vec2 padding = nk_panel_get_padding(&ctx->style, panel->type);
22775 body = panel->bounds; 22775 body = panel->bounds;
22776 body.y = (panel->at_y + panel->footer_height + panel->border + padding.y + panel->row.height); 22776 body.y = (panel->at_y + panel->footer_height + panel->border + padding.y + panel->row.height);
22777 body.h = (panel->bounds.y + panel->bounds.h) - body.y; 22777 body.h = (panel->bounds.y + panel->bounds.h) - body.y;
22778 } 22778 }
22779 int selected = ctx->input.selected_widget;
22780 ctx->input.selected_widget = -1;
22779 {int pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT); 22781 {int pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT);
22780 int in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body); 22782 int in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body);
22783 ctx->input.selected_widget = selected;
22781 if (pressed && in_body) 22784 if (pressed && in_body)
22782 popup->flags |= NK_WINDOW_HIDDEN; 22785 popup->flags |= NK_WINDOW_HIDDEN;
22783 } 22786 }
22784 } 22787 }
22785 if (popup->flags & NK_WINDOW_HIDDEN) 22788 if (popup->flags & NK_WINDOW_HIDDEN)
22848 if (!ctx || !ctx->current || !ctx->current->layout || !selected) 22851 if (!ctx || !ctx->current || !ctx->current->layout || !selected)
22849 return 0; 22852 return 0;
22850 22853
22851 win = ctx->current; 22854 win = ctx->current;
22852 style = &ctx->style; 22855 style = &ctx->style;
22853 s = nk_widget(&header, ctx); 22856 s = nk_keynav_widget(&header, ctx);
22854 if (s == NK_WIDGET_INVALID) 22857 if (s == NK_WIDGET_INVALID)
22855 return 0; 22858 return 0;
22856 22859
22857 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; 22860 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input;
22858 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) 22861 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT))
23409 max_height = count * item_height + count * (int)item_spacing.y; 23412 max_height = count * item_height + count * (int)item_spacing.y;
23410 max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; 23413 max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2;
23411 size.y = NK_MIN(size.y, (float)max_height); 23414 size.y = NK_MIN(size.y, (float)max_height);
23412 if (nk_combo_begin_label(ctx, items[selected], size)) { 23415 if (nk_combo_begin_label(ctx, items[selected], size)) {
23413 nk_layout_row_dynamic(ctx, (float)item_height, 1); 23416 nk_layout_row_dynamic(ctx, (float)item_height, 1);
23417 int main_item_widget = ctx->input.widget_counter;
23414 for (i = 0; i < count; ++i) { 23418 for (i = 0; i < count; ++i) {
23415 if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) 23419 if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) {
23416 selected = i; 23420 selected = i;
23421 ctx->input.selected_widget = main_item_widget;
23422 //prevent below code from advancing selected widget
23423 main_item_widget--;
23424 }
23417 } 23425 }
23418 nk_combo_end(ctx); 23426 nk_combo_end(ctx);
23427 if (ctx->input.selected_widget <= main_item_widget) {
23428 ctx->input.selected_widget = main_item_widget + 1;
23429 } else if (ctx->input.selected_widget > main_item_widget + count) {
23430 ctx->input.selected_widget = main_item_widget + count;
23431 }
23419 } 23432 }
23420 return selected; 23433 return selected;
23421 } 23434 }
23422 23435
23423 NK_API int 23436 NK_API int