Skip to content

Commit

Permalink
Store name_len in window
Browse files Browse the repository at this point in the history
  • Loading branch information
Hejsil committed Jun 24, 2021
1 parent f1877be commit adbe553
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/nuklear.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 3 additions & 5 deletions src/nuklear_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit adbe553

Please sign in to comment.