From b49808a21678ab26535c12a968fd3730de3bc757 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Sat, 4 Apr 2026 00:01:22 -0400 Subject: [PATCH 1/2] ui: experimental message box width auto-sizing --- src/render.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/render.c b/src/render.c index 4ecacdf..c0349b4 100644 --- a/src/render.c +++ b/src/render.c @@ -5,6 +5,7 @@ #include "settings.h" #include #include +#include void render_map(const Map *map) { for (int y = 0; y < MAP_HEIGHT; y++) { @@ -285,9 +286,13 @@ void render_game_over(void) { void render_message(const char *message) { if (message == NULL) return; - + int msg_len = strlen(message); + float msg_ratio = 13.5; // Draw message box - Rectangle msg_bg = {(float)(SCREEN_WIDTH / 2 - 150), (float)(SCREEN_HEIGHT / 2 - 30), 300, 60}; + // Rectangle msg_bg = {(float)(SCREEN_WIDTH / 2.0f - 150.0f), (float)(SCREEN_HEIGHT / 2.0f - 30.0f), 300, 60}; + + Rectangle msg_bg = {(float)(SCREEN_WIDTH / 2.0f - ((msg_ratio / 2.03f) * msg_len)), + (float)(SCREEN_HEIGHT / 2.0f - 30.0f), msg_ratio * msg_len, 60}; DrawRectangleRec(msg_bg, (Color){45, 45, 45, 235}); DrawRectangleLines((int)msg_bg.x, (int)msg_bg.y, (int)msg_bg.width, (int)msg_bg.height, (Color){180, 180, 180, 255}); -- 2.43.0 From 39b7e01119c5c5aa13aaae87a3eec5f83e90c030 Mon Sep 17 00:00:00 2001 From: "A.M. Rowsell" Date: Sat, 4 Apr 2026 00:23:24 -0400 Subject: [PATCH 2/2] formatting: cleaned up formatting of this change, added TODO --- src/render.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/render.c b/src/render.c index c0349b4..de0c254 100644 --- a/src/render.c +++ b/src/render.c @@ -286,11 +286,14 @@ void render_game_over(void) { void render_message(const char *message) { if (message == NULL) return; + int msg_len = strlen(message); float msg_ratio = 13.5; // Draw message box - // Rectangle msg_bg = {(float)(SCREEN_WIDTH / 2.0f - 150.0f), (float)(SCREEN_HEIGHT / 2.0f - 30.0f), 300, 60}; + // TODO: Separate out the calculation of the x/y and width/height so that if a message takes up more than, say, + // 75% of the screen width, we add a line break and increase the height. That would then require calculating the + // width based on the longest line. Rectangle msg_bg = {(float)(SCREEN_WIDTH / 2.0f - ((msg_ratio / 2.03f) * msg_len)), (float)(SCREEN_HEIGHT / 2.0f - 30.0f), msg_ratio * msg_len, 60}; DrawRectangleRec(msg_bg, (Color){45, 45, 45, 235}); -- 2.43.0