From 399ba1141286e2b224275c2b33f05d349ad6e8e9 Mon Sep 17 00:00:00 2001 From: Federico Angelilli Date: Sun, 26 Nov 2023 21:35:47 +0100 Subject: Treat a singleton group as a single button --- src/draw.c | 60 ++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/src/draw.c b/src/draw.c index 5aa4837..4d983d6 100644 --- a/src/draw.c +++ b/src/draw.c @@ -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; -- cgit v1.2.3