Mercurial > repos > blastem
comparison nuklear_ui/blastem_nuklear.c @ 1572:5efeca06d942
Scale UI font size based on window size and start basing widget sizes based on font size
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 24 Apr 2018 20:31:18 -0700 |
parents | 3def7b216a5b |
children | a051d8ee4528 |
comparison
equal
deleted
inserted
replaced
1571:3def7b216a5b | 1572:5efeca06d942 |
---|---|
20 typedef void (*view_fun)(struct nk_context *); | 20 typedef void (*view_fun)(struct nk_context *); |
21 static view_fun current_view; | 21 static view_fun current_view; |
22 static view_fun *previous_views; | 22 static view_fun *previous_views; |
23 static uint32_t view_storage; | 23 static uint32_t view_storage; |
24 static uint32_t num_prev; | 24 static uint32_t num_prev; |
25 static struct nk_font *def_font; | |
25 | 26 |
26 static void push_view(view_fun new_view) | 27 static void push_view(view_fun new_view) |
27 { | 28 { |
28 if (num_prev == view_storage) { | 29 if (num_prev == view_storage) { |
29 view_storage = view_storage ? 2*view_storage : 2; | 30 view_storage = view_storage ? 2*view_storage : 2; |
252 view_choose_state(context, 1); | 253 view_choose_state(context, 1); |
253 } | 254 } |
254 | 255 |
255 static void menu(struct nk_context *context, uint32_t num_entries, const menu_item *items) | 256 static void menu(struct nk_context *context, uint32_t num_entries, const menu_item *items) |
256 { | 257 { |
257 const uint32_t button_height = 52; | 258 const uint32_t button_height = context->style.font->height * 1.75; |
258 const uint32_t ideal_button_width = 300; | 259 const uint32_t ideal_button_width = context->style.font->height * 10; |
259 const uint32_t button_space = 6; | 260 const uint32_t button_space = 6; |
260 | 261 |
261 uint32_t width = render_width(); | 262 uint32_t width = render_width(); |
262 uint32_t height = render_height(); | 263 uint32_t height = render_height(); |
263 uint32_t top = height/2 - (button_height * num_entries)/2; | 264 uint32_t top = height/2 - (button_height * num_entries)/2; |
497 nk_end(context); | 498 nk_end(context); |
498 } | 499 } |
499 } | 500 } |
500 static struct nk_image controller_360_image; | 501 static struct nk_image controller_360_image; |
501 static uint32_t controller_360_width, controller_360_height; | 502 static uint32_t controller_360_width, controller_360_height; |
502 #define MIN_BIND_BOX_WIDTH 140 | 503 //#define MIN_BIND_BOX_WIDTH 140 |
503 #define MAX_BIND_BOX_WIDTH 350 | 504 #define MAX_BIND_BOX_WIDTH 350 |
504 void view_controllers(struct nk_context *context) | 505 void view_controllers(struct nk_context *context) |
505 { | 506 { |
506 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { | 507 if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { |
507 uint32_t avail_height = render_height() - 60; | 508 float orig_height = def_font->handle.height; |
509 def_font->handle.height *= 0.5f; | |
510 | |
511 uint32_t avail_height = render_height() - 2 * orig_height; | |
508 float desired_width = render_width() * 0.5f, desired_height = avail_height * 0.5f; | 512 float desired_width = render_width() * 0.5f, desired_height = avail_height * 0.5f; |
509 float controller_ratio = (float)controller_360_width / (float)controller_360_height; | 513 float controller_ratio = (float)controller_360_width / (float)controller_360_height; |
514 | |
515 const struct nk_user_font *font = context->style.font; | |
516 int MIN_BIND_BOX_WIDTH = font->width(font->userdata, font->height, "Right", strlen("Right")) | |
517 + def_font->handle.width(font->userdata, font->height, "Internal Screenshot", strlen("Internal Screenshot")); | |
518 | |
510 if (render_width() - desired_width < 2.5f*MIN_BIND_BOX_WIDTH) { | 519 if (render_width() - desired_width < 2.5f*MIN_BIND_BOX_WIDTH) { |
511 desired_width = render_width() - 2.5f*MIN_BIND_BOX_WIDTH; | 520 desired_width = render_width() - 2.5f*MIN_BIND_BOX_WIDTH; |
512 } | 521 } |
513 | 522 |
514 if (desired_width / desired_height > controller_ratio) { | 523 if (desired_width / desired_height > controller_ratio) { |
572 | 581 |
573 nk_group_end(context); | 582 nk_group_end(context); |
574 | 583 |
575 nk_layout_space_end(context); | 584 nk_layout_space_end(context); |
576 | 585 |
577 nk_layout_row_static(context, 34, (render_width() - 80) / 2, 1); | 586 def_font->handle.height = orig_height; |
587 nk_layout_row_static(context, orig_height + 4, (render_width() - 80) / 2, 1); | |
578 if (nk_button_label(context, "Back")) { | 588 if (nk_button_label(context, "Back")) { |
579 pop_view(); | 589 pop_view(); |
580 } | 590 } |
581 nk_end(context); | 591 nk_end(context); |
582 } | 592 } |
1037 uint32_t font_size; | 1047 uint32_t font_size; |
1038 uint8_t *font = default_font(&font_size); | 1048 uint8_t *font = default_font(&font_size); |
1039 if (!font) { | 1049 if (!font) { |
1040 fatal_error("Failed to find default font path\n"); | 1050 fatal_error("Failed to find default font path\n"); |
1041 } | 1051 } |
1042 struct nk_font *def_font = nk_font_atlas_add_from_memory(atlas, font, font_size, 30, NULL); | 1052 def_font = nk_font_atlas_add_from_memory(atlas, font, font_size, render_height() / 16, NULL); |
1043 nk_sdl_font_stash_end(); | 1053 nk_sdl_font_stash_end(); |
1044 nk_style_set_font(context, &def_font->handle); | 1054 nk_style_set_font(context, &def_font->handle); |
1045 if (controller_360_buf) { | 1055 if (controller_360_buf) { |
1046 GLuint tex; | 1056 GLuint tex; |
1047 glGenTextures(1, &tex); | 1057 glGenTextures(1, &tex); |