diff options
| author | Federico Angelilli <code@fedang.net> | 2023-11-26 22:02:36 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2023-11-26 22:02:36 +0100 |
| commit | 114f5b6cbe6624acb2b720b99fe372bec7d7649e (patch) | |
| tree | 44e7a14603b20617e914c6344bd3516c1af14343 /src/draw.c | |
| parent | 399ba1141286e2b224275c2b33f05d349ad6e8e9 (diff) | |
Add padding for buttons and fix drawing
Diffstat (limited to 'src/draw.c')
| -rw-r--r-- | src/draw.c | 29 |
1 files changed, 22 insertions, 7 deletions
@@ -64,7 +64,6 @@ void draw_paint(Drawable *draw, Window *win) cairo_set_fill_rule(cr, CAIRO_FILL_RULE_EVEN_ODD); cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); - int radius = height / 2; double degree = M_PI / 180.0; cairo_set_source_rgba(cr, draw->background.r, draw->background.g, draw->background.b, draw->background.a); @@ -75,6 +74,7 @@ void draw_paint(Drawable *draw, Window *win) // This is caused by some difference between the two shapes (that should technically be the same) // which causes a mismatch between the two layers and leaves some black pixels visible + //int radius = height / 2; //cairo_arc(cr, radius, radius, radius, 90.0 * degree, 270 * degree); //cairo_arc(cr, width - radius, radius, radius, 270 * degree, 450 * degree); //cairo_fill(cr); @@ -87,6 +87,8 @@ void draw_paint(Drawable *draw, Window *win) for (GList *it = draw->layouts; it; it = it->next) { Layout *layout = it->data; + int radius = layout->height / 2; + Color color = layout->btn->color; cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a); cairo_new_sub_path(cr); @@ -192,8 +194,8 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) if (prev != NULL && prev->align == btn->align) x += sep; - layout->x = x; - layout->y = 0; + layout->x = x + btn->padding; + layout->y = btn->padding; draw->layouts = g_list_prepend(draw->layouts, layout); @@ -215,8 +217,8 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) Layout *child = g_malloc(sizeof(Layout)); child->btn = btn; - child->x = x; - child->y = 0; + child->x = x + btn->padding; + child->y = btn->padding;; child->pl = pango_cairo_create_layout(window_get_context(win)); layout_text(child, draw->desc, scale, height, radius); @@ -225,6 +227,9 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) x += child->width + line_w * 2; + child->width -= 2 * btn->padding; + child->height -= 2 * btn->padding; + if (it->next != NULL) x += sep; } @@ -233,8 +238,15 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) layout->height = height; // FIXME: Temporary solution to make the antialiasing (or the circles not overlapping correctly) problem less noticeable - layout->x += 1; - layout->width -= 2; + + bool fix_left = CAST(g_list_first(group->children)->data, Button)->padding == 0; + bool fix_right = CAST(g_list_last(group->children)->data, Button)->padding == 0; + + if (fix_left) { + layout->x += 1; + layout->width -= 1; + } + if (fix_right) layout->width -= 1; goto end; } } @@ -243,6 +255,9 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) layout_text(layout, draw->desc, scale, height, radius); x += layout->width + line_w * 2; + layout->width -= 2 * btn->padding; + layout->height -= 2 * btn->padding; + end: if (prev != NULL && prev->align != btn->align) { if (btn->align == PANGO_ALIGN_CENTER) adjust_center = draw->layouts; |
