M*LIB: non-inlined strings, FuriString primitive (#1795)

* Quicksave 1
* Header stage complete
* Source stage complete
* Lint & merge fixes
* Includes
* Documentation step 1
* FBT: output free size considering BT STACK
* Documentation step 2
* py lint
* Fix music player plugin
* unit test stage 1: string allocator, mem, getters, setters, appends, compare, search.
* unit test: string equality
* unit test: string replace
* unit test: string start_with, end_with
* unit test: string trim
* unit test: utf-8
* Rename
* Revert fw_size changes
* Simplify CLI backspace handling
* Simplify CLI character insert
* Merge fixes
* Furi: correct filenaming and spelling
* Bt: remove furi string include

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
Sergey Gavrilov
2022-10-06 01:15:23 +10:00
committed by GitHub
parent 0f9ea925d3
commit 4bf29827f8
370 changed files with 5597 additions and 3963 deletions

View File

@@ -1,10 +1,9 @@
#include "widget_element_i.h"
#include <gui/elements.h>
#include <m-string.h>
typedef struct {
GuiButtonType button_type;
string_t text;
FuriString* text;
ButtonCallback callback;
void* context;
} GuiButtonModel;
@@ -18,11 +17,11 @@ static void gui_button_draw(Canvas* canvas, WidgetElement* element) {
canvas_set_font(canvas, FontSecondary);
if(model->button_type == GuiButtonTypeLeft) {
elements_button_left(canvas, string_get_cstr(model->text));
elements_button_left(canvas, furi_string_get_cstr(model->text));
} else if(model->button_type == GuiButtonTypeRight) {
elements_button_right(canvas, string_get_cstr(model->text));
elements_button_right(canvas, furi_string_get_cstr(model->text));
} else if(model->button_type == GuiButtonTypeCenter) {
elements_button_center(canvas, string_get_cstr(model->text));
elements_button_center(canvas, furi_string_get_cstr(model->text));
}
}
@@ -50,7 +49,7 @@ static void gui_button_free(WidgetElement* gui_button) {
furi_assert(gui_button);
GuiButtonModel* model = gui_button->model;
string_clear(model->text);
furi_string_free(model->text);
free(gui_button->model);
free(gui_button);
}
@@ -65,7 +64,7 @@ WidgetElement* widget_element_button_create(
model->button_type = button_type;
model->callback = callback;
model->context = context;
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
// Allocate and init Element
WidgetElement* gui_button = malloc(sizeof(WidgetElement));

View File

@@ -1,5 +1,4 @@
#include "widget_element_i.h"
#include <m-string.h>
typedef struct {
uint8_t x;
@@ -7,7 +6,7 @@ typedef struct {
Align horizontal;
Align vertical;
Font font;
string_t text;
FuriString* text;
} GuiStringModel;
static void gui_string_draw(Canvas* canvas, WidgetElement* element) {
@@ -15,7 +14,7 @@ static void gui_string_draw(Canvas* canvas, WidgetElement* element) {
furi_assert(element);
GuiStringModel* model = element->model;
if(string_size(model->text)) {
if(furi_string_size(model->text)) {
canvas_set_font(canvas, model->font);
canvas_draw_str_aligned(
canvas,
@@ -23,7 +22,7 @@ static void gui_string_draw(Canvas* canvas, WidgetElement* element) {
model->y,
model->horizontal,
model->vertical,
string_get_cstr(model->text));
furi_string_get_cstr(model->text));
}
}
@@ -31,7 +30,7 @@ static void gui_string_free(WidgetElement* gui_string) {
furi_assert(gui_string);
GuiStringModel* model = gui_string->model;
string_clear(model->text);
furi_string_free(model->text);
free(gui_string->model);
free(gui_string);
}
@@ -52,7 +51,7 @@ WidgetElement* widget_element_string_create(
model->horizontal = horizontal;
model->vertical = vertical;
model->font = font;
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
// Allocate and init Element
WidgetElement* gui_string = malloc(sizeof(WidgetElement));

View File

@@ -1,5 +1,4 @@
#include "widget_element_i.h"
#include <m-string.h>
#include <gui/elements.h>
typedef struct {
@@ -8,7 +7,7 @@ typedef struct {
Align horizontal;
Align vertical;
Font font;
string_t text;
FuriString* text;
} GuiStringMultiLineModel;
static void gui_string_multiline_draw(Canvas* canvas, WidgetElement* element) {
@@ -16,7 +15,7 @@ static void gui_string_multiline_draw(Canvas* canvas, WidgetElement* element) {
furi_assert(element);
GuiStringMultiLineModel* model = element->model;
if(string_size(model->text)) {
if(furi_string_size(model->text)) {
canvas_set_font(canvas, model->font);
elements_multiline_text_aligned(
canvas,
@@ -24,7 +23,7 @@ static void gui_string_multiline_draw(Canvas* canvas, WidgetElement* element) {
model->y,
model->horizontal,
model->vertical,
string_get_cstr(model->text));
furi_string_get_cstr(model->text));
}
}
@@ -32,7 +31,7 @@ static void gui_string_multiline_free(WidgetElement* gui_string) {
furi_assert(gui_string);
GuiStringMultiLineModel* model = gui_string->model;
string_clear(model->text);
furi_string_free(model->text);
free(gui_string->model);
free(gui_string);
}
@@ -53,7 +52,7 @@ WidgetElement* widget_element_string_multiline_create(
model->horizontal = horizontal;
model->vertical = vertical;
model->font = font;
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
// Allocate and init Element
WidgetElement* gui_string = malloc(sizeof(WidgetElement));

View File

@@ -1,5 +1,4 @@
#include "widget_element_i.h"
#include <m-string.h>
#include <gui/elements.h>
typedef struct {
@@ -9,7 +8,7 @@ typedef struct {
uint8_t height;
Align horizontal;
Align vertical;
string_t text;
FuriString* text;
bool strip_to_dots;
} GuiTextBoxModel;
@@ -18,7 +17,7 @@ static void gui_text_box_draw(Canvas* canvas, WidgetElement* element) {
furi_assert(element);
GuiTextBoxModel* model = element->model;
if(string_size(model->text)) {
if(furi_string_size(model->text)) {
elements_text_box(
canvas,
model->x,
@@ -27,7 +26,7 @@ static void gui_text_box_draw(Canvas* canvas, WidgetElement* element) {
model->height,
model->horizontal,
model->vertical,
string_get_cstr(model->text),
furi_string_get_cstr(model->text),
model->strip_to_dots);
}
}
@@ -36,7 +35,7 @@ static void gui_text_box_free(WidgetElement* gui_string) {
furi_assert(gui_string);
GuiTextBoxModel* model = gui_string->model;
string_clear(model->text);
furi_string_free(model->text);
free(gui_string->model);
free(gui_string);
}
@@ -60,7 +59,7 @@ WidgetElement* widget_element_text_box_create(
model->height = height;
model->horizontal = horizontal;
model->vertical = vertical;
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
model->strip_to_dots = strip_to_dots;
// Allocate and init Element

View File

@@ -1,5 +1,4 @@
#include "widget_element_i.h"
#include <m-string.h>
#include <gui/elements.h>
#include <m-array.h>
@@ -8,7 +7,7 @@
typedef struct {
Font font;
Align horizontal;
string_t text;
FuriString* text;
} TextScrollLineArray;
ARRAY_DEF(TextScrollLineArray, TextScrollLineArray, M_POD_OPLIST)
@@ -19,19 +18,19 @@ typedef struct {
uint8_t y;
uint8_t width;
uint8_t height;
string_t text;
FuriString* text;
uint8_t scroll_pos_total;
uint8_t scroll_pos_current;
bool text_formatted;
} WidgetElementTextScrollModel;
static bool
widget_element_text_scroll_process_ctrl_symbols(TextScrollLineArray* line, string_t text) {
widget_element_text_scroll_process_ctrl_symbols(TextScrollLineArray* line, FuriString* text) {
bool processed = false;
do {
if(string_get_char(text, 0) != '\e') break;
char ctrl_symbol = string_get_char(text, 1);
if(furi_string_get_char(text, 0) != '\e') break;
char ctrl_symbol = furi_string_get_char(text, 1);
if(ctrl_symbol == 'c') {
line->horizontal = AlignCenter;
} else if(ctrl_symbol == 'r') {
@@ -39,7 +38,7 @@ static bool
} else if(ctrl_symbol == '#') {
line->font = FontPrimary;
}
string_right(text, 2);
furi_string_right(text, 2);
processed = true;
} while(false);
@@ -51,7 +50,7 @@ void widget_element_text_scroll_add_line(WidgetElement* element, TextScrollLineA
TextScrollLineArray new_line;
new_line.font = line->font;
new_line.horizontal = line->horizontal;
string_init_set(new_line.text, line->text);
new_line.text = furi_string_alloc_set(line->text);
TextScrollLineArray_push_back(model->line_array, new_line);
}
@@ -59,7 +58,7 @@ static void widget_element_text_scroll_fill_lines(Canvas* canvas, WidgetElement*
WidgetElementTextScrollModel* model = element->model;
TextScrollLineArray line_tmp;
bool all_text_processed = false;
string_init(line_tmp.text);
line_tmp.text = furi_string_alloc();
bool reached_new_line = true;
uint16_t total_height = 0;
@@ -68,7 +67,7 @@ static void widget_element_text_scroll_fill_lines(Canvas* canvas, WidgetElement*
// Set default line properties
line_tmp.font = FontSecondary;
line_tmp.horizontal = AlignLeft;
string_reset(line_tmp.text);
furi_string_reset(line_tmp.text);
// Process control symbols
while(widget_element_text_scroll_process_ctrl_symbols(&line_tmp, model->text))
;
@@ -84,38 +83,38 @@ static void widget_element_text_scroll_fill_lines(Canvas* canvas, WidgetElement*
uint8_t line_width = 0;
uint16_t char_i = 0;
while(true) {
char next_char = string_get_char(model->text, char_i++);
char next_char = furi_string_get_char(model->text, char_i++);
if(next_char == '\0') {
string_push_back(line_tmp.text, '\0');
furi_string_push_back(line_tmp.text, '\0');
widget_element_text_scroll_add_line(element, &line_tmp);
total_height += params->leading_default - params->height;
all_text_processed = true;
break;
} else if(next_char == '\n') {
string_push_back(line_tmp.text, '\0');
furi_string_push_back(line_tmp.text, '\0');
widget_element_text_scroll_add_line(element, &line_tmp);
string_right(model->text, char_i);
furi_string_right(model->text, char_i);
total_height += params->leading_default - params->height;
reached_new_line = true;
break;
} else {
line_width += canvas_glyph_width(canvas, next_char);
if(line_width > model->width) {
string_push_back(line_tmp.text, '\0');
furi_string_push_back(line_tmp.text, '\0');
widget_element_text_scroll_add_line(element, &line_tmp);
string_right(model->text, char_i - 1);
string_reset(line_tmp.text);
furi_string_right(model->text, char_i - 1);
furi_string_reset(line_tmp.text);
total_height += params->leading_default - params->height;
reached_new_line = false;
break;
} else {
string_push_back(line_tmp.text, next_char);
furi_string_push_back(line_tmp.text, next_char);
}
}
}
}
string_clear(line_tmp.text);
furi_string_free(line_tmp.text);
}
static void widget_element_text_scroll_draw(Canvas* canvas, WidgetElement* element) {
@@ -150,7 +149,7 @@ static void widget_element_text_scroll_draw(Canvas* canvas, WidgetElement* eleme
x = model->x + model->width;
}
canvas_draw_str_aligned(
canvas, x, y, line->horizontal, AlignTop, string_get_cstr(line->text));
canvas, x, y, line->horizontal, AlignTop, furi_string_get_cstr(line->text));
y += params->leading_default;
}
// Draw scroll bar
@@ -205,10 +204,10 @@ static void widget_element_text_scroll_free(WidgetElement* text_scroll) {
for(TextScrollLineArray_it(it, model->line_array); !TextScrollLineArray_end_p(it);
TextScrollLineArray_next(it)) {
TextScrollLineArray* line = TextScrollLineArray_ref(it);
string_clear(line->text);
furi_string_free(line->text);
}
TextScrollLineArray_clear(model->line_array);
string_clear(model->text);
furi_string_free(model->text);
free(text_scroll->model);
furi_mutex_free(text_scroll->model_mutex);
free(text_scroll);
@@ -231,7 +230,7 @@ WidgetElement* widget_element_text_scroll_create(
model->scroll_pos_current = 0;
model->scroll_pos_total = 1;
TextScrollLineArray_init(model->line_array);
string_init_set_str(model->text, text);
model->text = furi_string_alloc_set(text);
WidgetElement* text_scroll = malloc(sizeof(WidgetElement));
text_scroll->parent = NULL;