From 03cc9e8040b9fdbf021a5237b8645dbca47f61ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Mon, 28 Jun 2021 23:54:11 +0200 Subject: [PATCH] fix: text component respect new line --- lib-gui/src/gui_component_text.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib-gui/src/gui_component_text.c b/lib-gui/src/gui_component_text.c index 8a77091947de40acc72a43ff1ddf289671c850c3..5b3dcb12d239e556c32cc43160c0869e955e0f4d 100644 --- a/lib-gui/src/gui_component_text.c +++ b/lib-gui/src/gui_component_text.c @@ -31,7 +31,7 @@ void gui_text_render(container_t *container, component_t *component, } int32_t remaining = strlen(state->line); - char *line = state->line; + const char *line = state->line; int16_t y = component->y; @@ -44,6 +44,13 @@ void gui_text_render(container_t *container, component_t *component, fit_chars = remaining; } + for (int i = 0; i < fit_chars; i++) { + if (line[i] == '\n' && lines_fit > 1) { + fit_chars = i + 1; + break; + } + } + renderer_write_string(gui->renderer, component->x, y, fit_chars, state->font, line, state->color);