# HG changeset patch # User Michael Pavone # Date 1524627078 25200 # Node ID 5efeca06d94280d7827185c4b182957924d32766 # Parent 3def7b216a5b8377b59ecb92d7c56ddfad583036 Scale UI font size based on window size and start basing widget sizes based on font size diff -r 3def7b216a5b -r 5efeca06d942 nuklear_ui/blastem_nuklear.c --- a/nuklear_ui/blastem_nuklear.c Sat Apr 21 14:48:01 2018 -0700 +++ b/nuklear_ui/blastem_nuklear.c Tue Apr 24 20:31:18 2018 -0700 @@ -22,6 +22,7 @@ static view_fun *previous_views; static uint32_t view_storage; static uint32_t num_prev; +static struct nk_font *def_font; static void push_view(view_fun new_view) { @@ -254,8 +255,8 @@ static void menu(struct nk_context *context, uint32_t num_entries, const menu_item *items) { - const uint32_t button_height = 52; - const uint32_t ideal_button_width = 300; + const uint32_t button_height = context->style.font->height * 1.75; + const uint32_t ideal_button_width = context->style.font->height * 10; const uint32_t button_space = 6; uint32_t width = render_width(); @@ -499,14 +500,22 @@ } static struct nk_image controller_360_image; static uint32_t controller_360_width, controller_360_height; -#define MIN_BIND_BOX_WIDTH 140 +//#define MIN_BIND_BOX_WIDTH 140 #define MAX_BIND_BOX_WIDTH 350 void view_controllers(struct nk_context *context) { if (nk_begin(context, "Controller Bindings", nk_rect(0, 0, render_width(), render_height()), NK_WINDOW_NO_SCROLLBAR)) { - uint32_t avail_height = render_height() - 60; + float orig_height = def_font->handle.height; + def_font->handle.height *= 0.5f; + + uint32_t avail_height = render_height() - 2 * orig_height; float desired_width = render_width() * 0.5f, desired_height = avail_height * 0.5f; float controller_ratio = (float)controller_360_width / (float)controller_360_height; + + const struct nk_user_font *font = context->style.font; + int MIN_BIND_BOX_WIDTH = font->width(font->userdata, font->height, "Right", strlen("Right")) + + def_font->handle.width(font->userdata, font->height, "Internal Screenshot", strlen("Internal Screenshot")); + if (render_width() - desired_width < 2.5f*MIN_BIND_BOX_WIDTH) { desired_width = render_width() - 2.5f*MIN_BIND_BOX_WIDTH; } @@ -574,7 +583,8 @@ nk_layout_space_end(context); - nk_layout_row_static(context, 34, (render_width() - 80) / 2, 1); + def_font->handle.height = orig_height; + nk_layout_row_static(context, orig_height + 4, (render_width() - 80) / 2, 1); if (nk_button_label(context, "Back")) { pop_view(); } @@ -1039,7 +1049,7 @@ if (!font) { fatal_error("Failed to find default font path\n"); } - struct nk_font *def_font = nk_font_atlas_add_from_memory(atlas, font, font_size, 30, NULL); + def_font = nk_font_atlas_add_from_memory(atlas, font, font_size, render_height() / 16, NULL); nk_sdl_font_stash_end(); nk_style_set_font(context, &def_font->handle); if (controller_360_buf) { diff -r 3def7b216a5b -r 5efeca06d942 util.c --- a/util.c Sat Apr 21 14:48:01 2018 -0700 +++ b/util.c Tue Apr 24 20:31:18 2018 -0700 @@ -248,6 +248,41 @@ return out; } +int utf8_codepoint(const char **text) +{ + uint8_t initial = **text; + (*text)++; + if (initial < 0x80) { + return initial; + } + int base; + uint8_t extended_bytes; + if ((initial & 0xE0) == 0xC0) { + base = 0x80; + initial &= 0x1F; + extended_bytes = 1; + } else if ((initial & 0xF0) == 0xE0) { + base = 0x800; + initial &= 0xF; + extended_bytes = 2; + } else if ((initial & 0xF8) == 0xF0) { + base = 0x10000; + initial &= 0x7; + extended_bytes = 3; + } + int value = initial; + for (uint8_t i = 0; i < extended_bytes; i++) + { + if ((**text & 0xC0) != 0x80) { + return -1; + } + value = value << 6; + value |= (**text) & 0x3F; + (*text)++; + } + return value + base; +} + char is_path_sep(char c) { #ifdef _WIN32 diff -r 3def7b216a5b -r 5efeca06d942 util.h --- a/util.h Sat Apr 21 14:48:01 2018 -0700 +++ b/util.h Tue Apr 24 20:31:18 2018 -0700 @@ -36,6 +36,8 @@ void bin_to_hex(uint8_t *output, uint8_t *input, uint64_t size); //Takes an (optionally) null-terminated UTF16-BE string and converts a maximum of max_size code-units to UTF-8 char *utf16be_to_utf8(uint8_t *buf, uint32_t max_size); +//Returns the next Unicode codepoint from a utf-8 string +int utf8_codepoint(const char **text); //Determines whether a character is a valid path separator for the current platform char is_path_sep(char c); //Determines whether a path is considered an absolute path on the current platform