From 68fd31a0f7c7b5c5ccf6796bc514bf1dac622d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Andr=C3=A9=20Santoni?= Date: Tue, 26 Jul 2016 21:10:43 +0200 Subject: [PATCH] (GLUI) Align help messages to the left, in a centered box --- menu/drivers/materialui.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/menu/drivers/materialui.c b/menu/drivers/materialui.c index cd9661a5f5..b69451bcf3 100644 --- a/menu/drivers/materialui.c +++ b/menu/drivers/materialui.c @@ -377,10 +377,11 @@ static void mui_render_messagebox(const char *message) { unsigned i, width, height; uint32_t font_normal_color; - int x, y, font_size; + int x, y, font_size, longest = 0, longest_width = 0; settings_t *settings = config_get_ptr(); struct string_list *list = (struct string_list*) string_split(message, "\n"); + void *fb_buf; if (!list) return; @@ -396,13 +397,28 @@ static void mui_render_messagebox(const char *message) font_normal_color = FONT_COLOR_ARGB_TO_RGBA(settings->menu.entry_normal_color); + fb_buf = menu_display_get_font_buffer(); + + /* find the longest line width */ + for (i = 0; i < list->size; i++) + { + const char *msg = list->elems[i].data; + int len = strlen(msg); + if (len > longest) + { + longest = len; + longest_width = font_driver_get_message_width(fb_buf, msg, len, 1); + } + } + + /* print each line */ for (i = 0; i < list->size; i++) { const char *msg = list->elems[i].data; if (msg) - mui_draw_text(x, y + i * font_size, + mui_draw_text(x - longest_width/2.0, y + i * font_size, width, height, - msg, font_normal_color, TEXT_ALIGN_CENTER); + msg, font_normal_color, TEXT_ALIGN_LEFT); } end: