aboutsummaryrefslogtreecommitdiff
path: root/src/draw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/draw.c')
-rw-r--r--src/draw.c60
1 files 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;