Added label clamping.

This commit is contained in:
2021-09-08 23:16:22 -07:00
parent 9ef961f871
commit 5579b012f6
4 changed files with 5 additions and 2 deletions

View File

@ -14,6 +14,7 @@
typedef struct { typedef struct {
font_t *font; font_t *font;
float fontSize; float fontSize;
float maxWidth;
fonttextinfo_t info; fonttextinfo_t info;
primitive_t primitive; primitive_t primitive;
} label_t; } label_t;

View File

@ -48,7 +48,7 @@ void sandboxSceneUpdate(sandboxscene_t *game, engine_t *engine) {
gridSetSize(&menu.menu.grid, gridSetSize(&menu.menu.grid,
engine->render.width, engine->render.height, engine->render.width, engine->render.height,
engine->render.width, FONT_LINE_HEIGHT * fontGetScale(16.0f) * 3, 100.0f, FONT_LINE_HEIGHT * fontGetScale(16.0f) * 3,
0, 0 0, 0
); );
menu2Update(&menu.menu, engine); menu2Update(&menu.menu, engine);

View File

@ -10,6 +10,7 @@
void labelInit(label_t *label) { void labelInit(label_t *label) {
label->fontSize = FONT_SIZE_DEFAULT; label->fontSize = FONT_SIZE_DEFAULT;
label->font = NULL; label->font = NULL;
label->maxWidth = -1;
label->primitive.verticeCount = 0; label->primitive.verticeCount = 0;
} }
@ -20,7 +21,7 @@ void labelSetText(label_t *label, font_t *font, char *text) {
} }
label->font = font; label->font = font;
fontTextClamp(font, &label->info, text, -1, label->fontSize); fontTextClamp(font, &label->info, text, label->maxWidth, label->fontSize);
fontTextInit(font, &label->primitive, &label->info); fontTextInit(font, &label->primitive, &label->info);
} }

View File

@ -28,6 +28,7 @@ void _textMenuOnResize(
info->y = y; info->y = y;
info->width = width; info->width = width;
info->height = height; info->height = height;
label->maxWidth = width;
labelSetText(label, textMenu->font, textMenu->texts[i]); labelSetText(label, textMenu->font, textMenu->texts[i]);
} }