Mercurial > repos > blastem
comparison nuklear_ui/nuklear.h @ 1845:b6ad26acade4
Adjust scroll of parent layout object if widget newly selected by keyboard is offscreen
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 22 Apr 2019 20:03:55 -0700 |
parents | 7a9e6fd94d61 |
children | 6fc4afea5424 |
comparison
equal
deleted
inserted
replaced
1844:7a9e6fd94d61 | 1845:b6ad26acade4 |
---|---|
20290 | 20290 |
20291 c.x = (float)((int)c.x); | 20291 c.x = (float)((int)c.x); |
20292 c.y = (float)((int)c.y); | 20292 c.y = (float)((int)c.y); |
20293 c.w = (float)((int)c.w); | 20293 c.w = (float)((int)c.w); |
20294 c.h = (float)((int)c.h); | 20294 c.h = (float)((int)c.h); |
20295 int newly_selected = nk_false; | |
20295 if (is_keynav) { | 20296 if (is_keynav) { |
20296 ctx->input.widget_counter++; | 20297 ctx->input.widget_counter++; |
20297 if ( | 20298 if ( |
20298 ctx->input.selected_widget == (ctx->input.widget_counter + 1) && | 20299 ctx->input.selected_widget == (ctx->input.widget_counter + 1) && |
20299 ctx->input.keyboard.keys[NK_KEY_UP].clicked && ctx->input.keyboard.keys[NK_KEY_UP].down | 20300 ctx->input.keyboard.keys[NK_KEY_UP].clicked && ctx->input.keyboard.keys[NK_KEY_UP].down |
20300 ) { | 20301 ) { |
20301 ctx->input.selected_widget--; | 20302 ctx->input.selected_widget--; |
20303 newly_selected = nk_true; | |
20302 } else if ( | 20304 } else if ( |
20303 ctx->input.selected_widget == (ctx->input.widget_counter - 1) && | 20305 ctx->input.selected_widget == (ctx->input.widget_counter - 1) && |
20304 ctx->input.keyboard.keys[NK_KEY_DOWN].clicked && ctx->input.keyboard.keys[NK_KEY_DOWN].down | 20306 ctx->input.keyboard.keys[NK_KEY_DOWN].clicked && ctx->input.keyboard.keys[NK_KEY_DOWN].down |
20305 ) { | 20307 ) { |
20306 ctx->input.keyboard.keys[NK_KEY_DOWN].clicked = 0; | 20308 ctx->input.keyboard.keys[NK_KEY_DOWN].clicked = 0; |
20307 ctx->input.selected_widget++; | 20309 ctx->input.selected_widget++; |
20310 newly_selected = nk_true; | |
20308 } | 20311 } |
20309 } | 20312 } |
20310 | 20313 |
20311 nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); | 20314 nk_unify(&v, &c, bounds->x, bounds->y, bounds->x + bounds->w, bounds->y + bounds->h); |
20315 if (is_keynav && newly_selected) { | |
20316 //ensure widget is fully on-screen if it was newly selected via a keyboard action | |
20317 if ((bounds->y + bounds->h) > (c.y + c.h)) { | |
20318 *layout->offset_y += bounds->y + bounds->h - (c.y + c.h); | |
20319 } else if(c.y > bounds->y){ | |
20320 *layout->offset_y -= c.y - bounds->y; | |
20321 } | |
20322 } | |
20312 if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) | 20323 if (!NK_INTERSECT(c.x, c.y, c.w, c.h, bounds->x, bounds->y, bounds->w, bounds->h)) |
20313 return NK_WIDGET_INVALID; | 20324 return NK_WIDGET_INVALID; |
20314 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)) | 20325 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)) |
20315 return NK_WIDGET_VALID; | 20326 return NK_WIDGET_VALID; |
20316 return NK_WIDGET_ROM; | 20327 return NK_WIDGET_ROM; |