Skip to content

Commit

Permalink
Fix word wrapped widget length (#15905)
Browse files Browse the repository at this point in the history
  • Loading branch information
sonninnos authored Nov 14, 2023
1 parent f091b5a commit b341d90
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions gfx/gfx_widgets.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 */
Expand All @@ -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);
}
Expand All @@ -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,
Expand Down

0 comments on commit b341d90

Please sign in to comment.