Fixed window hiding and exposing bug

Previously rapidly closing and exposing windows caused the library
to freeze. This had two reasons one was a bug in the list insert
and remove code the other was in the fact that if the currently
active window is removed no other window would active which resulted
in a blocking UI. Both problems are now fixed but there is a small
visual bug which is triggered if a window is toggled.
This commit is contained in:
vurtun 2016-03-03 13:12:20 +01:00
parent e847001728
commit acb2a31b82
3 changed files with 114 additions and 45 deletions

View File

@ -48,6 +48,14 @@ struct demo {
struct icons icons;
enum theme theme;
struct zr_memory_status status;
int show_simple;
int show_replay;
int show_demo;
int show_node;
int show_grid;
int show_button;
int show_basic;
};
static void
@ -271,7 +279,36 @@ control_window(struct zr_context *ctx, struct demo *gui)
ZR_WINDOW_CLOSABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_MOVABLE|
ZR_WINDOW_SCALABLE|ZR_WINDOW_BORDER))
{
/* Style */
if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "Windows", ZR_MINIMIZED)) {
zr_layout_row_dynamic(ctx, 25, 2);
gui->show_simple = !zr_window_is_closed(ctx, "Show");
gui->show_replay = !zr_window_is_closed(ctx, "Recorded");
gui->show_node = !zr_window_is_closed(ctx, "Node Editor");
gui->show_demo = !zr_window_is_closed(ctx, "Demo");
#ifndef DEMO_DO_NOT_DRAW_IMAGES
gui->show_grid = !zr_window_is_closed(ctx, "Grid Demo");
gui->show_basic = !zr_window_is_closed(ctx, "Basic Demo");
gui->show_button = !zr_window_is_closed(ctx, "Button Demo");
#endif
if (zr_checkbox(ctx, "Show", &gui->show_simple) && !gui->show_simple)
zr_window_close(ctx, "Show");
if (zr_checkbox(ctx, "Recorded", &gui->show_replay) && !gui->show_replay)
zr_window_close(ctx, "Recorded");
if (zr_checkbox(ctx, "Demo", &gui->show_demo) && !gui->show_demo)
zr_window_close(ctx, "Demo");
if (zr_checkbox(ctx, "Node Editor", &gui->show_node) && !gui->show_node)
zr_window_close(ctx, "Node Editor");
#ifndef DEMO_DO_NOT_DRAW_IMAGES
if (zr_checkbox(ctx, "Grid", &gui->show_grid) && !gui->show_grid)
zr_window_close(ctx, "Grid Demo");
if (zr_checkbox(ctx, "Basic", &gui->show_basic) && !gui->show_basic)
zr_window_close(ctx, "Basic Demo");
if (zr_checkbox(ctx, "Button", &gui->show_button) && !gui->show_button)
zr_window_close(ctx, "Button Demo");
#endif
zr_layout_pop(ctx);
}
if (zr_layout_push(ctx, ZR_LAYOUT_TAB, "Metrics", ZR_MINIMIZED)) {
zr_layout_row_dynamic(ctx, 20, 2);
zr_label(ctx,"Total:", ZR_TEXT_LEFT);
@ -774,7 +811,7 @@ demo_window(struct zr_context *ctx)
sprintf(buffer, "%02d:%02d:%02d", sel_time.tm_hour, sel_time.tm_min, sel_time.tm_sec);
if (zr_combo_begin_text(ctx, &combo, buffer, 250)) {
time_selected = 1;
zr_layout_row_dynamic(ctx, 20, 1);
zr_layout_row_dynamic(ctx, 25, 1);
sel_time.tm_sec = zr_propertyi(ctx, "#S:", 0, sel_time.tm_sec, 60, 1, 1);
sel_time.tm_min = zr_propertyi(ctx, "#M:", 0, sel_time.tm_min, 60, 1, 1);
sel_time.tm_hour = zr_propertyi(ctx, "#H:", 0, sel_time.tm_hour, 23, 1, 1);
@ -784,7 +821,7 @@ demo_window(struct zr_context *ctx)
/* date combobox */
zr_layout_row_static(ctx, 25, 350, 1);
sprintf(buffer, "%02d-%02d-%02d", sel_date.tm_mday, sel_date.tm_mon+1, sel_date.tm_year+1900);
if (zr_combo_begin_text(ctx, &combo, buffer, 350)) {
if (zr_combo_begin_text(ctx, &combo, buffer, 400)) {
int i = 0;
const char *month[] = {"January", "February", "March", "Apil", "May", "June", "July", "August", "September", "Ocotober", "November", "December"};
const char *week_days[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
@ -806,7 +843,7 @@ demo_window(struct zr_context *ctx)
} else sel_date.tm_mon--;
}
zr_layout_row_push(ctx, 0.9f);
sprintf(buffer, "%s %0000d", month[sel_date.tm_mon], year);
sprintf(buffer, "%s %d", month[sel_date.tm_mon], year);
zr_label(ctx, buffer, ZR_TEXT_DEFAULT_CENTER);
zr_layout_row_push(ctx, 0.05f);
if (zr_button_symbol(ctx, ZR_SYMBOL_TRIANGLE_RIGHT, ZR_BUTTON_DEFAULT)) {
@ -2404,6 +2441,17 @@ run_demo(struct demo *gui)
struct zr_context *ctx = &gui->ctx;
if (!init) {
gui->show_demo = 0;
gui->show_node = 0;
gui->show_replay = 0;
gui->show_simple = 0;
#ifndef DEMO_DO_NOT_DRAW_IMAGES
gui->show_grid = 0;
gui->show_basic = 0;
gui->show_button = 0;
#endif
memset(&nodedit, 0, sizeof(nodedit));
zr_buffer_init_fixed(&record, record_memory, sizeof(record_memory));
record_window(ctx, &record);
@ -2411,17 +2459,24 @@ run_demo(struct demo *gui)
init = 1;
}
if (gui->show_simple)
simple_window(ctx);
if (gui->show_replay)
replay_window(ctx, &record);
if (gui->show_demo)
demo_window(ctx);
if (gui->show_node)
node_editor_demo(ctx, &nodedit);
ret = control_window(ctx, gui);
#ifndef DEMO_DO_NOT_DRAW_IMAGES
if (gui->show_grid)
grid_demo(ctx);
if (gui->show_button)
button_demo(ctx, &gui->icons);
if (gui->show_basic)
basic_demo(ctx, &gui->icons);
#endif
ret = control_window(ctx, gui);
zr_buffer_info(&gui->status, &gui->ctx.memory);
return ret;
}

View File

@ -6967,6 +6967,7 @@ zr_pool_alloc(struct zr_pool *pool)
* CONTEXT
*
* ===============================================================*/
static void zr_remove_window(struct zr_context*, struct zr_window*);
static void* zr_create_window(struct zr_context *ctx);
static void zr_free_window(struct zr_context *ctx, struct zr_window *win);
static void zr_free_table(struct zr_context *ctx, struct zr_table *tbl);
@ -7120,10 +7121,10 @@ zr_clear(struct zr_context *ctx)
}}
/* window itself is not used anymore so free */
if (iter->seq != ctx->seq) {
if (iter->seq != ctx->seq || iter->flags & ZR_WINDOW_HIDDEN) {
next = iter->next;
zr_remove_window(ctx, iter);
zr_free_window(ctx, iter);
ctx->count--;
iter = next;
} else iter = iter->next;
}
@ -7290,7 +7291,11 @@ zr__next(struct zr_context *ctx, const struct zr_command *cmd)
* ---------------------------------------------------------------*/
static struct zr_table*
zr_create_table(struct zr_context *ctx)
{void *tbl = (void*)zr_create_window(ctx); return (struct zr_table*)tbl;}
{
void *tbl = (void*)zr_create_window(ctx);
zr_zero(tbl, sizeof(struct zr_table));
return (struct zr_table*)tbl;
}
static void
zr_free_table(struct zr_context *ctx, struct zr_table *tbl)
@ -7504,7 +7509,9 @@ zr_create_window(struct zr_context *ctx)
ZR_ASSERT(win);
if (!win) return 0;
}
zr_zero(win, sizeof(union zr_page_data));
zr_zero(win, sizeof(*win));
win->next = 0;
win->prev = 0;
win->seq = ctx->seq;
return win;
}
@ -7514,21 +7521,6 @@ zr_free_window(struct zr_context *ctx, struct zr_window *win)
{
/* unlink windows from list */
struct zr_table *n, *it = win->tables;
if (win == ctx->begin) {
ctx->begin = win->next;
if (win->next)
ctx->begin->prev = 0;
} else if (win == ctx->end) {
ctx->end = win->prev;
if (win->prev)
ctx->end->next = 0;
} else {
if (win->next)
win->next->prev = win->next;
if (win->prev)
win->prev->next = win->prev;
}
if (win->popup.win) {
zr_free_window(ctx, win->popup.win);
win->popup.win = 0;
@ -7564,6 +7556,7 @@ zr_find_window(struct zr_context *ctx, zr_hash hash)
struct zr_window *iter;
iter = ctx->begin;
while (iter) {
ZR_ASSERT(iter != iter->next);
if (iter->name == hash)
return iter;
iter = iter->next;
@ -7582,6 +7575,8 @@ zr_insert_window(struct zr_context *ctx, struct zr_window *win)
iter = ctx->begin;
while (iter) {
ZR_ASSERT(iter != iter->next);
ZR_ASSERT(iter != win);
if (iter == win) return;
iter = iter->next;
}
@ -7606,14 +7601,28 @@ zr_insert_window(struct zr_context *ctx, struct zr_window *win)
static void
zr_remove_window(struct zr_context *ctx, struct zr_window *win)
{
if (win == ctx->begin || win == ctx->end) {
if (win == ctx->begin) {
ctx->begin = win->next;
if (win->next)
win->next->prev = 0;
}
if (win == ctx->end) {
ctx->end = win->prev;
if (win->prev)
win->prev->next = win->next;
win->prev->next = 0;
}
} else {
if (win->next)
win->next->prev = win->prev;
if (ctx->begin == win)
ctx->begin = win->next;
if (ctx->end == win)
ctx->end = win->prev;
if (win->prev)
win->prev->next = win->next;
}
if (win == ctx->active) {
ctx->active = ctx->end;
if (ctx->end)
ctx->end->flags &= ~(zr_flags)ZR_WINDOW_ROM;
}
win->next = 0;
win->prev = 0;
@ -8038,13 +8047,13 @@ zr_window_is_closed(struct zr_context *ctx, const char *name)
zr_hash title_hash;
struct zr_window *win;
ZR_ASSERT(ctx);
if (!ctx) return 0;
if (!ctx) return 1;
title_len = (int)zr_strsiz(name);
title_hash = zr_murmur_hash(name, (int)title_len, ZR_WINDOW_TITLE);
win = zr_find_window(ctx, title_hash);
if (!win) return 0;
return win->flags & ZR_WINDOW_HIDDEN;
if (!win) return 1;
return (win->flags & ZR_WINDOW_HIDDEN);
}
int
@ -8076,6 +8085,8 @@ zr_window_close(struct zr_context *ctx, const char *name)
title_hash = zr_murmur_hash(name, (int)title_len, ZR_WINDOW_TITLE);
win = zr_find_window(ctx, title_hash);
if (!win) return;
ZR_ASSERT(ctx->current != win && "You cannot close a current window");
if (ctx->current == win) return;
win->flags |= ZR_WINDOW_HIDDEN;
}
@ -13508,6 +13519,7 @@ zr_recording_end(struct zr_context *ctx)
union zr_param p[2];
union zr_event evt;
struct zr_event_queue queue;
zr_size size;
ZR_ASSERT(ctx);
ZR_ASSERT(ctx->op_buffer);
@ -13518,8 +13530,10 @@ zr_recording_end(struct zr_context *ctx)
zr_event_queue_init_fixed(&queue, 0, &evt, 1);
zr_op_handle(ctx, p, &queue);
size = ctx->memory.size;
ctx->op_buffer = 0;
ctx->memory = ctx->op_memory;
ctx->memory.size = size;
ctx->next_id = 0;
}

View File

@ -1724,7 +1724,7 @@ int zr_window_is_collapsed(struct zr_context*, const char*);
int zr_window_is_closed(struct zr_context*, const char*);
int zr_window_is_active(struct zr_context*, const char*);
void zr_window_close(struct zr_context*, const char *name);
void zr_window_close(struct zr_context *ctx, const char *name);
void zr_window_set_bounds(struct zr_context*, struct zr_rect);
void zr_window_set_position(struct zr_context*, struct zr_vec2);
void zr_window_set_size(struct zr_context*, struct zr_vec2);