From 487d3217fc59fa4f1436bb7965468468ea8c175f Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Sat, 31 Dec 2016 16:13:59 +0900 Subject: [PATCH] Handle cases where decoration title is too long (fancy) --- userspace/gui/lib/decor-fancy.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/userspace/gui/lib/decor-fancy.c b/userspace/gui/lib/decor-fancy.c index b5255af1..1318d820 100644 --- a/userspace/gui/lib/decor-fancy.c +++ b/userspace/gui/lib/decor-fancy.c @@ -76,13 +76,29 @@ static void render_decorations_fancy(yutani_window_t * window, gfx_context_t * c set_font_face(FONT_SANS_SERIF_BOLD); set_font_size(12); - int title_offset = (width / 2) - (draw_string_width(title) / 2); - if (decors_active == 0) { - draw_string(ctx, title_offset, TEXT_OFFSET, rgb(226,226,226), title); - } else { - draw_string(ctx, title_offset, TEXT_OFFSET, rgb(147,147,147), title); + char * tmp_title = strdup(title); + int t_l = strlen(tmp_title); + +#define EXTRA_SPACE 40 + + if (draw_string_width(tmp_title) + EXTRA_SPACE > width) { + while (t_l >= 0 && (draw_string_width(tmp_title) + EXTRA_SPACE > width)) { + tmp_title[t_l] = '\0'; + t_l--; + } } + if (strlen(tmp_title)) { + int title_offset = (width / 2) - (draw_string_width(tmp_title) / 2); + if (decors_active == 0) { + draw_string(ctx, title_offset, TEXT_OFFSET, rgb(226,226,226), tmp_title); + } else { + draw_string(ctx, title_offset, TEXT_OFFSET, rgb(147,147,147), tmp_title); + } + } + + free(tmp_title); + /* Buttons */ draw_sprite(ctx, sprites[decors_active + 8], width - 28, 16); }