1
0
Fork 0
forked from NotAShelf/rogged

ui: experimental message box width auto-sizing

This commit is contained in:
A.M. Rowsell 2026-04-04 00:01:22 -04:00
commit b49808a216
Signed by: amr
GPG key ID: E0879EDBDB0CA7B1

View file

@ -5,6 +5,7 @@
#include "settings.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>
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});