diff options
| author | Federico Angelilli <code@fedang.net> | 2023-11-26 21:35:47 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2023-11-26 21:35:47 +0100 |
| commit | 399ba1141286e2b224275c2b33f05d349ad6e8e9 (patch) | |
| tree | 9ba93e2cb515ad1237627f62dfb0d8c85599474d | |
| parent | 238bedb3f4d3a356a6cd11cd8b4c5a2725de2cf8 (diff) | |
Treat a singleton group as a single button
| -rw-r--r-- | src/draw.c | 60 |
1 files changed, 34 insertions, 26 deletions
@@ -197,45 +197,53 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns) draw->layouts = g_list_prepend(draw->layouts, layout); - if (btn->simple) { - layout->pl = pango_cairo_create_layout(window_get_context(win)); - layout_text(layout, draw->desc, scale, height, radius); - x += layout->width + line_w * 2; - } else { + if (!btn->simple) { ButtonGroup *group = CAST(btn, ButtonGroup); - layout->pl = NULL; - g_assert_nonnull(group->children); - for (GList *it = group->children; it; it = it->next) { - Button *btn = it->data; - // Nested groups are not allowed - g_assert_true(btn->simple); + // If there is only one child treat a group like a single button + if (group->children->next == NULL) { + Button *child = group->children->data; + g_assert_true(child->simple); + layout->btn = child; + } else { + for (GList *it = group->children; it; it = it->next) { + Button *btn = it->data; + // Nested groups are not allowed + g_assert_true(btn->simple); - Layout *child = g_malloc(sizeof(Layout)); - child->btn = btn; + Layout *child = g_malloc(sizeof(Layout)); + child->btn = btn; - child->x = x; - child->y = 0; + child->x = x; + child->y = 0; - child->pl = pango_cairo_create_layout(window_get_context(win)); - layout_text(child, draw->desc, scale, height, radius); + child->pl = pango_cairo_create_layout(window_get_context(win)); + layout_text(child, draw->desc, scale, height, radius); - draw->layouts = g_list_prepend(draw->layouts, child); + draw->layouts = g_list_prepend(draw->layouts, child); - x += child->width + line_w * 2; + x += child->width + line_w * 2; - if (it->next != NULL) x += sep; - } + if (it->next != NULL) x += sep; + } - layout->width = x - layout->x; - layout->height = height; + layout->pl = NULL; + layout->width = x - layout->x; + 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; + // FIXME: Temporary solution to make the antialiasing (or the circles not overlapping correctly) problem less noticeable + layout->x += 1; + layout->width -= 2; + goto end; + } } + layout->pl = pango_cairo_create_layout(window_get_context(win)); + layout_text(layout, draw->desc, scale, height, radius); + x += layout->width + line_w * 2; + +end: if (prev != NULL && prev->align != btn->align) { if (btn->align == PANGO_ALIGN_CENTER) adjust_center = draw->layouts; else if (btn->align == PANGO_ALIGN_RIGHT) adjust_right = draw->layouts; |
