From b341d90c2ee2404fb7bdd55da5e1ef74283d93d8 Mon Sep 17 00:00:00 2001 From: sonninnos <45124675+sonninnos@users.noreply.github.com> Date: Tue, 14 Nov 2023 19:51:43 +0200 Subject: [PATCH] Fix word wrapped widget length (#15905) --- gfx/gfx_widgets.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/gfx/gfx_widgets.c b/gfx/gfx_widgets.c index 453dddc6636..39d70901e4c 100644 --- a/gfx/gfx_widgets.c +++ b/gfx/gfx_widgets.c @@ -276,8 +276,8 @@ void gfx_widgets_msg_queue_push( char *msg = NULL; size_t msg_len = 0; unsigned width = menu_is_alive - ? p_dispwidget->msg_queue_default_rect_width_menu_alive - : p_dispwidget->msg_queue_default_rect_width; + ? p_dispwidget->msg_queue_default_rect_width_menu_alive + : p_dispwidget->msg_queue_default_rect_width; unsigned text_width = font_driver_get_message_width( p_dispwidget->gfx_widget_fonts.msg_queue.font, title, @@ -293,6 +293,8 @@ void gfx_widgets_msg_queue_push( /* Text is too wide, split it into two lines */ if (text_width > width) { + size_t wrap_length = 0; + /* If the second line is too short, the widget may * look unappealing - ensure that second line is at * least 25% of the total width */ @@ -303,6 +305,24 @@ void gfx_widgets_msg_queue_push( (int)((title_length * width) / text_width), 100, 2); + /* Recalculate widget width with longest wrapped line */ + wrap_length = string_index_last_occurance(msg, '\n'); + if (wrap_length) + { + title_length -= wrap_length; + + if (title_length < wrap_length) + title_length = wrap_length; + + text_width = font_driver_get_message_width( + p_dispwidget->gfx_widget_fonts.msg_queue.font, + title, + title_length, + 1.0f); + + width = text_width; + } + msg_widget->text_height *= 2; msg_widget->msg_len = strlen(msg); } @@ -313,8 +333,7 @@ void gfx_widgets_msg_queue_push( } msg_widget->msg = msg; - msg_widget->width = width - + p_dispwidget->simple_widget_padding / 2; + msg_widget->width = width + (p_dispwidget->simple_widget_padding / 2); } fifo_write(&p_dispwidget->msg_queue,