1
mirror of https://github.com/flipperdevices/flipperzero-firmware.git synced 2025-12-12 12:51:22 +04:00

GUI: Fix textbox overflow/crash/hang with 256+ lines (#3536)

* GUI: Fix textbox overflow/crash/hang with 256+ lines
* GUI: Textbox calculate lines based on font height
* Gui: proper types in text_box

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
WillyJL
2024-03-25 06:28:20 +00:00
committed by GitHub
parent 0a48658a9a
commit c52f28efa4

View File

@@ -100,16 +100,19 @@ static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
line_num++; line_num++;
model->text = furi_string_get_cstr(model->text_formatted); model->text = furi_string_get_cstr(model->text_formatted);
model->text_pos = (char*)model->text; model->text_pos = (char*)model->text;
if(model->focus == TextBoxFocusEnd && line_num > 5) { size_t lines_on_screen = 56 / canvas_current_font_height(canvas);
if(model->focus == TextBoxFocusEnd && line_num > lines_on_screen) {
// Set text position to 5th line from the end // Set text position to 5th line from the end
for(uint8_t i = 0; i < line_num - 5; i++) { const char* end = model->text + furi_string_size(model->text_formatted);
while(*model->text_pos++ != '\n') { for(size_t i = 0; i < line_num - lines_on_screen; i++) {
}; while(model->text_pos < end) {
if(*model->text_pos++ == '\n') break;
} }
model->scroll_num = line_num - 4; }
model->scroll_pos = line_num - 5; model->scroll_num = line_num - (lines_on_screen - 1);
model->scroll_pos = line_num - lines_on_screen;
} else { } else {
model->scroll_num = MAX(line_num - 4, 0u); model->scroll_num = MAX(line_num - (lines_on_screen - 1), 0u);
model->scroll_pos = 0; model->scroll_pos = 0;
} }
} }