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 | |
| parent | fcd52f6db3dc9092dbd7a502e3e561ad16bf0743 (diff) | |
Fix text positioning
| -rw-r--r-- | comet.conf | 36 | ||||
| -rw-r--r-- | src/blocks/slider.c | 16 | ||||
| -rw-r--r-- | src/layout.c | 5 |
3 files changed, 41 insertions, 16 deletions
@@ -6,7 +6,7 @@ height = 40 background = #abc - blocks = date, perf, try2, sl + blocks = date, perf, try2, mus, sus [jib] sus = false @@ -41,6 +41,7 @@ [block.cpu] type = text text = CPU + ;text = "" text-color = #fff color = #181818 @@ -66,13 +67,36 @@ line-width = 4 text-color = #fff -[block.sl] +[block.mus] + type = group + ;color = #CCCCFF + color = #f7f7f7 + spacing = 2 + blocks = play, next, slide + +[block.play] + type = text + text = "" + text-color = #111 + color = #18baf2 + ;x-padding = 5 + ;y-padding = 5 + +[block.next] + type = text + text = "" + text-color = #111 + color = #18baf2 + x-padding = 5 + y-padding = 5 + +[block.slide] type = slider bar-value = 88 - color = #18baf2 - bar-width = 100 - bar-height = 10 - bar-color = #afafaf, #f1baee + ;color = #18baf2 + bar-width = 120 + bar-height = 15 + bar-color = #f1baee, #CCCCFF bar-line-color = #000 bar-line-width = 2 bar-bg-color = #fff 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; |
