From 83cef372b0c3815ff708be90233a76d09996ffd5 Mon Sep 17 00:00:00 2001 From: zoltanvb Date: Tue, 25 Jul 2023 07:16:58 +0200 Subject: [PATCH] Recalculate animation end position if layout changes after start. --- .../gfx_widget_load_content_animation.c | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gfx/widgets/gfx_widget_load_content_animation.c b/gfx/widgets/gfx_widget_load_content_animation.c index 461a614a1f5..bd06c422a4b 100644 --- a/gfx/widgets/gfx_widget_load_content_animation.c +++ b/gfx/widgets/gfx_widget_load_content_animation.c @@ -566,6 +566,42 @@ static void gfx_widget_load_content_animation_layout( (float)font_regular->line_centre_offset; /* > Note: cannot determine state->text_x_end * until text strings are set */ + + /* Recalculate end positions if layout changes after start */ + if (state->status > GFX_WIDGET_LOAD_CONTENT_BEGIN) + { + int content_name_width; + int system_name_width; + int text_width; + + /* Get overall text width */ + content_name_width = font_driver_get_message_width( + font_bold->font, state->content_name, + strlen(state->content_name), 1.0f); + system_name_width = font_driver_get_message_width( + font_regular->font, state->system_name, + state->system_name_len, 1.0f); + + state->content_name_width = (content_name_width > 0) ? + (unsigned)content_name_width : 0; + state->system_name_width = (system_name_width > 0) ? + (unsigned)system_name_width : 0; + + text_width = (state->content_name_width > state->system_name_width) ? + (int)state->content_name_width : (int)state->system_name_width; + + /* Now we have the text width, can determine + * final icon/text x draw positions */ + state->icon_x_end = ((int)last_video_width - text_width - + (int)state->icon_size - (3 * (int)widget_padding)) >> 1; + if (state->icon_x_end < (int)widget_padding) + state->icon_x_end = widget_padding; + + state->text_x_end = state->icon_x_end + + (float)(state->icon_size + widget_padding); + + } + } /* Widget iterate() */