Mercurial > repos > blastem
comparison nuklear_ui/nuklear.h @ 1854:58b6f5d918f4
Minor improvements to keyboard navigation
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 25 Apr 2019 21:54:47 -0700 |
parents | 6fc4afea5424 |
children | 92532eb6986d |
comparison
equal
deleted
inserted
replaced
1853:9b2acecf8124 | 1854:58b6f5d918f4 |
---|---|
16174 if (style->draw_begin) style->draw_begin(out, style->userdata); | 16174 if (style->draw_begin) style->draw_begin(out, style->userdata); |
16175 nk_draw_property(out, style, &property, &label, *ws, name, name_len, font); | 16175 nk_draw_property(out, style, &property, &label, *ws, name, name_len, font); |
16176 if (style->draw_end) style->draw_end(out, style->userdata); | 16176 if (style->draw_end) style->draw_end(out, style->userdata); |
16177 | 16177 |
16178 int selected = in && in->selected_widget == in->widget_counter; | 16178 int selected = in && in->selected_widget == in->widget_counter; |
16179 int enter_clicked; | |
16179 if (selected) { | 16180 if (selected) { |
16180 //prevent left/right buttons from activating when enter is pressed | 16181 //prevent left/right buttons from activating when enter is pressed |
16181 in->selected_widget = -1; | 16182 enter_clicked = in->keyboard.keys[NK_KEY_ENTER].clicked; |
16183 in->keyboard.keys[NK_KEY_ENTER].clicked = 0; | |
16182 } | 16184 } |
16183 /* execute left button */ | 16185 /* execute left button */ |
16184 if ( | 16186 if ( |
16185 nk_do_button_symbol(ws, out, left, style->sym_left, behavior, &style->dec_button, in, font) | 16187 nk_do_button_symbol(ws, out, left, style->sym_left, behavior, &style->dec_button, in, font) |
16186 || (selected && in->keyboard.keys[NK_KEY_LEFT].clicked && in->keyboard.keys[NK_KEY_LEFT].down) | 16188 || (selected && in->keyboard.keys[NK_KEY_LEFT].clicked && in->keyboard.keys[NK_KEY_LEFT].down) |
16209 case NK_PROPERTY_DOUBLE: | 16211 case NK_PROPERTY_DOUBLE: |
16210 variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d); break; | 16212 variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d); break; |
16211 } | 16213 } |
16212 } | 16214 } |
16213 if (selected) { | 16215 if (selected) { |
16214 in->selected_widget = in->widget_counter; | 16216 in->keyboard.keys[NK_KEY_ENTER].clicked = enter_clicked; |
16215 } | 16217 } |
16216 if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) { | 16218 if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) { |
16217 /* property has been activated so setup buffer */ | 16219 /* property has been activated so setup buffer */ |
16218 NK_MEMCPY(buffer, dst, (nk_size)*length); | 16220 NK_MEMCPY(buffer, dst, (nk_size)*length); |
16219 *cursor = nk_utf_len(buffer, *length); | 16221 *cursor = nk_utf_len(buffer, *length); |
20696 layout = win->layout; | 20698 layout = win->layout; |
20697 state = nk_keynav_widget(&bounds, ctx); | 20699 state = nk_keynav_widget(&bounds, ctx); |
20698 | 20700 |
20699 if (!state) return 0; | 20701 if (!state) return 0; |
20700 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20702 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20701 return nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, | 20703 int ret = nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, |
20702 title, len, style->text_alignment, ctx->button_behavior, | 20704 title, len, style->text_alignment, ctx->button_behavior, |
20703 style, in, ctx->style.font); | 20705 style, in, ctx->style.font); |
20706 if (ctx->last_widget_state & NK_WIDGET_STATE_ENTERED) { | |
20707 ctx->input.selected_widget = ctx->input.widget_counter; | |
20708 } | |
20709 return ret; | |
20704 } | 20710 } |
20705 | 20711 |
20706 NK_API int | 20712 NK_API int |
20707 nk_button_text(struct nk_context *ctx, const char *title, int len) | 20713 nk_button_text(struct nk_context *ctx, const char *title, int len) |
20708 { | 20714 { |
20749 button.hover = nk_style_item_color(color); | 20755 button.hover = nk_style_item_color(color); |
20750 button.active = nk_style_item_color(color); | 20756 button.active = nk_style_item_color(color); |
20751 ret = nk_do_button(&ctx->last_widget_state, &win->buffer, bounds, | 20757 ret = nk_do_button(&ctx->last_widget_state, &win->buffer, bounds, |
20752 &button, in, ctx->button_behavior, &content); | 20758 &button, in, ctx->button_behavior, &content); |
20753 nk_draw_button(&win->buffer, &bounds, ctx->last_widget_state, &button); | 20759 nk_draw_button(&win->buffer, &bounds, ctx->last_widget_state, &button); |
20760 if (ctx->last_widget_state & NK_WIDGET_STATE_ENTERED) { | |
20761 ctx->input.selected_widget = ctx->input.widget_counter; | |
20762 } | |
20754 return ret; | 20763 return ret; |
20755 } | 20764 } |
20756 | 20765 |
20757 NK_API int | 20766 NK_API int |
20758 nk_button_symbol_styled(struct nk_context *ctx, | 20767 nk_button_symbol_styled(struct nk_context *ctx, |
20774 win = ctx->current; | 20783 win = ctx->current; |
20775 layout = win->layout; | 20784 layout = win->layout; |
20776 state = nk_keynav_widget(&bounds, ctx); | 20785 state = nk_keynav_widget(&bounds, ctx); |
20777 if (!state) return 0; | 20786 if (!state) return 0; |
20778 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20787 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20779 return nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds, | 20788 int ret = nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds, |
20780 symbol, ctx->button_behavior, style, in, ctx->style.font); | 20789 symbol, ctx->button_behavior, style, in, ctx->style.font); |
20790 if (ctx->last_widget_state & NK_WIDGET_STATE_ENTERED) { | |
20791 ctx->input.selected_widget = ctx->input.widget_counter; | |
20792 } | |
20793 return ret; | |
20781 } | 20794 } |
20782 | 20795 |
20783 NK_API int | 20796 NK_API int |
20784 nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol) | 20797 nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol) |
20785 { | 20798 { |
21550 win->property.select_end = *select_end; | 21563 win->property.select_end = *select_end; |
21551 if (*state == NK_PROPERTY_DRAG) { | 21564 if (*state == NK_PROPERTY_DRAG) { |
21552 ctx->input.mouse.grab = nk_true; | 21565 ctx->input.mouse.grab = nk_true; |
21553 ctx->input.mouse.grabbed = nk_true; | 21566 ctx->input.mouse.grabbed = nk_true; |
21554 } | 21567 } |
21568 ctx->input.selected_widget = ctx->input.widget_counter; | |
21555 } | 21569 } |
21556 /* check if previously active property is now inactive */ | 21570 /* check if previously active property is now inactive */ |
21557 if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) { | 21571 if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) { |
21558 if (old_state == NK_PROPERTY_DRAG) { | 21572 if (old_state == NK_PROPERTY_DRAG) { |
21559 ctx->input.mouse.grab = nk_false; | 21573 ctx->input.mouse.grab = nk_false; |