Mercurial > repos > blastem
comparison nuklear_ui/nuklear.h @ 1931:374a5ae694e8 mame_interp
Merge from default
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 18 Apr 2020 11:42:53 -0700 |
parents | 13abdc98379e 92532eb6986d |
children | 638eb2d25696 |
comparison
equal
deleted
inserted
replaced
1843:13abdc98379e | 1931:374a5ae694e8 |
---|---|
1843 NK_WIDGET_STATE_ACTIVED = NK_FLAG(5),/* widget is currently activated */ | 1843 NK_WIDGET_STATE_ACTIVED = NK_FLAG(5),/* widget is currently activated */ |
1844 NK_WIDGET_STATE_LEFT = NK_FLAG(6), /* widget is from this frame on not hovered anymore */ | 1844 NK_WIDGET_STATE_LEFT = NK_FLAG(6), /* widget is from this frame on not hovered anymore */ |
1845 NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, /* widget is being hovered */ | 1845 NK_WIDGET_STATE_HOVERED = NK_WIDGET_STATE_HOVER|NK_WIDGET_STATE_MODIFIED, /* widget is being hovered */ |
1846 NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */ | 1846 NK_WIDGET_STATE_ACTIVE = NK_WIDGET_STATE_ACTIVED|NK_WIDGET_STATE_MODIFIED /* widget is currently activated */ |
1847 }; | 1847 }; |
1848 NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, const struct nk_context*); | 1848 NK_API enum nk_widget_layout_states nk_widget(struct nk_rect*, struct nk_context*); |
1849 NK_API enum nk_widget_layout_states nk_keynav_widget(struct nk_rect *, struct nk_context *); | |
1849 NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2); | 1850 NK_API enum nk_widget_layout_states nk_widget_fitting(struct nk_rect*, struct nk_context*, struct nk_vec2); |
1850 NK_API struct nk_rect nk_widget_bounds(struct nk_context*); | 1851 NK_API struct nk_rect nk_widget_bounds(struct nk_context*); |
1851 NK_API struct nk_vec2 nk_widget_position(struct nk_context*); | 1852 NK_API struct nk_vec2 nk_widget_position(struct nk_context*); |
1852 NK_API struct nk_vec2 nk_widget_size(struct nk_context*); | 1853 NK_API struct nk_vec2 nk_widget_size(struct nk_context*); |
1853 NK_API float nk_widget_width(struct nk_context*); | 1854 NK_API float nk_widget_width(struct nk_context*); |
3190 }; | 3191 }; |
3191 | 3192 |
3192 struct nk_input { | 3193 struct nk_input { |
3193 struct nk_keyboard keyboard; | 3194 struct nk_keyboard keyboard; |
3194 struct nk_mouse mouse; | 3195 struct nk_mouse mouse; |
3196 int widget_counter; | |
3197 int selected_widget; | |
3195 }; | 3198 }; |
3196 | 3199 |
3197 NK_API int nk_input_has_mouse_click(const struct nk_input*, enum nk_buttons); | 3200 NK_API int nk_input_has_mouse_click(const struct nk_input*, enum nk_buttons); |
3198 NK_API int nk_input_has_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); | 3201 NK_API int nk_input_has_mouse_click_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect); |
3199 NK_API int nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect, int down); | 3202 NK_API int nk_input_has_mouse_click_down_in_rect(const struct nk_input*, enum nk_buttons, struct nk_rect, int down); |
12566 in->mouse.prev.y = in->mouse.pos.y; | 12569 in->mouse.prev.y = in->mouse.pos.y; |
12567 in->mouse.delta.x = 0; | 12570 in->mouse.delta.x = 0; |
12568 in->mouse.delta.y = 0; | 12571 in->mouse.delta.y = 0; |
12569 for (i = 0; i < NK_KEY_MAX; i++) | 12572 for (i = 0; i < NK_KEY_MAX; i++) |
12570 in->keyboard.keys[i].clicked = 0; | 12573 in->keyboard.keys[i].clicked = 0; |
12574 in->widget_counter = -1; | |
12571 } | 12575 } |
12572 | 12576 |
12573 NK_API void | 12577 NK_API void |
12574 nk_input_end(struct nk_context *ctx) | 12578 nk_input_end(struct nk_context *ctx) |
12575 { | 12579 { |
12690 struct nk_rect b) | 12694 struct nk_rect b) |
12691 { | 12695 { |
12692 const struct nk_mouse_button *btn; | 12696 const struct nk_mouse_button *btn; |
12693 if (!i) return nk_false; | 12697 if (!i) return nk_false; |
12694 btn = &i->mouse.buttons[id]; | 12698 btn = &i->mouse.buttons[id]; |
12695 if (!NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) | 12699 if (NK_INBOX(btn->clicked_pos.x,btn->clicked_pos.y,b.x,b.y,b.w,b.h)) |
12696 return nk_false; | 12700 return nk_true; |
12697 return nk_true; | 12701 if (i->selected_widget == i->widget_counter && i->keyboard.keys[NK_KEY_ENTER].clicked) |
12702 return nk_true; | |
12703 return nk_false; | |
12698 } | 12704 } |
12699 | 12705 |
12700 NK_API int | 12706 NK_API int |
12701 nk_input_has_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, | 12707 nk_input_has_mouse_click_down_in_rect(const struct nk_input *i, enum nk_buttons id, |
12702 struct nk_rect b, int down) | 12708 struct nk_rect b, int down) |
12740 | 12746 |
12741 NK_API int | 12747 NK_API int |
12742 nk_input_is_mouse_hovering_rect(const struct nk_input *i, struct nk_rect rect) | 12748 nk_input_is_mouse_hovering_rect(const struct nk_input *i, struct nk_rect rect) |
12743 { | 12749 { |
12744 if (!i) return nk_false; | 12750 if (!i) return nk_false; |
12745 return NK_INBOX(i->mouse.pos.x, i->mouse.pos.y, rect.x, rect.y, rect.w, rect.h); | 12751 return i->selected_widget == i->widget_counter || NK_INBOX(i->mouse.pos.x, i->mouse.pos.y, rect.x, rect.y, rect.w, rect.h); |
12746 } | 12752 } |
12747 | 12753 |
12748 NK_API int | 12754 NK_API int |
12749 nk_input_is_mouse_prev_hovering_rect(const struct nk_input *i, struct nk_rect rect) | 12755 nk_input_is_mouse_prev_hovering_rect(const struct nk_input *i, struct nk_rect rect) |
12750 { | 12756 { |
12762 | 12768 |
12763 NK_API int | 12769 NK_API int |
12764 nk_input_is_mouse_down(const struct nk_input *i, enum nk_buttons id) | 12770 nk_input_is_mouse_down(const struct nk_input *i, enum nk_buttons id) |
12765 { | 12771 { |
12766 if (!i) return nk_false; | 12772 if (!i) return nk_false; |
12767 return i->mouse.buttons[id].down; | 12773 return i->mouse.buttons[id].down || ( |
12774 id == NK_BUTTON_LEFT && i->widget_counter == i->selected_widget && i->keyboard.keys[NK_KEY_ENTER].down | |
12775 ); | |
12768 } | 12776 } |
12769 | 12777 |
12770 NK_API int | 12778 NK_API int |
12771 nk_input_is_mouse_pressed(const struct nk_input *i, enum nk_buttons id) | 12779 nk_input_is_mouse_pressed(const struct nk_input *i, enum nk_buttons id) |
12772 { | 12780 { |
12773 const struct nk_mouse_button *b; | 12781 const struct nk_mouse_button *b; |
12774 if (!i) return nk_false; | 12782 if (!i) return nk_false; |
12775 b = &i->mouse.buttons[id]; | 12783 b = &i->mouse.buttons[id]; |
12776 if (b->down && b->clicked) | 12784 if (b->down && b->clicked) |
12777 return nk_true; | 12785 return nk_true; |
12786 if ( | |
12787 id == NK_BUTTON_LEFT && i->widget_counter == i->selected_widget | |
12788 && i->keyboard.keys[NK_KEY_ENTER].down && i->keyboard.keys[NK_KEY_ENTER].clicked | |
12789 ) | |
12790 return nk_true; | |
12778 return nk_false; | 12791 return nk_false; |
12779 } | 12792 } |
12780 | 12793 |
12781 NK_API int | 12794 NK_API int |
12782 nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id) | 12795 nk_input_is_mouse_released(const struct nk_input *i, enum nk_buttons id) |
12783 { | 12796 { |
12784 if (!i) return nk_false; | 12797 if (!i) return nk_false; |
12785 return (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked); | 12798 if (!i->mouse.buttons[id].down && i->mouse.buttons[id].clicked) |
12799 return nk_true; | |
12800 if ( | |
12801 id == NK_BUTTON_LEFT && i->widget_counter == i->selected_widget | |
12802 && !i->keyboard.keys[NK_KEY_ENTER].down && i->keyboard.keys[NK_KEY_ENTER].clicked | |
12803 ) | |
12804 return nk_true; | |
12805 return nk_false; | |
12786 } | 12806 } |
12787 | 12807 |
12788 NK_API int | 12808 NK_API int |
12789 nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key) | 12809 nk_input_is_key_pressed(const struct nk_input *i, enum nk_keys key) |
12790 { | 12810 { |
14608 } | 14628 } |
14609 | 14629 |
14610 NK_INTERN int | 14630 NK_INTERN int |
14611 nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, | 14631 nk_do_selectable(nk_flags *state, struct nk_command_buffer *out, |
14612 struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, | 14632 struct nk_rect bounds, const char *str, int len, nk_flags align, int *value, |
14613 const struct nk_style_selectable *style, const struct nk_input *in, | 14633 const struct nk_style_selectable *style, struct nk_input *in, |
14614 const struct nk_user_font *font) | 14634 const struct nk_user_font *font) |
14615 { | 14635 { |
14616 int old_value; | 14636 int old_value; |
14617 struct nk_rect touch; | 14637 struct nk_rect touch; |
14618 | 14638 |
14634 touch.h = bounds.h + style->touch_padding.y * 2; | 14654 touch.h = bounds.h + style->touch_padding.y * 2; |
14635 | 14655 |
14636 /* update button */ | 14656 /* update button */ |
14637 if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT)) | 14657 if (nk_button_behavior(state, touch, in, NK_BUTTON_DEFAULT)) |
14638 *value = !(*value); | 14658 *value = !(*value); |
14659 | |
14660 if (!old_value && !(*value) && in && in->selected_widget == in->widget_counter) { | |
14661 *value = 1; | |
14662 } else if (!old_value && *value && in) { | |
14663 in->selected_widget = in->widget_counter; | |
14664 } | |
14639 | 14665 |
14640 /* draw selectable */ | 14666 /* draw selectable */ |
14641 if (style->draw_begin) style->draw_begin(out, style->userdata); | 14667 if (style->draw_begin) style->draw_begin(out, style->userdata); |
14642 nk_draw_selectable(out, *state, style, *value, &bounds, 0,0, str, len, align, font); | 14668 nk_draw_selectable(out, *state, style, *value, &bounds, 0,0, str, len, align, font); |
14643 if (style->draw_end) style->draw_end(out, style->userdata); | 14669 if (style->draw_end) style->draw_end(out, style->userdata); |
16159 /* draw property */ | 16185 /* draw property */ |
16160 if (style->draw_begin) style->draw_begin(out, style->userdata); | 16186 if (style->draw_begin) style->draw_begin(out, style->userdata); |
16161 nk_draw_property(out, style, &property, &label, *ws, name, name_len, font); | 16187 nk_draw_property(out, style, &property, &label, *ws, name, name_len, font); |
16162 if (style->draw_end) style->draw_end(out, style->userdata); | 16188 if (style->draw_end) style->draw_end(out, style->userdata); |
16163 | 16189 |
16164 /* execute right button */ | 16190 int selected = in && in->selected_widget == in->widget_counter; |
16165 if (nk_do_button_symbol(ws, out, left, style->sym_left, behavior, &style->dec_button, in, font)) { | 16191 int enter_clicked; |
16192 if (selected) { | |
16193 //prevent left/right buttons from activating when enter is pressed | |
16194 enter_clicked = in->keyboard.keys[NK_KEY_ENTER].clicked; | |
16195 in->keyboard.keys[NK_KEY_ENTER].clicked = 0; | |
16196 } | |
16197 /* execute left button */ | |
16198 if ( | |
16199 nk_do_button_symbol(ws, out, left, style->sym_left, behavior, &style->dec_button, in, font) | |
16200 || (selected && in->keyboard.keys[NK_KEY_LEFT].clicked && in->keyboard.keys[NK_KEY_LEFT].down) | |
16201 ) { | |
16166 switch (variant->kind) { | 16202 switch (variant->kind) { |
16167 default: break; | 16203 default: break; |
16168 case NK_PROPERTY_INT: | 16204 case NK_PROPERTY_INT: |
16169 variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i - variant->step.i, variant->max_value.i); break; | 16205 variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i - variant->step.i, variant->max_value.i); break; |
16170 case NK_PROPERTY_FLOAT: | 16206 case NK_PROPERTY_FLOAT: |
16171 variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f - variant->step.f, variant->max_value.f); break; | 16207 variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f - variant->step.f, variant->max_value.f); break; |
16172 case NK_PROPERTY_DOUBLE: | 16208 case NK_PROPERTY_DOUBLE: |
16173 variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d - variant->step.d, variant->max_value.d); break; | 16209 variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d - variant->step.d, variant->max_value.d); break; |
16174 } | 16210 } |
16175 } | 16211 } |
16176 /* execute left button */ | 16212 /* execute right button */ |
16177 if (nk_do_button_symbol(ws, out, right, style->sym_right, behavior, &style->inc_button, in, font)) { | 16213 if ( |
16214 nk_do_button_symbol(ws, out, right, style->sym_right, behavior, &style->inc_button, in, font) | |
16215 || (selected && in->keyboard.keys[NK_KEY_RIGHT].clicked && in->keyboard.keys[NK_KEY_RIGHT].down) | |
16216 ) { | |
16178 switch (variant->kind) { | 16217 switch (variant->kind) { |
16179 default: break; | 16218 default: break; |
16180 case NK_PROPERTY_INT: | 16219 case NK_PROPERTY_INT: |
16181 variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i + variant->step.i, variant->max_value.i); break; | 16220 variant->value.i = NK_CLAMP(variant->min_value.i, variant->value.i + variant->step.i, variant->max_value.i); break; |
16182 case NK_PROPERTY_FLOAT: | 16221 case NK_PROPERTY_FLOAT: |
16183 variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f + variant->step.f, variant->max_value.f); break; | 16222 variant->value.f = NK_CLAMP(variant->min_value.f, variant->value.f + variant->step.f, variant->max_value.f); break; |
16184 case NK_PROPERTY_DOUBLE: | 16223 case NK_PROPERTY_DOUBLE: |
16185 variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d); break; | 16224 variant->value.d = NK_CLAMP(variant->min_value.d, variant->value.d + variant->step.d, variant->max_value.d); break; |
16186 } | 16225 } |
16187 } | 16226 } |
16227 if (selected) { | |
16228 in->keyboard.keys[NK_KEY_ENTER].clicked = enter_clicked; | |
16229 } | |
16188 if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) { | 16230 if (old != NK_PROPERTY_EDIT && (*state == NK_PROPERTY_EDIT)) { |
16189 /* property has been activated so setup buffer */ | 16231 /* property has been activated so setup buffer */ |
16190 NK_MEMCPY(buffer, dst, (nk_size)*length); | 16232 NK_MEMCPY(buffer, dst, (nk_size)*length); |
16191 *cursor = nk_utf_len(buffer, *length); | 16233 *cursor = nk_utf_len(buffer, *length); |
16192 *len = *length; | 16234 *len = *length; |
17257 ctx->seq = 1; | 17299 ctx->seq = 1; |
17258 if (font) ctx->style.font = font; | 17300 if (font) ctx->style.font = font; |
17259 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT | 17301 #ifdef NK_INCLUDE_VERTEX_BUFFER_OUTPUT |
17260 nk_draw_list_init(&ctx->draw_list); | 17302 nk_draw_list_init(&ctx->draw_list); |
17261 #endif | 17303 #endif |
17304 ctx->input.widget_counter = -1; | |
17262 } | 17305 } |
17263 | 17306 |
17264 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR | 17307 #ifdef NK_INCLUDE_DEFAULT_ALLOCATOR |
17265 NK_API int | 17308 NK_API int |
17266 nk_init_default(struct nk_context *ctx, const struct nk_user_font *font) | 17309 nk_init_default(struct nk_context *ctx, const struct nk_user_font *font) |
20236 return 0; | 20279 return 0; |
20237 return nk_input_has_mouse_click_down_in_rect(&ctx->input, btn, bounds, down); | 20280 return nk_input_has_mouse_click_down_in_rect(&ctx->input, btn, bounds, down); |
20238 } | 20281 } |
20239 | 20282 |
20240 NK_API enum nk_widget_layout_states | 20283 NK_API enum nk_widget_layout_states |
20241 nk_widget(struct nk_rect *bounds, const struct nk_context *ctx) | 20284 nk_widget_gen(struct nk_rect *bounds, struct nk_context *ctx, nk_byte is_keynav) |
20242 { | 20285 { |
20243 struct nk_rect c, v; | 20286 struct nk_rect c, v; |
20244 struct nk_window *win; | 20287 struct nk_window *win; |
20245 struct nk_panel *layout; | 20288 struct nk_panel *layout; |
20246 const struct nk_input *in; | 20289 const struct nk_input *in; |
20275 | 20318 |
20276 c.x = (float)((int)c.x); | 20319 c.x = (float)((int)c.x); |
20277 c.y = (float)((int)c.y); | 20320 c.y = (float)((int)c.y); |
20278 c.w = (float)((int)c.w); | 20321 c.w = (float)((int)c.w); |
20279 c.h = (float)((int)c.h); | 20322 c.h = (float)((int)c.h); |
20323 int newly_selected = nk_false; | |
20324 if (is_keynav) { | |
20325 ctx->input.widget_counter++; | |
20326 if ( | |
20327 ctx->input.selected_widget == (ctx->input.widget_counter + 1) && | |
20328 ctx->input.keyboard.keys[NK_KEY_UP].clicked && ctx->input.keyboard.keys[NK_KEY_UP].down | |
20329 ) { | |
20330 ctx->input.selected_widget--; | |
20331 newly_selected = nk_true; | |
20332 } else if ( | |
20333 ctx->input.selected_widget == (ctx->input.widget_counter - 1) && | |
20334 ctx->input.keyboard.keys[NK_KEY_DOWN].clicked && ctx->input.keyboard.keys[NK_KEY_DOWN].down | |
20335 ) { | |
20336 ctx->input.keyboard.keys[NK_KEY_DOWN].clicked = 0; | |
20337 ctx->input.selected_widget++; | |
20338 newly_selected = nk_true; | |
20339 } | |
20340 } | |
20280 | 20341 |
20281 nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); | 20342 nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); |
20343 if (is_keynav && newly_selected) { | |
20344 //ensure widget is fully on-screen if it was newly selected via a keyboard action | |
20345 if ((bounds->y + bounds->h) > (c.y + c.h)) { | |
20346 *layout->offset_y += bounds->y + bounds->h - (c.y + c.h); | |
20347 } else if(c.y > bounds->y){ | |
20348 *layout->offset_y -= c.y - bounds->y; | |
20349 } | |
20350 } | |
20282 if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) | 20351 if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) |
20283 return NK_WIDGET_INVALID; | 20352 return NK_WIDGET_INVALID; |
20284 if (!NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, v.x, v.y, v.w, v.h)) | 20353 if ((is_keynav && ctx->input.selected_widget == ctx->input.widget_counter ) || NK_INBOX(in->mouse.pos.x, in->mouse.pos.y, v.x, v.y, v.w, v.h)) |
20285 return NK_WIDGET_ROM; | 20354 return NK_WIDGET_VALID; |
20286 return NK_WIDGET_VALID; | 20355 return NK_WIDGET_ROM; |
20356 } | |
20357 | |
20358 NK_API enum nk_widget_layout_states | |
20359 nk_widget(struct nk_rect *bounds, struct nk_context *ctx) | |
20360 { | |
20361 return nk_widget_gen(bounds, ctx, 0); | |
20362 } | |
20363 | |
20364 NK_API enum nk_widget_layout_states | |
20365 nk_keynav_widget(struct nk_rect *bounds, struct nk_context *ctx) | |
20366 { | |
20367 return nk_widget_gen(bounds, ctx, 1); | |
20287 } | 20368 } |
20288 | 20369 |
20289 NK_API enum nk_widget_layout_states | 20370 NK_API enum nk_widget_layout_states |
20290 nk_widget_fitting(struct nk_rect *bounds, struct nk_context *ctx, | 20371 nk_widget_fitting(struct nk_rect *bounds, struct nk_context *ctx, |
20291 struct nk_vec2 item_padding) | 20372 struct nk_vec2 item_padding) |
20304 return NK_WIDGET_INVALID; | 20385 return NK_WIDGET_INVALID; |
20305 | 20386 |
20306 win = ctx->current; | 20387 win = ctx->current; |
20307 style = &ctx->style; | 20388 style = &ctx->style; |
20308 layout = win->layout; | 20389 layout = win->layout; |
20309 state = nk_widget(bounds, ctx); | 20390 state = nk_keynav_widget(bounds, ctx); |
20310 | 20391 |
20311 panel_padding = nk_panel_get_padding(style, layout->type); | 20392 panel_padding = nk_panel_get_padding(style, layout->type); |
20312 if (layout->row.index == 1) { | 20393 if (layout->row.index == 1) { |
20313 bounds->w += panel_padding.x; | 20394 bounds->w += panel_padding.x; |
20314 bounds->x -= panel_padding.x; | 20395 bounds->x -= panel_padding.x; |
20625 NK_ASSERT(ctx->current->layout); | 20706 NK_ASSERT(ctx->current->layout); |
20626 if (!style || !ctx || !ctx->current || !ctx->current->layout) return 0; | 20707 if (!style || !ctx || !ctx->current || !ctx->current->layout) return 0; |
20627 | 20708 |
20628 win = ctx->current; | 20709 win = ctx->current; |
20629 layout = win->layout; | 20710 layout = win->layout; |
20630 state = nk_widget(&bounds, ctx); | 20711 state = nk_keynav_widget(&bounds, ctx); |
20631 | 20712 |
20632 if (!state) return 0; | 20713 if (!state) return 0; |
20633 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20714 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20634 return nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, | 20715 int ret = nk_do_button_text(&ctx->last_widget_state, &win->buffer, bounds, |
20635 title, len, style->text_alignment, ctx->button_behavior, | 20716 title, len, style->text_alignment, ctx->button_behavior, |
20636 style, in, ctx->style.font); | 20717 style, in, ctx->style.font); |
20718 if (ctx->last_widget_state & NK_WIDGET_STATE_ENTERED) { | |
20719 ctx->input.selected_widget = ctx->input.widget_counter; | |
20720 } | |
20721 return ret; | |
20637 } | 20722 } |
20638 | 20723 |
20639 NK_API int | 20724 NK_API int |
20640 nk_button_text(struct nk_context *ctx, const char *title, int len) | 20725 nk_button_text(struct nk_context *ctx, const char *title, int len) |
20641 { | 20726 { |
20671 return 0; | 20756 return 0; |
20672 | 20757 |
20673 win = ctx->current; | 20758 win = ctx->current; |
20674 layout = win->layout; | 20759 layout = win->layout; |
20675 | 20760 |
20676 state = nk_widget(&bounds, ctx); | 20761 state = nk_keynav_widget(&bounds, ctx); |
20677 if (!state) return 0; | 20762 if (!state) return 0; |
20678 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20763 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20679 | 20764 |
20680 button = ctx->style.button; | 20765 button = ctx->style.button; |
20681 button.normal = nk_style_item_color(color); | 20766 button.normal = nk_style_item_color(color); |
20682 button.hover = nk_style_item_color(color); | 20767 button.hover = nk_style_item_color(color); |
20683 button.active = nk_style_item_color(color); | 20768 button.active = nk_style_item_color(color); |
20684 ret = nk_do_button(&ctx->last_widget_state, &win->buffer, bounds, | 20769 ret = nk_do_button(&ctx->last_widget_state, &win->buffer, bounds, |
20685 &button, in, ctx->button_behavior, &content); | 20770 &button, in, ctx->button_behavior, &content); |
20686 nk_draw_button(&win->buffer, &bounds, ctx->last_widget_state, &button); | 20771 nk_draw_button(&win->buffer, &bounds, ctx->last_widget_state, &button); |
20772 if (ctx->last_widget_state & NK_WIDGET_STATE_ENTERED) { | |
20773 ctx->input.selected_widget = ctx->input.widget_counter; | |
20774 } | |
20687 return ret; | 20775 return ret; |
20688 } | 20776 } |
20689 | 20777 |
20690 NK_API int | 20778 NK_API int |
20691 nk_button_symbol_styled(struct nk_context *ctx, | 20779 nk_button_symbol_styled(struct nk_context *ctx, |
20704 if (!ctx || !ctx->current || !ctx->current->layout) | 20792 if (!ctx || !ctx->current || !ctx->current->layout) |
20705 return 0; | 20793 return 0; |
20706 | 20794 |
20707 win = ctx->current; | 20795 win = ctx->current; |
20708 layout = win->layout; | 20796 layout = win->layout; |
20709 state = nk_widget(&bounds, ctx); | 20797 state = nk_keynav_widget(&bounds, ctx); |
20710 if (!state) return 0; | 20798 if (!state) return 0; |
20711 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20799 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20712 return nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds, | 20800 int ret = nk_do_button_symbol(&ctx->last_widget_state, &win->buffer, bounds, |
20713 symbol, ctx->button_behavior, style, in, ctx->style.font); | 20801 symbol, ctx->button_behavior, style, in, ctx->style.font); |
20802 if (ctx->last_widget_state & NK_WIDGET_STATE_ENTERED) { | |
20803 ctx->input.selected_widget = ctx->input.widget_counter; | |
20804 } | |
20805 return ret; | |
20714 } | 20806 } |
20715 | 20807 |
20716 NK_API int | 20808 NK_API int |
20717 nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol) | 20809 nk_button_symbol(struct nk_context *ctx, enum nk_symbol_type symbol) |
20718 { | 20810 { |
20739 return 0; | 20831 return 0; |
20740 | 20832 |
20741 win = ctx->current; | 20833 win = ctx->current; |
20742 layout = win->layout; | 20834 layout = win->layout; |
20743 | 20835 |
20744 state = nk_widget(&bounds, ctx); | 20836 state = nk_keynav_widget(&bounds, ctx); |
20745 if (!state) return 0; | 20837 if (!state) return 0; |
20746 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20838 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20747 return nk_do_button_image(&ctx->last_widget_state, &win->buffer, bounds, | 20839 return nk_do_button_image(&ctx->last_widget_state, &win->buffer, bounds, |
20748 img, ctx->button_behavior, style, in); | 20840 img, ctx->button_behavior, style, in); |
20749 } | 20841 } |
20775 return 0; | 20867 return 0; |
20776 | 20868 |
20777 win = ctx->current; | 20869 win = ctx->current; |
20778 layout = win->layout; | 20870 layout = win->layout; |
20779 | 20871 |
20780 state = nk_widget(&bounds, ctx); | 20872 state = nk_keynav_widget(&bounds, ctx); |
20781 if (!state) return 0; | 20873 if (!state) return 0; |
20782 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20874 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20783 return nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds, | 20875 return nk_do_button_text_symbol(&ctx->last_widget_state, &win->buffer, bounds, |
20784 symbol, text, len, align, ctx->button_behavior, | 20876 symbol, text, len, align, ctx->button_behavior, |
20785 style, ctx->style.font, in); | 20877 style, ctx->style.font, in); |
20822 return 0; | 20914 return 0; |
20823 | 20915 |
20824 win = ctx->current; | 20916 win = ctx->current; |
20825 layout = win->layout; | 20917 layout = win->layout; |
20826 | 20918 |
20827 state = nk_widget(&bounds, ctx); | 20919 state = nk_keynav_widget(&bounds, ctx); |
20828 if (!state) return 0; | 20920 if (!state) return 0; |
20829 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20921 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20830 return nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, | 20922 return nk_do_button_text_image(&ctx->last_widget_state, &win->buffer, |
20831 bounds, img, text, len, align, ctx->button_behavior, | 20923 bounds, img, text, len, align, ctx->button_behavior, |
20832 style, ctx->style.font, in); | 20924 style, ctx->style.font, in); |
20856 nk_selectable_text(struct nk_context *ctx, const char *str, int len, | 20948 nk_selectable_text(struct nk_context *ctx, const char *str, int len, |
20857 nk_flags align, int *value) | 20949 nk_flags align, int *value) |
20858 { | 20950 { |
20859 struct nk_window *win; | 20951 struct nk_window *win; |
20860 struct nk_panel *layout; | 20952 struct nk_panel *layout; |
20861 const struct nk_input *in; | 20953 struct nk_input *in; |
20862 const struct nk_style *style; | 20954 const struct nk_style *style; |
20863 | 20955 |
20864 enum nk_widget_layout_states state; | 20956 enum nk_widget_layout_states state; |
20865 struct nk_rect bounds; | 20957 struct nk_rect bounds; |
20866 | 20958 |
20873 | 20965 |
20874 win = ctx->current; | 20966 win = ctx->current; |
20875 layout = win->layout; | 20967 layout = win->layout; |
20876 style = &ctx->style; | 20968 style = &ctx->style; |
20877 | 20969 |
20878 state = nk_widget(&bounds, ctx); | 20970 state = nk_keynav_widget(&bounds, ctx); |
20879 if (!state) return 0; | 20971 if (!state) return 0; |
20880 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 20972 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20881 return nk_do_selectable(&ctx->last_widget_state, &win->buffer, bounds, | 20973 return nk_do_selectable(&ctx->last_widget_state, &win->buffer, bounds, |
20882 str, len, align, value, &style->selectable, in, style->font); | 20974 str, len, align, value, &style->selectable, in, style->font); |
20883 } | 20975 } |
20958 | 21050 |
20959 win = ctx->current; | 21051 win = ctx->current; |
20960 style = &ctx->style; | 21052 style = &ctx->style; |
20961 layout = win->layout; | 21053 layout = win->layout; |
20962 | 21054 |
20963 state = nk_widget(&bounds, ctx); | 21055 state = nk_keynav_widget(&bounds, ctx); |
20964 if (!state) return active; | 21056 if (!state) return active; |
20965 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; | 21057 in = (state == NK_WIDGET_ROM || layout->flags & NK_WINDOW_ROM) ? 0 : &ctx->input; |
20966 nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active, | 21058 nk_do_toggle(&ctx->last_widget_state, &win->buffer, bounds, &active, |
20967 text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font); | 21059 text, len, NK_TOGGLE_CHECK, &style->checkbox, in, style->font); |
20968 return active; | 21060 return active; |
21433 return; | 21525 return; |
21434 | 21526 |
21435 win = ctx->current; | 21527 win = ctx->current; |
21436 layout = win->layout; | 21528 layout = win->layout; |
21437 style = &ctx->style; | 21529 style = &ctx->style; |
21438 s = nk_widget(&bounds, ctx); | 21530 s = nk_keynav_widget(&bounds, ctx); |
21439 if (!s) return; | 21531 if (!s) return; |
21440 | 21532 |
21441 /* calculate hash from name */ | 21533 /* calculate hash from name */ |
21442 if (name[0] == '#') { | 21534 if (name[0] == '#') { |
21443 hash = nk_murmur_hash(name, (int)nk_strlen(name), win->property.seq++); | 21535 hash = nk_murmur_hash(name, (int)nk_strlen(name), win->property.seq++); |
21483 win->property.select_end = *select_end; | 21575 win->property.select_end = *select_end; |
21484 if (*state == NK_PROPERTY_DRAG) { | 21576 if (*state == NK_PROPERTY_DRAG) { |
21485 ctx->input.mouse.grab = nk_true; | 21577 ctx->input.mouse.grab = nk_true; |
21486 ctx->input.mouse.grabbed = nk_true; | 21578 ctx->input.mouse.grabbed = nk_true; |
21487 } | 21579 } |
21580 ctx->input.selected_widget = ctx->input.widget_counter; | |
21488 } | 21581 } |
21489 /* check if previously active property is now inactive */ | 21582 /* check if previously active property is now inactive */ |
21490 if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) { | 21583 if (*state == NK_PROPERTY_DEFAULT && old_state != NK_PROPERTY_DEFAULT) { |
21491 if (old_state == NK_PROPERTY_DRAG) { | 21584 if (old_state == NK_PROPERTY_DRAG) { |
21492 ctx->input.mouse.grab = nk_false; | 21585 ctx->input.mouse.grab = nk_false; |
22693 struct nk_vec2 padding = nk_panel_get_padding(&ctx->style, panel->type); | 22786 struct nk_vec2 padding = nk_panel_get_padding(&ctx->style, panel->type); |
22694 body = panel->bounds; | 22787 body = panel->bounds; |
22695 body.y = (panel->at_y + panel->footer_height + panel->border + padding.y + panel->row.height); | 22788 body.y = (panel->at_y + panel->footer_height + panel->border + padding.y + panel->row.height); |
22696 body.h = (panel->bounds.y + panel->bounds.h) - body.y; | 22789 body.h = (panel->bounds.y + panel->bounds.h) - body.y; |
22697 } | 22790 } |
22791 int selected = ctx->input.selected_widget; | |
22792 ctx->input.selected_widget = -1; | |
22698 {int pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT); | 22793 {int pressed = nk_input_is_mouse_pressed(&ctx->input, NK_BUTTON_LEFT); |
22699 int in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body); | 22794 int in_body = nk_input_is_mouse_hovering_rect(&ctx->input, body); |
22795 ctx->input.selected_widget = selected; | |
22700 if (pressed && in_body) | 22796 if (pressed && in_body) |
22701 popup->flags |= NK_WINDOW_HIDDEN; | 22797 popup->flags |= NK_WINDOW_HIDDEN; |
22702 } | 22798 } |
22703 } | 22799 } |
22704 if (popup->flags & NK_WINDOW_HIDDEN) | 22800 if (popup->flags & NK_WINDOW_HIDDEN) |
22767 if (!ctx || !ctx->current || !ctx->current->layout || !selected) | 22863 if (!ctx || !ctx->current || !ctx->current->layout || !selected) |
22768 return 0; | 22864 return 0; |
22769 | 22865 |
22770 win = ctx->current; | 22866 win = ctx->current; |
22771 style = &ctx->style; | 22867 style = &ctx->style; |
22772 s = nk_widget(&header, ctx); | 22868 s = nk_keynav_widget(&header, ctx); |
22773 if (s == NK_WIDGET_INVALID) | 22869 if (s == NK_WIDGET_INVALID) |
22774 return 0; | 22870 return 0; |
22775 | 22871 |
22776 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; | 22872 in = (win->layout->flags & NK_WINDOW_ROM || s == NK_WIDGET_ROM)? 0: &ctx->input; |
22777 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) | 22873 if (nk_button_behavior(&ctx->last_widget_state, header, in, NK_BUTTON_DEFAULT)) |
23328 max_height = count * item_height + count * (int)item_spacing.y; | 23424 max_height = count * item_height + count * (int)item_spacing.y; |
23329 max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; | 23425 max_height += (int)item_spacing.y * 2 + (int)window_padding.y * 2; |
23330 size.y = NK_MIN(size.y, (float)max_height); | 23426 size.y = NK_MIN(size.y, (float)max_height); |
23331 if (nk_combo_begin_label(ctx, items[selected], size)) { | 23427 if (nk_combo_begin_label(ctx, items[selected], size)) { |
23332 nk_layout_row_dynamic(ctx, (float)item_height, 1); | 23428 nk_layout_row_dynamic(ctx, (float)item_height, 1); |
23429 int main_item_widget = ctx->input.widget_counter; | |
23333 for (i = 0; i < count; ++i) { | 23430 for (i = 0; i < count; ++i) { |
23334 if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) | 23431 if (nk_combo_item_label(ctx, items[i], NK_TEXT_LEFT)) { |
23335 selected = i; | 23432 selected = i; |
23433 ctx->input.selected_widget = main_item_widget; | |
23434 //prevent below code from advancing selected widget | |
23435 main_item_widget--; | |
23436 } | |
23336 } | 23437 } |
23337 nk_combo_end(ctx); | 23438 nk_combo_end(ctx); |
23439 if (ctx->input.selected_widget <= main_item_widget) { | |
23440 ctx->input.selected_widget = main_item_widget + 1; | |
23441 } else if (ctx->input.selected_widget > main_item_widget + count) { | |
23442 ctx->input.selected_widget = main_item_widget + count; | |
23443 } | |
23338 } | 23444 } |
23339 return selected; | 23445 return selected; |
23340 } | 23446 } |
23341 | 23447 |
23342 NK_API int | 23448 NK_API int |