aboutsummaryrefslogtreecommitdiff
path: root/src/layout.c
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-11-20 23:47:53 +0100
committerFederico Angelilli <code@fedang.net>2024-11-20 23:48:09 +0100
commit98e8080ed671e7b7459c91eafec23f903298e8c3 (patch)
tree60217be80076a9d0184273e9df975903ac63d3a6 /src/layout.c
parentfcd52f6db3dc9092dbd7a502e3e561ad16bf0743 (diff)
Fix text positioning
Diffstat (limited to 'src/layout.c')
-rw-r--r--src/layout.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/layout.c b/src/layout.c
index bfc25c0..cf19d4b 100644
--- a/src/layout.c
+++ b/src/layout.c
@@ -32,7 +32,7 @@ void layout_init(layout_t *layout, block_t *block, layout_info_t info)
pango_layout_set_text(layout->pl, text->text, -1);
pango_layout_get_pixel_size(layout->pl, &layout->text_width, &layout->text_height);
- size_t length = strlen(text->text);
+ int length = pango_layout_get_character_count(layout->pl);
layout->width = info.height + (length != 1) * layout->text_width;
break;
}
@@ -131,14 +131,13 @@ void layout_render(layout_t *layout, cairo_t *cr)
block_text_t *text = (block_text_t *)layout->block;
assert(layout->n_children == 0);
- int text_x = layout->x + (layout->width - layout->text_width) / 2;
+ int text_x = layout->x + (layout->width - layout->text_width + layout->x_padding) / 2;
int text_y = layout->y + (layout->height - layout->text_height) / 2;
color_t color = text->text_color;
cairo_set_source_rgba(cr, color.r, color.g, color.b, color.a);
cairo_move_to(cr, text_x, text_y);
- pango_layout_set_text(layout->pl, text->text, -1);
pango_cairo_update_layout(cr, layout->pl);
pango_cairo_show_layout(cr, layout->pl);
break;