From 193f53ce6b6e3d94b1f4da86bd2fce7b1d33a58d Mon Sep 17 00:00:00 2001 From: vurtun Date: Tue, 24 Nov 2015 14:36:28 +0100 Subject: [PATCH] fixed horizontal popup scrollbars + added font stack to zr_style --- zahnrad.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- zahnrad.h | 57 ++++++++++++++++++++++++++++++++++-- 2 files changed, 139 insertions(+), 5 deletions(-) diff --git a/zahnrad.c b/zahnrad.c index 0a0deee..166a283 100644 --- a/zahnrad.c +++ b/zahnrad.c @@ -5592,6 +5592,35 @@ zr_style_push_property(struct zr_style *style, enum zr_style_properties index, style->properties[index] = v; } +void +zr_style_push_font(struct zr_style *style, struct zr_user_font font) +{ + struct zr_saved_font *f; + ZR_ASSERT(style); + if (!style) return; + if (style->stack.font >= ZR_MAX_FONT_STACK) return; + + f = &style->stack.fonts[style->stack.font++]; + f->font_height_begin = style->stack.font_height; + f->font_height_end = style->stack.font_height; + f->value = style->font; + style->font = font; +} + +void +zr_style_push_font_height(struct zr_style *style, float font_height) +{ + struct zr_saved_font *f; + ZR_ASSERT(style); + if (!style) return; + if (style->stack.font >= ZR_MAX_FONT_HEIGHT_STACK) return; + + style->stack.font_heights[style->stack.font_height++] = style->font.height; + if (style->stack.font) + style->stack.fonts[style->stack.font-1].font_height_end++; + style->font.height = font_height; +} + void zr_style_pop_color(struct zr_style *style) { @@ -5614,6 +5643,36 @@ zr_style_pop_property(struct zr_style *style) style->properties[p->type] = p->value; } +void +zr_style_pop_font(struct zr_style *style) +{ + struct zr_saved_font *f; + ZR_ASSERT(style); + if (!style) return; + if (!style->stack.font) return; + + f = &style->stack.fonts[--style->stack.font]; + style->stack.font_height = f->font_height_begin; + style->font = f->value; + if (style->stack.font_height) + style->font.height = style->stack.font_heights[style->stack.font_height-1]; +} + +void +zr_style_pop_font_height(struct zr_style *style) +{ + float font_height; + ZR_ASSERT(style); + if (!style) return; + if (!style->stack.font_height) return; + font_height = style->stack.font_heights[--style->stack.font_height]; + style->font.height = font_height; + if (style->stack.font) { + ZR_ASSERT(style->stack.fonts[style->stack.font-1].font_height_end); + style->stack.fonts[style->stack.font-1].font_height_end--; + } +} + void zr_style_reset_colors(struct zr_style *style) { @@ -5632,6 +5691,24 @@ zr_style_reset_properties(struct zr_style *style) zr_style_pop_property(style); } +void +zr_style_reset_font(struct zr_style *style) +{ + ZR_ASSERT(style); + if (!style) return; + while (style->stack.font) + zr_style_pop_font(style); +} + +void +zr_style_reset_font_height(struct zr_style *style) +{ + ZR_ASSERT(style); + if (!style) return; + while (style->stack.font_height) + zr_style_pop_font_height(style); +} + void zr_style_reset(struct zr_style *style) { @@ -5639,6 +5716,8 @@ zr_style_reset(struct zr_style *style) if (!style) return; zr_style_reset_colors(style); zr_style_reset_properties(style); + zr_style_reset_font(style); + zr_style_reset_font_height(style); } /* ============================================================== @@ -5930,7 +6009,7 @@ zr_begin(struct zr_context *context, struct zr_window *window, const char *title context->row.height = 0; } else { context->header_h = 2 * item_spacing.y; - context->row.height = context->header_h; + context->row.height = context->header_h + 1; } /* window activation by click inside */ @@ -5950,7 +6029,8 @@ zr_begin(struct zr_context *context, struct zr_window *window, const char *title !(window->flags & ZR_WINDOW_MINIMIZED); /* calculate window footer height */ - if ((window->flags & ZR_WINDOW_SCALEABLE)) + if (!(window->flags & ZR_WINDOW_COMBO_MENU) && + (!(window->flags & ZR_WINDOW_NO_SCROLLBAR) || (window->flags & ZR_WINDOW_SCALEABLE))) context->footer_h = scaler_size.y + item_padding.y; else context->footer_h = 0; @@ -6069,12 +6149,13 @@ zr_begin(struct zr_context *context, struct zr_window *window, const char *title context->clip.h = window->bounds.h - (context->footer_h + context->header_h); context->clip.h -= (window_padding.y + item_padding.y); context->clip.y = window->bounds.y; - if (!(window->flags & ZR_WINDOW_COMBO_MENU) && header_active) + if (!(window->flags & ZR_WINDOW_COMBO_MENU)) context->clip.y += context->header_h; if (window->flags & ZR_WINDOW_BORDER) { context->clip.y += 1; context->clip.h -= 1; } + zr_unify(&clip, &context->buffer->clip, context->clip.x, context->clip.y, context->clip.x + context->clip.w, context->clip.y + context->clip.h); zr_command_buffer_push_scissor(out, clip); diff --git a/zahnrad.h b/zahnrad.h index cb22a98..edd361b 100644 --- a/zahnrad.h +++ b/zahnrad.h @@ -39,6 +39,10 @@ extern "C" { /* defines the number of temporary configuration color changes that can be stored */ #define ZR_MAX_ATTRIB_STACK 32 /* defines the number of temporary configuration attribute changes that can be stored */ +#define ZR_MAX_FONT_STACK 32 +/* defines the number of temporary configuration user font changes that can be stored */ +#define ZR_MAX_FONT_HEIGHT_STACK 32 +/* defines the number of temporary configuration font height changes that can be stored */ /* * ============================================================== * @@ -1877,6 +1881,15 @@ struct zr_saved_color { /* color value that has been saveed */ }; +struct zr_saved_font { + struct zr_user_font value; + /* user font reference */ + zr_size font_height_begin; + /* style font height stack begin */ + zr_size font_height_end; + /* user font height stack end */ +}; + enum zr_style_components { ZR_DEFAULT_COLOR = 0x01, /* default all colors inside the configuration struct */ @@ -1893,10 +1906,18 @@ struct zr_style_mod_stack { /* current property stack pushing index */ struct zr_saved_property properties[ZR_MAX_ATTRIB_STACK]; /* saved property stack */ - struct zr_saved_color colors[ZR_MAX_COLOR_STACK]; - /* saved color stack */ zr_size color; /* current color stack pushing index */ + struct zr_saved_color colors[ZR_MAX_COLOR_STACK]; + /* saved color stack */ + zr_size font; + /* current font stack pushing index */ + struct zr_saved_font fonts[ZR_MAX_FONT_STACK]; + /* saved user font stack */ + zr_size font_height; + /* current font stack pushing index */ + float font_heights[ZR_MAX_FONT_HEIGHT_STACK]; + /* saved user font stack */ }; struct zr_style_header { @@ -1969,6 +1990,18 @@ void zr_style_push_color(struct zr_style*, enum zr_style_colors, struct zr_color - color idenfifier to change - new color */ +void zr_style_push_font(struct zr_style*, struct zr_user_font font); +/* this function temporarily changes the used font in a stack like fashion to be reseted later + Input: + - Configuration structure to push the change to + - user font to use from now on +*/ +void zr_style_push_font_height(struct zr_style*, float font_height); +/* this function temporarily changes the used font in a stack like fashion to be reseted later + Input: + - Configuration structure to push the change to + - user font to use from now on +*/ void zr_style_pop_color(struct zr_style*); /* this function reverts back a previously pushed temporary color change Input: @@ -1979,6 +2012,16 @@ void zr_style_pop_property(struct zr_style*); Input: - Configuration structure to pop the change from and to */ +void zr_style_pop_font(struct zr_style*); +/* this function reverts back a previously pushed temporary font change + Input: + - Configuration structure to pop the change from and to +*/ +void zr_style_pop_font_height(struct zr_style*); +/* this function reverts back a previously pushed temporary font height change + Input: + - Configuration structure to pop the change from and to +*/ void zr_style_reset_colors(struct zr_style*); /* this function reverts back all previously pushed temporary color changes Input: @@ -1989,6 +2032,16 @@ void zr_style_reset_properties(struct zr_style*); Input: - Configuration structure to pop the change from and to */ +void zr_style_reset_font(struct zr_style*); +/* this function reverts back all previously pushed temporary font changes + Input: + - Configuration structure to pop the change from and to +*/ +void zr_style_reset_font_height(struct zr_style*); +/* this function reverts back all previously pushed temporary font height changes + Input: + - Configuration structure to pop the change from and to +*/ void zr_style_reset(struct zr_style*); /* this function reverts back all previously pushed temporary color and * property changes