Finally fixed customizable window border width

Previously all window, popup, comboboxes, tooltips, menu and
contextuals had a fixed border width of 1 and had the same color.
Now it is possible to change the individual border width and color of
each one seperatly.
This commit is contained in:
vurtun 2016-04-01 18:15:49 +02:00
parent 803e369a40
commit d9f1831321
3 changed files with 115 additions and 53 deletions

View File

@ -2414,8 +2414,6 @@ set_style(struct zr_context *ctx, enum theme theme)
table[ZR_COLOR_SLIDER_CURSOR_HOVER] = zr_rgba(70, 70, 70, 255);
table[ZR_COLOR_SLIDER_CURSOR_ACTIVE] = zr_rgba(60, 60, 60, 255);
table[ZR_COLOR_PROPERTY] = zr_rgba(175, 175, 175, 255);
table[ZR_COLOR_PROPERTY_HOVER] = zr_rgba(160, 160, 160, 255);
table[ZR_COLOR_PROPERTY_ACTIVE] = zr_rgba(165, 165, 165, 255);
table[ZR_COLOR_EDIT] = zr_rgba(150, 150, 150, 255);
table[ZR_COLOR_EDIT_CURSOR] = zr_rgba(0, 0, 0, 255);
table[ZR_COLOR_COMBO] = zr_rgba(175, 175, 175, 255);
@ -2447,8 +2445,6 @@ set_style(struct zr_context *ctx, enum theme theme)
table[ZR_COLOR_SLIDER_CURSOR_HOVER] = zr_rgba(186, 50, 74, 255);
table[ZR_COLOR_SLIDER_CURSOR_ACTIVE] = zr_rgba(191, 55, 79, 255);
table[ZR_COLOR_PROPERTY] = zr_rgba(51, 55, 67, 255);
table[ZR_COLOR_PROPERTY_HOVER] = zr_rgba(55, 60, 72, 255);
table[ZR_COLOR_PROPERTY_ACTIVE] = zr_rgba(60, 65, 77, 255);
table[ZR_COLOR_EDIT] = zr_rgba(51, 55, 67, 225);
table[ZR_COLOR_EDIT_CURSOR] = zr_rgba(190, 190, 190, 255);
table[ZR_COLOR_COMBO] = zr_rgba(51, 55, 67, 255);
@ -2480,8 +2476,6 @@ set_style(struct zr_context *ctx, enum theme theme)
table[ZR_COLOR_SLIDER_CURSOR_HOVER] = zr_rgba(142, 188, 229, 255);
table[ZR_COLOR_SLIDER_CURSOR_ACTIVE] = zr_rgba(147, 193, 234, 255);
table[ZR_COLOR_PROPERTY] = zr_rgba(210, 210, 210, 255);
table[ZR_COLOR_PROPERTY_HOVER] = zr_rgba(235, 235, 235, 255);
table[ZR_COLOR_PROPERTY_ACTIVE] = zr_rgba(230, 230, 230, 255);
table[ZR_COLOR_EDIT] = zr_rgba(210, 210, 210, 225);
table[ZR_COLOR_EDIT_CURSOR] = zr_rgba(20, 20, 20, 255);
table[ZR_COLOR_COMBO] = zr_rgba(210, 210, 210, 255);
@ -2513,8 +2507,6 @@ set_style(struct zr_context *ctx, enum theme theme)
table[ZR_COLOR_SLIDER_CURSOR_HOVER] = zr_rgba(53, 88, 116, 255);
table[ZR_COLOR_SLIDER_CURSOR_ACTIVE] = zr_rgba(58, 93, 121, 255);
table[ZR_COLOR_PROPERTY] = zr_rgba(50, 58, 61, 255);
table[ZR_COLOR_PROPERTY_HOVER] = zr_rgba(55, 63, 66, 255);
table[ZR_COLOR_PROPERTY_ACTIVE] = zr_rgba(60, 68, 71, 255);
table[ZR_COLOR_EDIT] = zr_rgba(50, 58, 61, 225);
table[ZR_COLOR_EDIT_CURSOR] = zr_rgba(210, 210, 210, 255);
table[ZR_COLOR_COMBO] = zr_rgba(50, 58, 61, 255);

144
zahnrad.c
View File

@ -7689,8 +7689,6 @@ void zr_style_default(struct zr_context *ctx){zr_style_from_table(ctx, 0);}
ZR_COLOR(ZR_COLOR_SLIDER_CURSOR_HOVER, 120,120,120,255) \
ZR_COLOR(ZR_COLOR_SLIDER_CURSOR_ACTIVE, 150,150,150,255) \
ZR_COLOR(ZR_COLOR_PROPERTY, 38, 38, 38,255) \
ZR_COLOR(ZR_COLOR_PROPERTY_HOVER, 40, 40, 40,255) \
ZR_COLOR(ZR_COLOR_PROPERTY_ACTIVE, 42, 42, 42,255) \
ZR_COLOR(ZR_COLOR_EDIT, 38, 38, 38,255) \
ZR_COLOR(ZR_COLOR_EDIT_CURSOR, 175,175,175,255) \
ZR_COLOR(ZR_COLOR_COMBO, 45, 45, 45,255) \
@ -8008,8 +8006,8 @@ zr_style_from_table(struct zr_context *ctx, const struct zr_color *table)
property = &style->property;
zr_zero_struct(*property);
property->normal = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
property->hover = zr_style_item_color(table[ZR_COLOR_PROPERTY_HOVER]);
property->active = zr_style_item_color(table[ZR_COLOR_PROPERTY_ACTIVE]);
property->hover = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
property->active = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
property->border_color = table[ZR_COLOR_BORDER];
property->label_normal = table[ZR_COLOR_TEXT];
property->label_hover = table[ZR_COLOR_TEXT];
@ -8028,8 +8026,8 @@ zr_style_from_table(struct zr_context *ctx, const struct zr_color *table)
button = &style->property.dec_button;
zr_zero_struct(*button);
button->normal = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
button->hover = zr_style_item_color(table[ZR_COLOR_PROPERTY_HOVER]);
button->active = zr_style_item_color(table[ZR_COLOR_PROPERTY_ACTIVE]);
button->hover = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
button->active = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
button->border_color = zr_rgba(0,0,0,0);
button->text_background = table[ZR_COLOR_PROPERTY];
button->text_normal = table[ZR_COLOR_TEXT];
@ -8049,8 +8047,8 @@ zr_style_from_table(struct zr_context *ctx, const struct zr_color *table)
edit = &style->property.edit;
zr_zero_struct(*edit);
edit->normal = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
edit->hover = zr_style_item_color(table[ZR_COLOR_PROPERTY_HOVER]);
edit->active = zr_style_item_color(table[ZR_COLOR_PROPERTY_ACTIVE]);
edit->hover = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
edit->active = zr_style_item_color(table[ZR_COLOR_PROPERTY]);
edit->cursor_normal = zr_style_item_color(table[ZR_COLOR_EDIT_CURSOR]);
edit->cursor_hover = zr_style_item_color(table[ZR_COLOR_EDIT_CURSOR]);
edit->cursor_active = zr_style_item_color(table[ZR_COLOR_EDIT_CURSOR]);
@ -8234,18 +8232,27 @@ zr_style_from_table(struct zr_context *ctx, const struct zr_color *table)
win->background = table[ZR_COLOR_WINDOW];
win->fixed_background = zr_style_item_color(table[ZR_COLOR_WINDOW]);
win->border_color = table[ZR_COLOR_BORDER];
win->combo_border_color = table[ZR_COLOR_BORDER];
win->contextual_border_color = table[ZR_COLOR_BORDER];
win->menu_border_color = table[ZR_COLOR_BORDER];
win->group_border_color = table[ZR_COLOR_BORDER];
win->tooltip_border_color = table[ZR_COLOR_BORDER];
win->scaler = zr_style_item_color(table[ZR_COLOR_TEXT]);
win->footer_padding = zr_vec2(4,4);
win->border = 1.0f;
win->rounding = 0.0f;
win->scaler_size = zr_vec2(16,16);
win->padding = zr_vec2(8,8);
win->spacing = zr_vec2(4,4);
win->scrollbar_size = zr_vec2(10,10);
win->min_size = zr_vec2(64,64);
win->combo_border = 1.0f;
win->contextual_border = 1.0f;
win->menu_border = 1.0f;
win->group_border = 1.0f;
win->tooltip_border = 1.0f;
win->border = 2.0f;
}
void
zr_style_set_font(struct zr_context *ctx, const struct zr_user_font *font)
{
@ -9435,12 +9442,29 @@ zr_panel_begin(struct zr_context *ctx, const char *title)
win->buffer.userdata = ctx->userdata;
#endif
/* setup window layout */
layout->bounds = win->bounds;
layout->at_x = win->bounds.x;
layout->at_y = win->bounds.y;
layout->width = win->bounds.w;
layout->height = win->bounds.h;
/* panel space without border */
if (win->flags & ZR_WINDOW_BORDER) {
if (!(win->flags & ZR_WINDOW_SUB))
layout->bounds = zr_shrink_rect(win->bounds, style->window.border);
else if (win->flags & ZR_WINDOW_COMBO)
layout->bounds = zr_shrink_rect(win->bounds, style->window.combo_border);
else if (win->flags & ZR_WINDOW_CONTEXTUAL)
layout->bounds = zr_shrink_rect(win->bounds, style->window.contextual_border);
else if (win->flags & ZR_WINDOW_MENU)
layout->bounds = zr_shrink_rect(win->bounds, style->window.menu_border);
else if (win->flags & ZR_WINDOW_GROUP)
layout->bounds = zr_shrink_rect(win->bounds, style->window.group_border);
else if (win->flags & ZR_WINDOW_TOOLTIP)
layout->bounds = zr_shrink_rect(win->bounds, style->window.tooltip_border);
else layout->bounds = zr_shrink_rect(win->bounds, style->window.border);
} else layout->bounds = win->bounds;
/* setup panel */
layout->border = layout->bounds.x - win->bounds.x;
layout->at_x = layout->bounds.x;
layout->at_y = layout->bounds.y;
layout->width = layout->bounds.w;
layout->height = layout->bounds.h;
layout->max_x = 0;
layout->row.index = 0;
layout->row.columns = 0;
@ -9468,8 +9492,8 @@ zr_panel_begin(struct zr_context *ctx, const char *title)
/* calculate the window size */
if (!(win->flags & ZR_WINDOW_NO_SCROLLBAR))
layout->width = win->bounds.w - scrollbar_size.x;
layout->height = win->bounds.h - (layout->header_h + 2 * item_spacing.y);
layout->width = layout->bounds.w - scrollbar_size.x;
layout->height = layout->bounds.h - (layout->header_h + 2 * item_spacing.y);
layout->height -= layout->footer_h;
/* window header state */
@ -9609,28 +9633,41 @@ zr_panel_begin(struct zr_context *ctx, const char *title)
/* draw top window border line */
if (layout->flags & ZR_WINDOW_BORDER) {
zr_stroke_line(out, layout->bounds.x, layout->bounds.y,
layout->bounds.x + layout->bounds.w, layout->bounds.y, style->window.border,
style->window.border_color);
struct zr_color border;
if (!(win->flags & ZR_WINDOW_SUB))
border = style->window.border_color;
else if (win->flags & ZR_WINDOW_COMBO)
border = style->window.combo_border_color;
else if (win->flags & ZR_WINDOW_CONTEXTUAL)
border = style->window.contextual_border_color;
else if (win->flags & ZR_WINDOW_MENU)
border = style->window.menu_border_color;
else if (win->flags & ZR_WINDOW_GROUP)
border = style->window.group_border_color;
else if (win->flags & ZR_WINDOW_TOOLTIP)
border = style->window.tooltip_border_color;
else border = style->window.border_color;
zr_stroke_line(out,
win->bounds.x + layout->border/2.0f,
win->bounds.y + layout->border/2.0f,
win->bounds.x + win->bounds.w - layout->border,
win->bounds.y + layout->border/2.0f,
style->window.border, border);
}
{
/* calculate and set the window clipping rectangle*/
struct zr_rect clip;
if (!(win->flags & ZR_WINDOW_DYNAMIC)) {
layout->clip.x = win->bounds.x + window_padding.x;
layout->clip.x = layout->bounds.x + window_padding.x;
layout->clip.w = layout->width - 2 * window_padding.x;
} else {
layout->clip.x = win->bounds.x;
layout->clip.x = layout->bounds.x;
layout->clip.w = layout->width;
}
layout->clip.h = win->bounds.h - (layout->footer_h + layout->header_h);
layout->clip.h = layout->bounds.h - (layout->footer_h + layout->header_h);
layout->clip.h -= (2.0f * window_padding.y);
layout->clip.y = win->bounds.y;
if (win->flags & ZR_WINDOW_BORDER) {
layout->clip.y += style->window.border;
layout->clip.h -= 2.0f * style->window.border;
}
layout->clip.y = layout->bounds.y;
/* combo box and menu do not have header space */
if (!(win->flags & ZR_WINDOW_COMBO) && !(win->flags & ZR_WINDOW_MENU))
@ -9833,26 +9870,47 @@ zr_panel_end(struct zr_context *ctx)
}
/* window border */
if (layout->flags & ZR_WINDOW_BORDER) {
const float width = (layout->flags & ZR_WINDOW_NO_SCROLLBAR) ?
layout->width: layout->width + scrollbar_size.x;
if (layout->flags & ZR_WINDOW_BORDER)
{
const float padding_y = (layout->flags & ZR_WINDOW_MINIMIZED) ?
window->bounds.y + layout->header_h:
(layout->flags & ZR_WINDOW_DYNAMIC)?
layout->footer_h + footer.y:
layout->bounds.y + layout->bounds.h;
struct zr_color border;
if (!(layout->flags & ZR_WINDOW_SUB))
border = style->window.border_color;
else if (layout->flags & ZR_WINDOW_COMBO)
border = style->window.combo_border_color;
else if (layout->flags & ZR_WINDOW_CONTEXTUAL)
border = style->window.contextual_border_color;
else if (layout->flags & ZR_WINDOW_MENU)
border = style->window.menu_border_color;
else if (layout->flags & ZR_WINDOW_GROUP)
border = style->window.group_border_color;
else if (layout->flags & ZR_WINDOW_TOOLTIP)
border = style->window.tooltip_border_color;
else border = style->window.border_color;
if (window->flags & ZR_WINDOW_BORDER_HEADER)
zr_stroke_line(out, window->bounds.x, window->bounds.y + layout->header_h,
window->bounds.x + window->bounds.w, window->bounds.y + layout->header_h,
style->window.border, style->window.border_color);
zr_stroke_line(out, window->bounds.x, padding_y, window->bounds.x + width,
padding_y, style->window.border, style->window.border_color);
zr_stroke_line(out, window->bounds.x, window->bounds.y, window->bounds.x,
padding_y, style->window.border, style->window.border_color);
zr_stroke_line(out, window->bounds.x + width, window->bounds.y,
window->bounds.x + width, padding_y, style->window.border,
style->window.border_color);
zr_stroke_line(out, window->bounds.x + layout->border/2.0f,
window->bounds.y + layout->header_h - layout->border,
window->bounds.x + window->bounds.w - layout->border,
window->bounds.y + layout->header_h - layout->border,
layout->border, border);
zr_stroke_line(out, window->bounds.x + layout->border/2.0f,
padding_y - layout->border,
window->bounds.x + window->bounds.w - layout->border,
padding_y - layout->border,
layout->border, border);
zr_stroke_line(out, window->bounds.x + layout->border/2.0f,
window->bounds.y + layout->border/2.0f, window->bounds.x + layout->border/2.0f,
padding_y - layout->border, layout->border, border);
zr_stroke_line(out, window->bounds.x + window->bounds.w - layout->border,
window->bounds.y + layout->border/2.0f,
window->bounds.x + window->bounds.w - layout->border,
padding_y - layout->border, layout->border, border);
}
if (!(window->flags & ZR_WINDOW_SUB)) {
@ -12184,6 +12242,8 @@ zr_group_end(struct zr_context *ctx)
ctx->current = win;
win->layout = parent;
win->bounds = parent->bounds;
if (win->flags & ZR_WINDOW_BORDER)
win->bounds = zr_shrink_rect(win->bounds, -win->layout->border);
return;
}

View File

@ -1605,13 +1605,24 @@ struct zr_style_window {
struct zr_style_window_header header;
struct zr_style_item fixed_background;
struct zr_color background;
struct zr_color border_color;
struct zr_color combo_border_color;
struct zr_color contextual_border_color;
struct zr_color menu_border_color;
struct zr_color group_border_color;
struct zr_color tooltip_border_color;
struct zr_style_item scaler;
struct zr_vec2 footer_padding;
float border;
float fixed_border;
float combo_border;
float contextual_border;
float menu_border;
float group_border;
float tooltip_border;
float rounding;
struct zr_vec2 scaler_size;
struct zr_vec2 padding;
@ -1661,8 +1672,6 @@ enum zr_style_colors {
ZR_COLOR_SLIDER_CURSOR_HOVER,
ZR_COLOR_SLIDER_CURSOR_ACTIVE,
ZR_COLOR_PROPERTY,
ZR_COLOR_PROPERTY_HOVER,
ZR_COLOR_PROPERTY_ACTIVE,
ZR_COLOR_EDIT,
ZR_COLOR_EDIT_CURSOR,
ZR_COLOR_COMBO,
@ -1848,6 +1857,7 @@ struct zr_panel {
float width, height;
float footer_h;
float header_h;
float border;
struct zr_rect clip;
struct zr_menu_state menu;
struct zr_row_layout row;