ui: experimental message box width auto-sizing #2
1 changed files with 9 additions and 1 deletions
10
src/render.c
10
src/render.c
|
|
@ -5,6 +5,7 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void render_map(const Map *map) {
|
void render_map(const Map *map) {
|
||||||
for (int y = 0; y < MAP_HEIGHT; y++) {
|
for (int y = 0; y < MAP_HEIGHT; y++) {
|
||||||
|
|
@ -286,8 +287,15 @@ void render_message(const char *message) {
|
||||||
if (message == NULL)
|
if (message == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
int msg_len = strlen(message);
|
||||||
|
float msg_ratio = 13.5;
|
||||||
// Draw message box
|
// Draw message box
|
||||||
Rectangle msg_bg = {(float)(SCREEN_WIDTH / 2 - 150), (float)(SCREEN_HEIGHT / 2 - 30), 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});
|
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});
|
DrawRectangleLines((int)msg_bg.x, (int)msg_bg.y, (int)msg_bg.width, (int)msg_bg.height, (Color){180, 180, 180, 255});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue