From adbe553c88a0c62e099261f0aca4ed503970f048 Mon Sep 17 00:00:00 2001 From: Komari Spaghetti <3759175+Hejsil@users.noreply.github.com> Date: Sun, 20 Jun 2021 21:22:34 +0200 Subject: [PATCH] Store name_len in window --- nuklear.h | 9 ++++----- src/nuklear.h | 1 + src/nuklear_window.c | 8 +++----- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/nuklear.h b/nuklear.h index ce1a58c2d..bc3dfef80 100644 --- a/nuklear.h +++ b/nuklear.h @@ -5383,6 +5383,7 @@ struct nk_property_state { struct nk_window { unsigned int seq; nk_hash name; + nk_size name_len; char name_string[NK_WINDOW_MAX_NAME]; nk_flags flags; @@ -19738,7 +19739,7 @@ nk_find_window(struct nk_context *ctx, nk_hash hash, struct nk_slice name) while (iter) { NK_ASSERT(iter != iter->next); if (iter->name == hash) { - if (!nk_stricmp(nk_slicez(iter->name_string), name)) + if (!nk_stricmp(nk_slice(iter->name_string, iter->name_len), name)) return iter; } iter = iter->next; @@ -19848,7 +19849,6 @@ nk_begin_titled(struct nk_context *ctx, struct nk_slice name, struct nk_slice ti win = nk_find_window(ctx, name_hash, name); if (!win) { /* create new window */ - nk_size name_length = name.len; win = (struct nk_window*)nk_create_window(ctx); NK_ASSERT(win); if (!win) return 0; @@ -19861,9 +19861,8 @@ nk_begin_titled(struct nk_context *ctx, struct nk_slice name, struct nk_slice ti win->flags = flags; win->bounds = bounds; win->name = name_hash; - name_length = NK_MIN(name_length, NK_WINDOW_MAX_NAME-1); - NK_MEMCPY(win->name_string, name.ptr, name.len); - win->name_string[name_length] = 0; + win->name_len = NK_MIN(name.len, NK_WINDOW_MAX_NAME); + NK_MEMCPY(win->name_string, name.ptr, win->name_len); win->popup.win = 0; if (!ctx->active) ctx->active = win; diff --git a/src/nuklear.h b/src/nuklear.h index a33fb996b..be17d4945 100644 --- a/src/nuklear.h +++ b/src/nuklear.h @@ -5162,6 +5162,7 @@ struct nk_property_state { struct nk_window { unsigned int seq; nk_hash name; + nk_size name_len; char name_string[NK_WINDOW_MAX_NAME]; nk_flags flags; diff --git a/src/nuklear_window.c b/src/nuklear_window.c index 6666deaf0..d08318a89 100644 --- a/src/nuklear_window.c +++ b/src/nuklear_window.c @@ -50,7 +50,7 @@ nk_find_window(struct nk_context *ctx, nk_hash hash, struct nk_slice name) while (iter) { NK_ASSERT(iter != iter->next); if (iter->name == hash) { - if (!nk_stricmp(nk_slicez(iter->name_string), name)) + if (!nk_stricmp(nk_slice(iter->name_string, iter->name_len), name)) return iter; } iter = iter->next; @@ -160,7 +160,6 @@ nk_begin_titled(struct nk_context *ctx, struct nk_slice name, struct nk_slice ti win = nk_find_window(ctx, name_hash, name); if (!win) { /* create new window */ - nk_size name_length = name.len; win = (struct nk_window*)nk_create_window(ctx); NK_ASSERT(win); if (!win) return 0; @@ -173,9 +172,8 @@ nk_begin_titled(struct nk_context *ctx, struct nk_slice name, struct nk_slice ti win->flags = flags; win->bounds = bounds; win->name = name_hash; - name_length = NK_MIN(name_length, NK_WINDOW_MAX_NAME-1); - NK_MEMCPY(win->name_string, name.ptr, name.len); - win->name_string[name_length] = 0; + win->name_len = NK_MIN(name.len, NK_WINDOW_MAX_NAME); + NK_MEMCPY(win->name_string, name.ptr, win->name_len); win->popup.win = 0; if (!ctx->active) ctx->active = win;