mirror of
https://github.com/DarkFlippers/unleashed-firmware
synced 2024-11-10 15:04:19 +00: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:
parent
0a48658a9a
commit
c52f28efa4
1 changed files with 10 additions and 7 deletions
|
@ -100,16 +100,19 @@ static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
|
|||
line_num++;
|
||||
model->text = furi_string_get_cstr(model->text_formatted);
|
||||
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
|
||||
for(uint8_t i = 0; i < line_num - 5; i++) {
|
||||
while(*model->text_pos++ != '\n') {
|
||||
};
|
||||
const char* end = model->text + furi_string_size(model->text_formatted);
|
||||
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 {
|
||||
model->scroll_num = MAX(line_num - 4, 0u);
|
||||
model->scroll_num = MAX(line_num - (lines_on_screen - 1), 0u);
|
||||
model->scroll_pos = 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue