aboutsummaryrefslogtreecommitdiff
path: root/src/draw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/draw.c')
-rw-r--r--src/draw.c65
1 files changed, 31 insertions, 34 deletions
diff --git a/src/draw.c b/src/draw.c
index 16a5669..30f59a1 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -169,22 +169,22 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns)
//double scale = window_get_scale(win);
double scale = 1;
+ // Remove this...
int width, height;
compute_width(draw, win, &width, &height);
+ // Order by alignment
+ btns = g_list_sort(btns, align_compare);
+ Button *prev = NULL;
+
int x = 0;
int radius = height / 2;
int sep = 10 * scale;
int line_w = draw->line_w * scale;
- btns = g_list_sort(btns, align_compare);
-
- GList *adjust_center = NULL;
- GList *adjust_right = NULL;
-
- int end_xs[3] = { 0 };
- Button *prev = NULL;
+ GList *layout_start[3] = { NULL };
+ int layout_end[3] = { 0 };
for (GList *it = btns; it; it = it->next) {
Button *btn = it->data;
@@ -199,6 +199,10 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns)
draw->layouts = g_list_prepend(draw->layouts, layout);
+ if (prev == NULL || prev->align != btn->align) {
+ layout_start[btn->align] = draw->layouts;
+ }
+
if (!btn->simple) {
ButtonGroup *group = CAST(btn, ButtonGroup);
g_assert_nonnull(group->children);
@@ -247,56 +251,49 @@ void draw_compute_layout(Drawable *draw, Window *win, GList *btns)
layout->width -= 1;
}
if (fix_right) layout->width -= 1;
- 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;
-
- layout->width -= 2 * btn->padding;
- layout->height -= 2 * btn->padding;
+ if (layout->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;
-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;
+ layout->width -= 2 * btn->padding;
+ layout->height -= 2 * btn->padding;
}
prev = btn;
- end_xs[btn->align] = x;
+ layout_end[btn->align] = x;
}
draw->layouts = g_list_reverse(draw->layouts);
- int widths[3] = {
- end_xs[0],
- end_xs[1] - end_xs[0],
- end_xs[2] - MAX(end_xs[1], end_xs[0]),
+ int layout_width[3] = {
+ layout_end[PANGO_ALIGN_LEFT],
+ layout_end[PANGO_ALIGN_CENTER] - layout_end[PANGO_ALIGN_LEFT],
+ layout_end[PANGO_ALIGN_RIGHT] - MAX(layout_end[PANGO_ALIGN_CENTER], layout_end[PANGO_ALIGN_LEFT]),
};
- int start_xs[3] = {
- 0,
- end_xs[0],
- MAX(end_xs[1], end_xs[0]),
- };
+ if (layout_end[PANGO_ALIGN_RIGHT] > width) {
+ log_error("LENGHT %d on %d", layout_end[PANGO_ALIGN_RIGHT], width);
+ }
int center = round(width / 2);
- int center_off = (center - widths[1] / 2) - start_xs[1];
- log_debug("Aligning center layout [x=%d, off=%d]", center, center_off);
+ int center_off = center - round(layout_width[PANGO_ALIGN_CENTER] / 2) - layout_end[PANGO_ALIGN_LEFT];
+ log_debug("Aligning center layout [center=%d, off=%d]", center, center_off);
- for (GList *it = adjust_center; it != adjust_right; it = it->next) {
+ for (GList *it = layout_start[PANGO_ALIGN_CENTER]; it != layout_start[PANGO_ALIGN_RIGHT]; it = it->next) {
Layout *layout = it->data;
layout->x += center_off;
}
- int right = width - widths[2];
+ int right = width - layout_width[PANGO_ALIGN_LEFT];
// The width is off by 2 line width
- int right_off = right - start_xs[2] + 2 * line_w;
+ int right_off = right - MAX(layout_end[PANGO_ALIGN_LEFT], layout_end[PANGO_ALIGN_CENTER]) + 2 * line_w;
log_debug("Aligning right layout [x=%d, off=%d]", right, right_off);
- for (GList *it = adjust_right; it != NULL; it = it->next) {
+ for (GList *it = layout_start[PANGO_ALIGN_RIGHT]; it != NULL; it = it->next) {
Layout *layout = it->data;
layout->x += right_off;
}