diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-02-05 20:14:43 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-02-05 20:14:43 +0100 |
commit | 7498535a49042dc58c6dfc9ef4df6e7e77ab93fa (patch) | |
tree | ada48d2e1b939a2ac2c4844ac9d34c0dfdb81c56 | |
parent | ddc745dab8b03e25e77e143aafb8e26a7af299d1 (diff) |
-rw-r--r-- | src/graphics/text.c | 4 | ||||
-rw-r--r-- | tests/main.c | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/src/graphics/text.c b/src/graphics/text.c index 2aa3bb4..3385667 100644 --- a/src/graphics/text.c +++ b/src/graphics/text.c @@ -94,12 +94,13 @@ static void mgl_text_for_each_codepoint(const mgl_text *self, codepoint_loop_cal typedef struct { mgl_vec2f bounds; + mgl_font *font; } CalculateBoundsUserdata; static bool calculate_bounds_callback(codepoint_loop_callback_data callback_data, void *userdata) { CalculateBoundsUserdata *calculate_bounds_userdata = userdata; calculate_bounds_userdata->bounds.x = max_float(calculate_bounds_userdata->bounds.x, callback_data.glyph_offset.x + callback_data.glyph_width); - calculate_bounds_userdata->bounds.y = max_float(calculate_bounds_userdata->bounds.y, callback_data.glyph_offset.y + callback_data.glyph->size.y); + calculate_bounds_userdata->bounds.y = max_float(calculate_bounds_userdata->bounds.y, callback_data.glyph_offset.y + calculate_bounds_userdata->font->character_size); return true; } @@ -107,6 +108,7 @@ static mgl_vec2f mgl_text_calculate_bounds(mgl_text *self) { CalculateBoundsUserdata calculate_bounds_userdata; calculate_bounds_userdata.bounds.x = 0.0f; calculate_bounds_userdata.bounds.y = self->font->character_size; + calculate_bounds_userdata.font = self->font; mgl_text_for_each_codepoint(self, calculate_bounds_callback, &calculate_bounds_userdata); return calculate_bounds_userdata.bounds; } diff --git a/tests/main.c b/tests/main.c index 3ec5738..09e59ed 100644 --- a/tests/main.c +++ b/tests/main.c @@ -62,7 +62,15 @@ static void draw(mgl_window *window, void *userdata) { mgl_text text; mgl_text_init(&text, u->font, str, strlen(str)); mgl_text_set_max_width(&text, 200.0f); - mgl_text_set_max_rows(&text, 5); + //mgl_text_set_max_rows(&text, 5); + { + mgl_rectangle text_bg = { + .position = text.position, + .size = mgl_text_get_bounds(&text), + .color = { 255, 0, 0, 255 }, + }; + mgl_rectangle_draw(context, &text_bg); + } mgl_text_draw(context, &text); mgl_text_deinit(&text); |