diff options
| author | Federico Angelilli <code@fedang.net> | 2024-11-20 23:47:53 +0100 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-11-20 23:48:09 +0100 |
| commit | 98e8080ed671e7b7459c91eafec23f903298e8c3 (patch) | |
| tree | 60217be80076a9d0184273e9df975903ac63d3a6 /src | |
| parent | fcd52f6db3dc9092dbd7a502e3e561ad16bf0743 (diff) | |
Fix text positioning
Diffstat (limited to 'src')
| -rw-r--r-- | src/blocks/slider.c | 16 | ||||
| -rw-r--r-- | src/layout.c | 5 |
2 files changed, 11 insertions, 10 deletions
diff --git a/src/blocks/slider.c b/src/blocks/slider.c index 8c89ddf..ba3bb6d 100644 --- a/src/blocks/slider.c +++ b/src/blocks/slider.c @@ -71,15 +71,17 @@ static void block_slider_event(layout_t *layout, event_t event) { block_slider_t *slider = (block_slider_t *)layout->block; - int bar_x = layout->x + layout->height / 2; int bar_y = layout->y + (layout->height - slider->height) / 2; + int bar_x = layout->x + (layout->width - slider->width) / 2; - log_value_debug("Clicked slider", - "i:bar_x", bar_x, - "i:bar_y", bar_y, - "i:bar_width", slider->width, - "i:bar_height", slider->height, - "i:value", slider->value); + if (check_capsule(event.x, event.y, bar_x, bar_y, slider->width, slider->height)) { + log_value_debug("Clicked slider", + "i:bar_x", bar_x, + "i:bar_y", bar_y, + "i:bar_width", slider->width, + "i:bar_height", slider->height, + "i:value", slider->value); + } } static void block_slider_init(block_t *block, const block_scheme_t *scheme) 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; |
