diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 75fa67f..a806978 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -26,7 +26,6 @@ If you have an idea for new features just [open an issue](https://github.com/vur * Seperator widget is currently bugged and does not work as intended * Text handling is still a little bit janky and probably needs to be further tested and polished * `zr_edit_buffer` with multiline flag is bugged for '\n', need to differentiate between visible and non-visible characters - * Currently you cannot open popups (combobox, popup, contextual, ...) inside groups ## Coding conventions * Only use C89 (ANSI C) diff --git a/demo/demo.c b/demo/demo.c index 1d8b7be..2cb95da 100644 --- a/demo/demo.c +++ b/demo/demo.c @@ -255,7 +255,7 @@ control_window(struct zr_context *ctx, struct demo *gui) { int i; struct zr_panel layout; - if (zr_begin(ctx, &layout, "Control", zr_rect(0, 0, 350, 500), + if (zr_begin(ctx, &layout, "Control", zr_rect(0, 0, 350, 520), ZR_WINDOW_CLOSABLE|ZR_WINDOW_MINIMIZABLE|ZR_WINDOW_MOVABLE| ZR_WINDOW_SCALABLE|ZR_WINDOW_BORDER)) { @@ -291,7 +291,7 @@ control_window(struct zr_context *ctx, struct demo *gui) } if (zr_layout_push(ctx, ZR_LAYOUT_NODE, "Color", ZR_MINIMIZED)) { - struct zr_panel combo; + struct zr_panel tab, combo; enum theme old = gui->theme; static const char *themes[] = {"Black", "White", "Red", "Blue", "Dark", "Grey"}; @@ -307,17 +307,23 @@ control_window(struct zr_context *ctx, struct demo *gui) if (old != gui->theme) set_style(ctx, gui->theme); zr_combo_end(ctx); } - for (i = 0; i < ZR_COLOR_COUNT; ++i) { - zr_layout_row_dynamic(ctx, 25, 2); - zr_label(ctx, zr_get_color_name((enum zr_style_colors)i), ZR_TEXT_LEFT); - if (zr_combo_begin_color(ctx, &combo, ctx->style.colors[i], 200)) { - zr_layout_row_dynamic(ctx, 25, 1); - ctx->style.colors[i].r = (zr_byte)zr_propertyi(ctx, "#R:", 0, ctx->style.colors[i].r, 255, 1,1); - ctx->style.colors[i].g = (zr_byte)zr_propertyi(ctx, "#G:", 0, ctx->style.colors[i].g, 255, 1,1); - ctx->style.colors[i].b = (zr_byte)zr_propertyi(ctx, "#B:", 0, ctx->style.colors[i].b, 255, 1,1); - ctx->style.colors[i].a = (zr_byte)zr_propertyi(ctx, "#A:", 0, ctx->style.colors[i].a, 255, 1,1); - zr_combo_end(ctx); + + zr_layout_row_dynamic(ctx, 300, 1); + if (zr_group_begin(ctx, &tab, "Colors", 0)) + { + for (i = 0; i < ZR_COLOR_COUNT; ++i) { + zr_layout_row_dynamic(ctx, 25, 2); + zr_label(ctx, zr_get_color_name((enum zr_style_colors)i), ZR_TEXT_LEFT); + if (zr_combo_begin_color(ctx, &combo, ctx->style.colors[i], 200)) { + zr_layout_row_dynamic(ctx, 25, 1); + ctx->style.colors[i].r = (zr_byte)zr_propertyi(ctx, "#R:", 0, ctx->style.colors[i].r, 255, 1,1); + ctx->style.colors[i].g = (zr_byte)zr_propertyi(ctx, "#G:", 0, ctx->style.colors[i].g, 255, 1,1); + ctx->style.colors[i].b = (zr_byte)zr_propertyi(ctx, "#B:", 0, ctx->style.colors[i].b, 255, 1,1); + ctx->style.colors[i].a = (zr_byte)zr_propertyi(ctx, "#A:", 0, ctx->style.colors[i].a, 255, 1,1); + zr_combo_end(ctx); + } } + zr_group_end(ctx); } zr_layout_pop(ctx); } diff --git a/demo/nodedit.c b/demo/nodedit.c index d2ce2a6..313b877 100644 --- a/demo/nodedit.c +++ b/demo/nodedit.c @@ -177,7 +177,6 @@ node_editor_demo(struct zr_context *ctx, struct node_editor *nodedit) /* ====================================================*/ zr_group_end(ctx); } - { /* node connector and linking */ float space; diff --git a/zahnrad.c b/zahnrad.c index 46024b3..556fbf3 100644 --- a/zahnrad.c +++ b/zahnrad.c @@ -6738,11 +6738,18 @@ static void zr_start_popup(struct zr_context *ctx, struct zr_window *win) { struct zr_popup_buffer *buf; + struct zr_panel *iter; ZR_ASSERT(ctx); ZR_ASSERT(win); if (!ctx || !win) return; - buf = &win->layout->popup_buffer; + /* make sure to use the correct popup buffer*/ + iter = win->layout; + while (iter->parent) + iter = iter->parent; + + /* save buffer fill state for popup */ + buf = &iter->popup_buffer; buf->begin = win->buffer.end; buf->end = win->buffer.end; buf->parent = win->buffer.last; @@ -6754,12 +6761,17 @@ static void zr_finish_popup(struct zr_context *ctx, struct zr_window *win) { struct zr_popup_buffer *buf; + struct zr_panel *iter; ZR_ASSERT(ctx); ZR_ASSERT(win); if (!ctx || !win) return; - /* */ - buf = &win->layout->popup_buffer; + /* make sure to use the correct popup buffer*/ + iter = win->layout; + while (iter->parent) + iter = iter->parent; + + buf = &iter->popup_buffer; buf->last = win->buffer.last; buf->end = win->buffer.end; } @@ -10707,6 +10719,7 @@ zr_combo_begin_text(struct zr_context *ctx, struct zr_panel *layout, struct zr_rect bounds = {0,0,0,0}; zr_size text_len = zr_strsiz(selected); + /* draw selected label */ text.padding = zr_vec2(0,0); text.background = ctx->style.colors[ZR_COLOR_COMBO]; text.text = ctx->style.colors[ZR_COLOR_TEXT]; @@ -10771,6 +10784,7 @@ zr_combo_begin_color(struct zr_context *ctx, struct zr_panel *layout, struct zr_symbol sym; struct zr_rect bounds = {0,0,0,0}; + /* draw color */ content.h = header.h - 4 * item_padding.y; content.y = header.y + 2 * item_padding.y; content.x = header.x + 2 * item_padding.x; @@ -10830,6 +10844,7 @@ zr_combo_begin_image(struct zr_context *ctx, struct zr_panel *layout, struct zr_symbol sym; struct zr_rect content; + /* draw image */ content.h = header.h - 4 * item_padding.y; content.y = header.y + 2 * item_padding.y; content.x = header.x + 2 * item_padding.x; @@ -10892,12 +10907,14 @@ zr_combo_begin_icon(struct zr_context *ctx, struct zr_panel *layout, content.x = header.x + 2 * item_padding.x; content.w = header.w - (header.h + 4 * item_padding.x); + /* draw icon */ icon.x = content.x; icon.y = content.y; icon.h = content.h; icon.w = icon.h; zr_draw_image(&win->buffer, icon, &img); + /* draw label */ label.x = icon.x + icon.w + 2 * item_padding.x; label.y = content.y; label.w = (content.x + content.w) - (icon.x + icon.w); @@ -10911,6 +10928,7 @@ zr_combo_begin_icon(struct zr_context *ctx, struct zr_panel *layout, bounds.w = bounds.h = ctx->style.font.height; bounds.x = (header.x + header.w) - (bounds.w + 2 * item_padding.x); + /* draw open/close symbol */ sym.type = ZR_SYMBOL_TRIANGLE_DOWN; sym.background = ctx->style.colors[ZR_COLOR_COMBO]; sym.foreground = ctx->style.colors[ZR_COLOR_TEXT];