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:
@@ -8,7 +8,6 @@
|
||||
#include <gui/icon_i.h>
|
||||
#include <gui/icon_animation_i.h>
|
||||
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
#include "canvas_i.h"
|
||||
|
||||
@@ -189,12 +188,12 @@ static size_t
|
||||
end = text + strlen(text);
|
||||
}
|
||||
size_t text_size = end - text;
|
||||
string_t str;
|
||||
string_init_set_str(str, text);
|
||||
string_left(str, text_size);
|
||||
FuriString* str;
|
||||
str = furi_string_alloc_set(text);
|
||||
furi_string_left(str, text_size);
|
||||
size_t result = 0;
|
||||
|
||||
uint16_t len_px = canvas_string_width(canvas, string_get_cstr(str));
|
||||
uint16_t len_px = canvas_string_width(canvas, furi_string_get_cstr(str));
|
||||
uint8_t px_left = 0;
|
||||
if(horizontal == AlignCenter) {
|
||||
if(x > (canvas_width(canvas) / 2)) {
|
||||
@@ -224,7 +223,7 @@ static size_t
|
||||
result = text_size;
|
||||
}
|
||||
|
||||
string_clear(str);
|
||||
furi_string_free(str);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -240,7 +239,7 @@ void elements_multiline_text_aligned(
|
||||
|
||||
uint8_t lines_count = 0;
|
||||
uint8_t font_height = canvas_current_font_height(canvas);
|
||||
string_t line;
|
||||
FuriString* line;
|
||||
|
||||
/* go through text line by line and count lines */
|
||||
for(const char* start = text; start[0];) {
|
||||
@@ -261,14 +260,14 @@ void elements_multiline_text_aligned(
|
||||
size_t chars_fit = elements_get_max_chars_to_fit(canvas, horizontal, start, x);
|
||||
|
||||
if((start[chars_fit] == '\n') || (start[chars_fit] == 0)) {
|
||||
string_init_printf(line, "%.*s", chars_fit, start);
|
||||
line = furi_string_alloc_printf("%.*s", chars_fit, start);
|
||||
} else if((y + font_height) > canvas_height(canvas)) {
|
||||
string_init_printf(line, "%.*s...\n", chars_fit, start);
|
||||
line = furi_string_alloc_printf("%.*s...\n", chars_fit, start);
|
||||
} else {
|
||||
string_init_printf(line, "%.*s-\n", chars_fit, start);
|
||||
line = furi_string_alloc_printf("%.*s-\n", chars_fit, start);
|
||||
}
|
||||
canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, string_get_cstr(line));
|
||||
string_clear(line);
|
||||
canvas_draw_str_aligned(canvas, x, y, horizontal, vertical, furi_string_get_cstr(line));
|
||||
furi_string_free(line);
|
||||
y += font_height;
|
||||
if(y > canvas_height(canvas)) {
|
||||
break;
|
||||
@@ -284,22 +283,22 @@ void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* t
|
||||
furi_assert(text);
|
||||
|
||||
uint8_t font_height = canvas_current_font_height(canvas);
|
||||
string_t str;
|
||||
string_init(str);
|
||||
FuriString* str;
|
||||
str = furi_string_alloc();
|
||||
const char* start = text;
|
||||
char* end;
|
||||
do {
|
||||
end = strchr(start, '\n');
|
||||
if(end) {
|
||||
string_set_strn(str, start, end - start);
|
||||
furi_string_set_strn(str, start, end - start);
|
||||
} else {
|
||||
string_set_str(str, start);
|
||||
furi_string_set(str, start);
|
||||
}
|
||||
canvas_draw_str(canvas, x, y, string_get_cstr(str));
|
||||
canvas_draw_str(canvas, x, y, furi_string_get_cstr(str));
|
||||
start = end + 1;
|
||||
y += font_height;
|
||||
} while(end && y < 64);
|
||||
string_clear(str);
|
||||
furi_string_free(str);
|
||||
}
|
||||
|
||||
void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const char* text) {
|
||||
@@ -533,18 +532,18 @@ void elements_bubble_str(
|
||||
canvas_draw_line(canvas, x2, y2, x3, y3);
|
||||
}
|
||||
|
||||
void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width) {
|
||||
void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width) {
|
||||
furi_assert(canvas);
|
||||
furi_assert(string);
|
||||
|
||||
uint16_t len_px = canvas_string_width(canvas, string_get_cstr(string));
|
||||
uint16_t len_px = canvas_string_width(canvas, furi_string_get_cstr(string));
|
||||
if(len_px > width) {
|
||||
width -= canvas_string_width(canvas, "...");
|
||||
do {
|
||||
string_left(string, string_size(string) - 1);
|
||||
len_px = canvas_string_width(canvas, string_get_cstr(string));
|
||||
furi_string_left(string, furi_string_size(string) - 1);
|
||||
len_px = canvas_string_width(canvas, furi_string_get_cstr(string));
|
||||
} while(len_px > width);
|
||||
string_cat(string, "...");
|
||||
furi_string_cat(string, "...");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
#include "canvas.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -190,7 +190,7 @@ void elements_bubble_str(
|
||||
* @param string string to trim
|
||||
* @param width max width
|
||||
*/
|
||||
void elements_string_fit_width(Canvas* canvas, string_t string, uint8_t width);
|
||||
void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width);
|
||||
|
||||
/** Draw text box element
|
||||
*
|
||||
|
||||
@@ -79,8 +79,8 @@ static void button_menu_draw_common_button(
|
||||
canvas_draw_rframe(canvas, item_x, item_y, ITEM_WIDTH, ITEM_HEIGHT, 5);
|
||||
}
|
||||
|
||||
string_t disp_str;
|
||||
string_init_set_str(disp_str, text);
|
||||
FuriString* disp_str;
|
||||
disp_str = furi_string_alloc_set(text);
|
||||
elements_string_fit_width(canvas, disp_str, ITEM_WIDTH - 6);
|
||||
|
||||
canvas_draw_str_aligned(
|
||||
@@ -89,9 +89,9 @@ static void button_menu_draw_common_button(
|
||||
item_y + (ITEM_HEIGHT / 2),
|
||||
AlignCenter,
|
||||
AlignCenter,
|
||||
string_get_cstr(disp_str));
|
||||
furi_string_get_cstr(disp_str));
|
||||
|
||||
string_clear(disp_str);
|
||||
furi_string_free(disp_str);
|
||||
}
|
||||
|
||||
static void button_menu_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
@@ -116,12 +116,12 @@ static void button_menu_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
}
|
||||
|
||||
if(model->header) {
|
||||
string_t disp_str;
|
||||
string_init_set_str(disp_str, model->header);
|
||||
FuriString* disp_str;
|
||||
disp_str = furi_string_alloc_set(model->header);
|
||||
elements_string_fit_width(canvas, disp_str, ITEM_WIDTH - 6);
|
||||
canvas_draw_str_aligned(
|
||||
canvas, 32, 10, AlignCenter, AlignCenter, string_get_cstr(disp_str));
|
||||
string_clear(disp_str);
|
||||
canvas, 32, 10, AlignCenter, AlignCenter, furi_string_get_cstr(disp_str));
|
||||
furi_string_free(disp_str);
|
||||
}
|
||||
|
||||
for(ButtonMenuItemArray_it(it, model->items); !ButtonMenuItemArray_end_p(it);
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <core/common_defines.h>
|
||||
#include <core/log.h>
|
||||
#include "furi_hal_resources.h"
|
||||
#include "m-string.h"
|
||||
#include <m-array.h>
|
||||
#include <gui/elements.h>
|
||||
#include <furi.h>
|
||||
@@ -28,23 +27,23 @@ typedef enum {
|
||||
} BrowserItemType;
|
||||
|
||||
typedef struct {
|
||||
string_t path;
|
||||
FuriString* path;
|
||||
BrowserItemType type;
|
||||
uint8_t* custom_icon_data;
|
||||
string_t display_name;
|
||||
FuriString* display_name;
|
||||
} BrowserItem_t;
|
||||
|
||||
static void BrowserItem_t_init(BrowserItem_t* obj) {
|
||||
obj->type = BrowserItemTypeLoading;
|
||||
string_init(obj->path);
|
||||
string_init(obj->display_name);
|
||||
obj->path = furi_string_alloc();
|
||||
obj->display_name = furi_string_alloc();
|
||||
obj->custom_icon_data = NULL;
|
||||
}
|
||||
|
||||
static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src) {
|
||||
obj->type = src->type;
|
||||
string_init_set(obj->path, src->path);
|
||||
string_init_set(obj->display_name, src->display_name);
|
||||
obj->path = furi_string_alloc_set(src->path);
|
||||
obj->display_name = furi_string_alloc_set(src->display_name);
|
||||
if(src->custom_icon_data) {
|
||||
obj->custom_icon_data = malloc(CUSTOM_ICON_MAX_SIZE);
|
||||
memcpy(obj->custom_icon_data, src->custom_icon_data, CUSTOM_ICON_MAX_SIZE);
|
||||
@@ -55,8 +54,8 @@ static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src)
|
||||
|
||||
static void BrowserItem_t_set(BrowserItem_t* obj, const BrowserItem_t* src) {
|
||||
obj->type = src->type;
|
||||
string_set(obj->path, src->path);
|
||||
string_set(obj->display_name, src->display_name);
|
||||
furi_string_set(obj->path, src->path);
|
||||
furi_string_set(obj->display_name, src->display_name);
|
||||
if(src->custom_icon_data) {
|
||||
obj->custom_icon_data = malloc(CUSTOM_ICON_MAX_SIZE);
|
||||
memcpy(obj->custom_icon_data, src->custom_icon_data, CUSTOM_ICON_MAX_SIZE);
|
||||
@@ -66,8 +65,8 @@ static void BrowserItem_t_set(BrowserItem_t* obj, const BrowserItem_t* src) {
|
||||
}
|
||||
|
||||
static void BrowserItem_t_clear(BrowserItem_t* obj) {
|
||||
string_clear(obj->path);
|
||||
string_clear(obj->display_name);
|
||||
furi_string_free(obj->path);
|
||||
furi_string_free(obj->display_name);
|
||||
if(obj->custom_icon_data) {
|
||||
free(obj->custom_icon_data);
|
||||
}
|
||||
@@ -94,7 +93,7 @@ struct FileBrowser {
|
||||
FileBrowserLoadItemCallback item_callback;
|
||||
void* item_context;
|
||||
|
||||
string_ptr result_path;
|
||||
FuriString* result_path;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@@ -125,10 +124,11 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context);
|
||||
static void
|
||||
browser_folder_open_cb(void* context, uint32_t item_cnt, int32_t file_idx, bool is_root);
|
||||
static void browser_list_load_cb(void* context, uint32_t list_load_offset);
|
||||
static void browser_list_item_cb(void* context, string_t item_path, bool is_folder, bool is_last);
|
||||
static void
|
||||
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last);
|
||||
static void browser_long_load_cb(void* context);
|
||||
|
||||
FileBrowser* file_browser_alloc(string_ptr result_path) {
|
||||
FileBrowser* file_browser_alloc(FuriString* result_path) {
|
||||
furi_assert(result_path);
|
||||
FileBrowser* browser = malloc(sizeof(FileBrowser));
|
||||
browser->view = view_alloc();
|
||||
@@ -186,7 +186,7 @@ void file_browser_configure(
|
||||
});
|
||||
}
|
||||
|
||||
void file_browser_start(FileBrowser* browser, string_t path) {
|
||||
void file_browser_start(FileBrowser* browser, FuriString* path) {
|
||||
furi_assert(browser);
|
||||
browser->worker = file_browser_worker_alloc(path, browser->ext_filter, browser->skip_assets);
|
||||
file_browser_worker_set_callback_context(browser->worker, browser);
|
||||
@@ -336,7 +336,8 @@ static void browser_list_load_cb(void* context, uint32_t list_load_offset) {
|
||||
BrowserItem_t_clear(&back_item);
|
||||
}
|
||||
|
||||
static void browser_list_item_cb(void* context, string_t item_path, bool is_folder, bool is_last) {
|
||||
static void
|
||||
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
|
||||
furi_assert(context);
|
||||
FileBrowser* browser = (FileBrowser*)context;
|
||||
|
||||
@@ -344,8 +345,8 @@ static void browser_list_item_cb(void* context, string_t item_path, bool is_fold
|
||||
item.custom_icon_data = NULL;
|
||||
|
||||
if(!is_last) {
|
||||
string_init_set(item.path, item_path);
|
||||
string_init(item.display_name);
|
||||
item.path = furi_string_alloc_set(item_path);
|
||||
item.display_name = furi_string_alloc();
|
||||
if(is_folder) {
|
||||
item.type = BrowserItemTypeFolder;
|
||||
} else {
|
||||
@@ -363,7 +364,7 @@ static void browser_list_item_cb(void* context, string_t item_path, bool is_fold
|
||||
}
|
||||
}
|
||||
|
||||
if(string_empty_p(item.display_name)) {
|
||||
if(furi_string_empty(item.display_name)) {
|
||||
path_extract_filename(
|
||||
item_path,
|
||||
item.display_name,
|
||||
@@ -376,8 +377,8 @@ static void browser_list_item_cb(void* context, string_t item_path, bool is_fold
|
||||
// TODO: calculate if element is visible
|
||||
return true;
|
||||
});
|
||||
string_clear(item.display_name);
|
||||
string_clear(item.path);
|
||||
furi_string_free(item.display_name);
|
||||
furi_string_free(item.path);
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, (FileBrowserModel * model) {
|
||||
@@ -427,8 +428,8 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
|
||||
uint32_t array_size = items_array_size(model->items);
|
||||
bool show_scrollbar = model->item_cnt > LIST_ITEMS;
|
||||
|
||||
string_t filename;
|
||||
string_init(filename);
|
||||
FuriString* filename;
|
||||
filename = furi_string_alloc();
|
||||
|
||||
for(uint32_t i = 0; i < MIN(model->item_cnt, LIST_ITEMS); i++) {
|
||||
int32_t idx = CLAMP((uint32_t)(i + model->list_offset), model->item_cnt, 0u);
|
||||
@@ -440,16 +441,16 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
|
||||
BrowserItem_t* item = items_array_get(
|
||||
model->items, CLAMP(idx - model->array_offset, (int32_t)(array_size - 1), 0));
|
||||
item_type = item->type;
|
||||
string_set(filename, item->display_name);
|
||||
furi_string_set(filename, item->display_name);
|
||||
if(item_type == BrowserItemTypeFile) {
|
||||
custom_icon_data = item->custom_icon_data;
|
||||
}
|
||||
} else {
|
||||
string_set_str(filename, "---");
|
||||
furi_string_set(filename, "---");
|
||||
}
|
||||
|
||||
if(item_type == BrowserItemTypeBack) {
|
||||
string_set_str(filename, ". .");
|
||||
furi_string_set(filename, ". .");
|
||||
}
|
||||
|
||||
elements_string_fit_width(
|
||||
@@ -471,7 +472,8 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
|
||||
canvas_draw_icon(
|
||||
canvas, 2, Y_OFFSET + 1 + i * FRAME_HEIGHT, BrowserItemIcons[item_type]);
|
||||
}
|
||||
canvas_draw_str(canvas, 15, Y_OFFSET + 9 + i * FRAME_HEIGHT, string_get_cstr(filename));
|
||||
canvas_draw_str(
|
||||
canvas, 15, Y_OFFSET + 9 + i * FRAME_HEIGHT, furi_string_get_cstr(filename));
|
||||
}
|
||||
|
||||
if(show_scrollbar) {
|
||||
@@ -484,7 +486,7 @@ static void browser_draw_list(Canvas* canvas, FileBrowserModel* model) {
|
||||
model->item_cnt);
|
||||
}
|
||||
|
||||
string_clear(filename);
|
||||
furi_string_free(filename);
|
||||
}
|
||||
|
||||
static void file_browser_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
@@ -568,7 +570,7 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
|
||||
file_browser_worker_folder_enter(
|
||||
browser->worker, selected_item->path, select_index);
|
||||
} else if(selected_item->type == BrowserItemTypeFile) {
|
||||
string_set(browser->result_path, selected_item->path);
|
||||
furi_string_set(browser->result_path, selected_item->path);
|
||||
if(browser->callback) {
|
||||
browser->callback(browser->context);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "m-string.h"
|
||||
#include <gui/view.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -15,10 +14,13 @@ extern "C" {
|
||||
typedef struct FileBrowser FileBrowser;
|
||||
typedef void (*FileBrowserCallback)(void* context);
|
||||
|
||||
typedef bool (
|
||||
*FileBrowserLoadItemCallback)(string_t path, void* context, uint8_t** icon, string_t item_name);
|
||||
typedef bool (*FileBrowserLoadItemCallback)(
|
||||
FuriString* path,
|
||||
void* context,
|
||||
uint8_t** icon,
|
||||
FuriString* item_name);
|
||||
|
||||
FileBrowser* file_browser_alloc(string_ptr result_path);
|
||||
FileBrowser* file_browser_alloc(FuriString* result_path);
|
||||
|
||||
void file_browser_free(FileBrowser* browser);
|
||||
|
||||
@@ -31,7 +33,7 @@ void file_browser_configure(
|
||||
const Icon* file_icon,
|
||||
bool hide_ext);
|
||||
|
||||
void file_browser_start(FileBrowser* browser, string_t path);
|
||||
void file_browser_start(FileBrowser* browser, FuriString* path);
|
||||
|
||||
void file_browser_stop(FileBrowser* browser);
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include "file_browser_worker.h"
|
||||
#include <core/check.h>
|
||||
#include <core/common_defines.h>
|
||||
#include "m-string.h"
|
||||
#include "storage/filesystem_api_defines.h"
|
||||
#include <m-array.h>
|
||||
#include <stdbool.h>
|
||||
@@ -35,8 +34,8 @@ ARRAY_DEF(idx_last_array, int32_t)
|
||||
struct BrowserWorker {
|
||||
FuriThread* thread;
|
||||
|
||||
string_t filter_extension;
|
||||
string_t path_next;
|
||||
FuriString* filter_extension;
|
||||
FuriString* path_next;
|
||||
int32_t item_sel_idx;
|
||||
uint32_t load_offset;
|
||||
uint32_t load_count;
|
||||
@@ -50,11 +49,11 @@ struct BrowserWorker {
|
||||
BrowserWorkerLongLoadCallback long_load_cb;
|
||||
};
|
||||
|
||||
static bool browser_path_is_file(string_t path) {
|
||||
static bool browser_path_is_file(FuriString* path) {
|
||||
bool state = false;
|
||||
FileInfo file_info;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
if((file_info.flags & FSF_DIRECTORY) == 0) {
|
||||
state = true;
|
||||
}
|
||||
@@ -63,50 +62,50 @@ static bool browser_path_is_file(string_t path) {
|
||||
return state;
|
||||
}
|
||||
|
||||
static bool browser_path_trim(string_t path) {
|
||||
static bool browser_path_trim(FuriString* path) {
|
||||
bool is_root = false;
|
||||
size_t filename_start = string_search_rchar(path, '/');
|
||||
string_left(path, filename_start);
|
||||
if((string_empty_p(path)) || (filename_start == STRING_FAILURE)) {
|
||||
string_set_str(path, BROWSER_ROOT);
|
||||
size_t filename_start = furi_string_search_rchar(path, '/');
|
||||
furi_string_left(path, filename_start);
|
||||
if((furi_string_empty(path)) || (filename_start == FURI_STRING_FAILURE)) {
|
||||
furi_string_set(path, BROWSER_ROOT);
|
||||
is_root = true;
|
||||
}
|
||||
return is_root;
|
||||
}
|
||||
|
||||
static bool browser_filter_by_name(BrowserWorker* browser, string_t name, bool is_folder) {
|
||||
static bool browser_filter_by_name(BrowserWorker* browser, FuriString* name, bool is_folder) {
|
||||
if(is_folder) {
|
||||
// Skip assets folders (if enabled)
|
||||
if(browser->skip_assets) {
|
||||
return ((string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true));
|
||||
return ((furi_string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
// Filter files by extension
|
||||
if((string_empty_p(browser->filter_extension)) ||
|
||||
(string_cmp_str(browser->filter_extension, "*") == 0)) {
|
||||
if((furi_string_empty(browser->filter_extension)) ||
|
||||
(furi_string_cmp_str(browser->filter_extension, "*") == 0)) {
|
||||
return true;
|
||||
}
|
||||
if(string_end_with_string_p(name, browser->filter_extension)) {
|
||||
if(furi_string_end_with(name, browser->filter_extension)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool browser_folder_check_and_switch(string_t path) {
|
||||
static bool browser_folder_check_and_switch(FuriString* path) {
|
||||
FileInfo file_info;
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
bool is_root = false;
|
||||
|
||||
if(string_search_rchar(path, '/') == 0) {
|
||||
if(furi_string_search_rchar(path, '/') == 0) {
|
||||
is_root = true;
|
||||
}
|
||||
|
||||
while(1) {
|
||||
// Check if folder is existing and navigate back if not
|
||||
if(storage_common_stat(storage, string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(path), &file_info) == FSE_OK) {
|
||||
if(file_info.flags & FSF_DIRECTORY) {
|
||||
break;
|
||||
}
|
||||
@@ -122,8 +121,8 @@ static bool browser_folder_check_and_switch(string_t path) {
|
||||
|
||||
static bool browser_folder_init(
|
||||
BrowserWorker* browser,
|
||||
string_t path,
|
||||
string_t filename,
|
||||
FuriString* path,
|
||||
FuriString* filename,
|
||||
uint32_t* item_cnt,
|
||||
int32_t* file_idx) {
|
||||
bool state = false;
|
||||
@@ -134,13 +133,13 @@ static bool browser_folder_init(
|
||||
File* directory = storage_file_alloc(storage);
|
||||
|
||||
char name_temp[FILE_NAME_LEN_MAX];
|
||||
string_t name_str;
|
||||
string_init(name_str);
|
||||
FuriString* name_str;
|
||||
name_str = furi_string_alloc();
|
||||
|
||||
*item_cnt = 0;
|
||||
*file_idx = -1;
|
||||
|
||||
if(storage_dir_open(directory, string_get_cstr(path))) {
|
||||
if(storage_dir_open(directory, furi_string_get_cstr(path))) {
|
||||
state = true;
|
||||
while(1) {
|
||||
if(!storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX)) {
|
||||
@@ -148,10 +147,10 @@ static bool browser_folder_init(
|
||||
}
|
||||
if((storage_file_get_error(directory) == FSE_OK) && (name_temp[0] != '\0')) {
|
||||
total_files_cnt++;
|
||||
string_set_str(name_str, name_temp);
|
||||
furi_string_set(name_str, name_temp);
|
||||
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
|
||||
if(!string_empty_p(filename)) {
|
||||
if(string_cmp(name_str, filename) == 0) {
|
||||
if(!furi_string_empty(filename)) {
|
||||
if(furi_string_cmp(name_str, filename) == 0) {
|
||||
*file_idx = *item_cnt;
|
||||
}
|
||||
}
|
||||
@@ -167,7 +166,7 @@ static bool browser_folder_init(
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(name_str);
|
||||
furi_string_free(name_str);
|
||||
|
||||
storage_dir_close(directory);
|
||||
storage_file_free(directory);
|
||||
@@ -178,20 +177,20 @@ static bool browser_folder_init(
|
||||
}
|
||||
|
||||
static bool
|
||||
browser_folder_load(BrowserWorker* browser, string_t path, uint32_t offset, uint32_t count) {
|
||||
browser_folder_load(BrowserWorker* browser, FuriString* path, uint32_t offset, uint32_t count) {
|
||||
FileInfo file_info;
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
File* directory = storage_file_alloc(storage);
|
||||
|
||||
char name_temp[FILE_NAME_LEN_MAX];
|
||||
string_t name_str;
|
||||
string_init(name_str);
|
||||
FuriString* name_str;
|
||||
name_str = furi_string_alloc();
|
||||
|
||||
uint32_t items_cnt = 0;
|
||||
|
||||
do {
|
||||
if(!storage_dir_open(directory, string_get_cstr(path))) {
|
||||
if(!storage_dir_open(directory, furi_string_get_cstr(path))) {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -201,7 +200,7 @@ static bool
|
||||
break;
|
||||
}
|
||||
if(storage_file_get_error(directory) == FSE_OK) {
|
||||
string_set_str(name_str, name_temp);
|
||||
furi_string_set(name_str, name_temp);
|
||||
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
|
||||
items_cnt++;
|
||||
}
|
||||
@@ -223,9 +222,9 @@ static bool
|
||||
break;
|
||||
}
|
||||
if(storage_file_get_error(directory) == FSE_OK) {
|
||||
string_set_str(name_str, name_temp);
|
||||
furi_string_set(name_str, name_temp);
|
||||
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
|
||||
string_printf(name_str, "%s/%s", string_get_cstr(path), name_temp);
|
||||
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
|
||||
if(browser->list_item_cb) {
|
||||
browser->list_item_cb(
|
||||
browser->cb_ctx, name_str, (file_info.flags & FSF_DIRECTORY), false);
|
||||
@@ -241,7 +240,7 @@ static bool
|
||||
}
|
||||
} while(0);
|
||||
|
||||
string_clear(name_str);
|
||||
furi_string_free(name_str);
|
||||
|
||||
storage_dir_close(directory);
|
||||
storage_file_free(directory);
|
||||
@@ -257,12 +256,12 @@ static int32_t browser_worker(void* context) {
|
||||
FURI_LOG_D(TAG, "Start");
|
||||
|
||||
uint32_t items_cnt = 0;
|
||||
string_t path;
|
||||
string_init_set_str(path, BROWSER_ROOT);
|
||||
FuriString* path;
|
||||
path = furi_string_alloc_set(BROWSER_ROOT);
|
||||
browser->item_sel_idx = -1;
|
||||
|
||||
string_t filename;
|
||||
string_init(filename);
|
||||
FuriString* filename;
|
||||
filename = furi_string_alloc();
|
||||
|
||||
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);
|
||||
|
||||
@@ -282,7 +281,7 @@ static int32_t browser_worker(void* context) {
|
||||
}
|
||||
|
||||
if(flags & WorkerEvtFolderEnter) {
|
||||
string_set(path, browser->path_next);
|
||||
furi_string_set(path, browser->path_next);
|
||||
bool is_root = browser_folder_check_and_switch(path);
|
||||
|
||||
// Push previous selected item index to history array
|
||||
@@ -293,13 +292,13 @@ static int32_t browser_worker(void* context) {
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"Enter folder: %s items: %u idx: %d",
|
||||
string_get_cstr(path),
|
||||
furi_string_get_cstr(path),
|
||||
items_cnt,
|
||||
file_idx);
|
||||
if(browser->folder_cb) {
|
||||
browser->folder_cb(browser->cb_ctx, items_cnt, file_idx, is_root);
|
||||
}
|
||||
string_reset(filename);
|
||||
furi_string_reset(filename);
|
||||
}
|
||||
|
||||
if(flags & WorkerEvtFolderExit) {
|
||||
@@ -313,7 +312,11 @@ static int32_t browser_worker(void* context) {
|
||||
idx_last_array_pop_back(&file_idx, browser->idx_last);
|
||||
}
|
||||
FURI_LOG_D(
|
||||
TAG, "Exit to: %s items: %u idx: %d", string_get_cstr(path), items_cnt, file_idx);
|
||||
TAG,
|
||||
"Exit to: %s items: %u idx: %d",
|
||||
furi_string_get_cstr(path),
|
||||
items_cnt,
|
||||
file_idx);
|
||||
if(browser->folder_cb) {
|
||||
browser->folder_cb(browser->cb_ctx, items_cnt, file_idx, is_root);
|
||||
}
|
||||
@@ -323,12 +326,12 @@ static int32_t browser_worker(void* context) {
|
||||
bool is_root = browser_folder_check_and_switch(path);
|
||||
|
||||
int32_t file_idx = 0;
|
||||
string_reset(filename);
|
||||
furi_string_reset(filename);
|
||||
browser_folder_init(browser, path, filename, &items_cnt, &file_idx);
|
||||
FURI_LOG_D(
|
||||
TAG,
|
||||
"Refresh folder: %s items: %u idx: %d",
|
||||
string_get_cstr(path),
|
||||
furi_string_get_cstr(path),
|
||||
items_cnt,
|
||||
browser->item_sel_idx);
|
||||
if(browser->folder_cb) {
|
||||
@@ -346,21 +349,22 @@ static int32_t browser_worker(void* context) {
|
||||
}
|
||||
}
|
||||
|
||||
string_clear(filename);
|
||||
string_clear(path);
|
||||
furi_string_free(filename);
|
||||
furi_string_free(path);
|
||||
|
||||
FURI_LOG_D(TAG, "End");
|
||||
return 0;
|
||||
}
|
||||
|
||||
BrowserWorker* file_browser_worker_alloc(string_t path, const char* filter_ext, bool skip_assets) {
|
||||
BrowserWorker*
|
||||
file_browser_worker_alloc(FuriString* path, const char* filter_ext, bool skip_assets) {
|
||||
BrowserWorker* browser = malloc(sizeof(BrowserWorker));
|
||||
|
||||
idx_last_array_init(browser->idx_last);
|
||||
|
||||
string_init_set_str(browser->filter_extension, filter_ext);
|
||||
browser->filter_extension = furi_string_alloc_set(filter_ext);
|
||||
browser->skip_assets = skip_assets;
|
||||
string_init_set(browser->path_next, path);
|
||||
browser->path_next = furi_string_alloc_set(path);
|
||||
|
||||
browser->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(browser->thread, "BrowserWorker");
|
||||
@@ -379,8 +383,8 @@ void file_browser_worker_free(BrowserWorker* browser) {
|
||||
furi_thread_join(browser->thread);
|
||||
furi_thread_free(browser->thread);
|
||||
|
||||
string_clear(browser->filter_extension);
|
||||
string_clear(browser->path_next);
|
||||
furi_string_free(browser->filter_extension);
|
||||
furi_string_free(browser->path_next);
|
||||
|
||||
idx_last_array_clear(browser->idx_last);
|
||||
|
||||
@@ -422,19 +426,19 @@ void file_browser_worker_set_long_load_callback(
|
||||
|
||||
void file_browser_worker_set_config(
|
||||
BrowserWorker* browser,
|
||||
string_t path,
|
||||
FuriString* path,
|
||||
const char* filter_ext,
|
||||
bool skip_assets) {
|
||||
furi_assert(browser);
|
||||
string_set(browser->path_next, path);
|
||||
string_set_str(browser->filter_extension, filter_ext);
|
||||
furi_string_set(browser->path_next, path);
|
||||
furi_string_set(browser->filter_extension, filter_ext);
|
||||
browser->skip_assets = skip_assets;
|
||||
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);
|
||||
}
|
||||
|
||||
void file_browser_worker_folder_enter(BrowserWorker* browser, string_t path, int32_t item_idx) {
|
||||
void file_browser_worker_folder_enter(BrowserWorker* browser, FuriString* path, int32_t item_idx) {
|
||||
furi_assert(browser);
|
||||
string_set(browser->path_next, path);
|
||||
furi_string_set(browser->path_next, path);
|
||||
browser->item_sel_idx = item_idx;
|
||||
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "m-string.h"
|
||||
#include <gui/view.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -17,12 +16,13 @@ typedef void (*BrowserWorkerFolderOpenCallback)(
|
||||
typedef void (*BrowserWorkerListLoadCallback)(void* context, uint32_t list_load_offset);
|
||||
typedef void (*BrowserWorkerListItemCallback)(
|
||||
void* context,
|
||||
string_t item_path,
|
||||
FuriString* item_path,
|
||||
bool is_folder,
|
||||
bool is_last);
|
||||
typedef void (*BrowserWorkerLongLoadCallback)(void* context);
|
||||
|
||||
BrowserWorker* file_browser_worker_alloc(string_t path, const char* filter_ext, bool skip_assets);
|
||||
BrowserWorker*
|
||||
file_browser_worker_alloc(FuriString* path, const char* filter_ext, bool skip_assets);
|
||||
|
||||
void file_browser_worker_free(BrowserWorker* browser);
|
||||
|
||||
@@ -46,11 +46,11 @@ void file_browser_worker_set_long_load_callback(
|
||||
|
||||
void file_browser_worker_set_config(
|
||||
BrowserWorker* browser,
|
||||
string_t path,
|
||||
FuriString* path,
|
||||
const char* filter_ext,
|
||||
bool skip_assets);
|
||||
|
||||
void file_browser_worker_folder_enter(BrowserWorker* browser, string_t path, int32_t item_idx);
|
||||
void file_browser_worker_folder_enter(BrowserWorker* browser, FuriString* path, int32_t item_idx);
|
||||
|
||||
void file_browser_worker_folder_exit(BrowserWorker* browser);
|
||||
|
||||
|
||||
@@ -65,17 +65,17 @@ static void submenu_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas_set_color(canvas, ColorBlack);
|
||||
}
|
||||
|
||||
string_t disp_str;
|
||||
string_init_set_str(disp_str, SubmenuItemArray_cref(it)->label);
|
||||
FuriString* disp_str;
|
||||
disp_str = furi_string_alloc_set(SubmenuItemArray_cref(it)->label);
|
||||
elements_string_fit_width(canvas, disp_str, item_width - 20);
|
||||
|
||||
canvas_draw_str(
|
||||
canvas,
|
||||
6,
|
||||
y_offset + (item_position * item_height) + item_height - 4,
|
||||
string_get_cstr(disp_str));
|
||||
furi_string_get_cstr(disp_str));
|
||||
|
||||
string_clear(disp_str);
|
||||
furi_string_free(disp_str);
|
||||
}
|
||||
|
||||
position++;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "text_box.h"
|
||||
#include "gui/canvas.h"
|
||||
#include <m-string.h>
|
||||
#include <furi.h>
|
||||
#include <gui/elements.h>
|
||||
#include <stdint.h>
|
||||
@@ -12,7 +11,7 @@ struct TextBox {
|
||||
typedef struct {
|
||||
const char* text;
|
||||
char* text_pos;
|
||||
string_t text_formatted;
|
||||
FuriString* text_formatted;
|
||||
int32_t scroll_pos;
|
||||
int32_t scroll_num;
|
||||
TextBoxFont font;
|
||||
@@ -66,17 +65,17 @@ static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
|
||||
if(line_width + glyph_width > text_width) {
|
||||
line_num++;
|
||||
line_width = 0;
|
||||
string_push_back(model->text_formatted, '\n');
|
||||
furi_string_push_back(model->text_formatted, '\n');
|
||||
}
|
||||
line_width += glyph_width;
|
||||
} else {
|
||||
line_num++;
|
||||
line_width = 0;
|
||||
}
|
||||
string_push_back(model->text_formatted, symb);
|
||||
furi_string_push_back(model->text_formatted, symb);
|
||||
}
|
||||
line_num++;
|
||||
model->text = string_get_cstr(model->text_formatted);
|
||||
model->text = furi_string_get_cstr(model->text_formatted);
|
||||
model->text_pos = (char*)model->text;
|
||||
if(model->focus == TextBoxFocusEnd && line_num > 5) {
|
||||
// Set text position to 5th line from the end
|
||||
@@ -140,7 +139,7 @@ TextBox* text_box_alloc() {
|
||||
with_view_model(
|
||||
text_box->view, (TextBoxModel * model) {
|
||||
model->text = NULL;
|
||||
string_init_set_str(model->text_formatted, "");
|
||||
model->text_formatted = furi_string_alloc_set("");
|
||||
model->formatted = false;
|
||||
model->font = TextBoxFontText;
|
||||
return true;
|
||||
@@ -154,7 +153,7 @@ void text_box_free(TextBox* text_box) {
|
||||
|
||||
with_view_model(
|
||||
text_box->view, (TextBoxModel * model) {
|
||||
string_clear(model->text_formatted);
|
||||
furi_string_free(model->text_formatted);
|
||||
return true;
|
||||
});
|
||||
view_free(text_box->view);
|
||||
@@ -172,7 +171,7 @@ void text_box_reset(TextBox* text_box) {
|
||||
with_view_model(
|
||||
text_box->view, (TextBoxModel * model) {
|
||||
model->text = NULL;
|
||||
string_set_str(model->text_formatted, "");
|
||||
furi_string_set(model->text_formatted, "");
|
||||
model->font = TextBoxFontText;
|
||||
model->focus = TextBoxFocusStart;
|
||||
return true;
|
||||
@@ -186,8 +185,8 @@ void text_box_set_text(TextBox* text_box, const char* text) {
|
||||
with_view_model(
|
||||
text_box->view, (TextBoxModel * model) {
|
||||
model->text = text;
|
||||
string_reset(model->text_formatted);
|
||||
string_reserve(model->text_formatted, strlen(text));
|
||||
furi_string_reset(model->text_formatted);
|
||||
furi_string_reserve(model->text_formatted, strlen(text));
|
||||
model->formatted = false;
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -27,7 +27,7 @@ typedef struct {
|
||||
|
||||
TextInputValidatorCallback validator_callback;
|
||||
void* validator_callback_context;
|
||||
string_t validator_text;
|
||||
FuriString* validator_text;
|
||||
bool valadator_message_visible;
|
||||
} TextInputModel;
|
||||
|
||||
@@ -257,7 +257,7 @@ static void text_input_view_draw_callback(Canvas* canvas, void* _model) {
|
||||
canvas_draw_icon(canvas, 10, 14, &I_WarningDolphin_45x42);
|
||||
canvas_draw_rframe(canvas, 8, 8, 112, 50, 3);
|
||||
canvas_draw_rframe(canvas, 9, 9, 110, 48, 2);
|
||||
elements_multiline_text(canvas, 62, 20, string_get_cstr(model->validator_text));
|
||||
elements_multiline_text(canvas, 62, 20, furi_string_get_cstr(model->validator_text));
|
||||
canvas_set_font(canvas, FontKeyboard);
|
||||
}
|
||||
}
|
||||
@@ -447,7 +447,7 @@ TextInput* text_input_alloc() {
|
||||
|
||||
with_view_model(
|
||||
text_input->view, (TextInputModel * model) {
|
||||
string_init(model->validator_text);
|
||||
model->validator_text = furi_string_alloc();
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -460,7 +460,7 @@ void text_input_free(TextInput* text_input) {
|
||||
furi_assert(text_input);
|
||||
with_view_model(
|
||||
text_input->view, (TextInputModel * model) {
|
||||
string_clear(model->validator_text);
|
||||
furi_string_free(model->validator_text);
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -489,7 +489,7 @@ void text_input_reset(TextInput* text_input) {
|
||||
model->callback_context = NULL;
|
||||
model->validator_callback = NULL;
|
||||
model->validator_callback_context = NULL;
|
||||
string_reset(model->validator_text);
|
||||
furi_string_reset(model->validator_text);
|
||||
model->valadator_message_visible = false;
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
#include <gui/view.h>
|
||||
#include "validators.h"
|
||||
#include <m-string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@@ -16,7 +15,7 @@ extern "C" {
|
||||
/** Text input anonymous structure */
|
||||
typedef struct TextInput TextInput;
|
||||
typedef void (*TextInputCallback)(void* context);
|
||||
typedef bool (*TextInputValidatorCallback)(const char* text, string_t error, void* context);
|
||||
typedef bool (*TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
|
||||
|
||||
/** Allocate and initialize text input
|
||||
*
|
||||
|
||||
@@ -8,7 +8,7 @@ struct ValidatorIsFile {
|
||||
char* current_name;
|
||||
};
|
||||
|
||||
bool validator_is_file_callback(const char* text, string_t error, void* context) {
|
||||
bool validator_is_file_callback(const char* text, FuriString* error, void* context) {
|
||||
furi_assert(context);
|
||||
ValidatorIsFile* instance = context;
|
||||
|
||||
@@ -19,16 +19,16 @@ bool validator_is_file_callback(const char* text, string_t error, void* context)
|
||||
}
|
||||
|
||||
bool ret = true;
|
||||
string_t path;
|
||||
string_init_printf(path, "%s/%s%s", instance->app_path_folder, text, instance->app_extension);
|
||||
FuriString* path = furi_string_alloc_printf(
|
||||
"%s/%s%s", instance->app_path_folder, text, instance->app_extension);
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
if(storage_common_stat(storage, string_get_cstr(path), NULL) == FSE_OK) {
|
||||
if(storage_common_stat(storage, furi_string_get_cstr(path), NULL) == FSE_OK) {
|
||||
ret = false;
|
||||
string_printf(error, "This name\nexists!\nChoose\nanother one.");
|
||||
furi_string_printf(error, "This name\nexists!\nChoose\nanother one.");
|
||||
} else {
|
||||
ret = true;
|
||||
}
|
||||
string_clear(path);
|
||||
furi_string_free(path);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <m-string.h>
|
||||
#include <core/common_defines.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -15,7 +14,7 @@ ValidatorIsFile* validator_is_file_alloc_init(
|
||||
|
||||
void validator_is_file_free(ValidatorIsFile* instance);
|
||||
|
||||
bool validator_is_file_callback(const char* text, string_t error, void* context);
|
||||
bool validator_is_file_callback(const char* text, FuriString* error, void* context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
struct VariableItem {
|
||||
const char* label;
|
||||
uint8_t current_value_index;
|
||||
string_t current_value_text;
|
||||
FuriString* current_value_text;
|
||||
uint8_t values_count;
|
||||
VariableItemChangeCallback change_callback;
|
||||
void* context;
|
||||
@@ -77,7 +77,7 @@ static void variable_item_list_draw_callback(Canvas* canvas, void* _model) {
|
||||
item_text_y,
|
||||
AlignCenter,
|
||||
AlignBottom,
|
||||
string_get_cstr(item->current_value_text));
|
||||
furi_string_get_cstr(item->current_value_text));
|
||||
|
||||
if(item->current_value_index < (item->values_count - 1)) {
|
||||
canvas_draw_str(canvas, 115, item_text_y, ">");
|
||||
@@ -303,7 +303,7 @@ void variable_item_list_free(VariableItemList* variable_item_list) {
|
||||
VariableItemArray_it_t it;
|
||||
for(VariableItemArray_it(it, model->items); !VariableItemArray_end_p(it);
|
||||
VariableItemArray_next(it)) {
|
||||
string_clear(VariableItemArray_ref(it)->current_value_text);
|
||||
furi_string_free(VariableItemArray_ref(it)->current_value_text);
|
||||
}
|
||||
VariableItemArray_clear(model->items);
|
||||
return false;
|
||||
@@ -320,7 +320,7 @@ void variable_item_list_reset(VariableItemList* variable_item_list) {
|
||||
VariableItemArray_it_t it;
|
||||
for(VariableItemArray_it(it, model->items); !VariableItemArray_end_p(it);
|
||||
VariableItemArray_next(it)) {
|
||||
string_clear(VariableItemArray_ref(it)->current_value_text);
|
||||
furi_string_free(VariableItemArray_ref(it)->current_value_text);
|
||||
}
|
||||
VariableItemArray_reset(model->items);
|
||||
return false;
|
||||
@@ -350,7 +350,7 @@ VariableItem* variable_item_list_add(
|
||||
item->change_callback = change_callback;
|
||||
item->context = context;
|
||||
item->current_value_index = 0;
|
||||
string_init(item->current_value_text);
|
||||
item->current_value_text = furi_string_alloc();
|
||||
return true;
|
||||
});
|
||||
|
||||
@@ -376,7 +376,7 @@ void variable_item_set_current_value_index(VariableItem* item, uint8_t current_v
|
||||
}
|
||||
|
||||
void variable_item_set_current_value_text(VariableItem* item, const char* current_value_text) {
|
||||
string_set_str(item->current_value_text, current_value_text);
|
||||
furi_string_set(item->current_value_text, current_value_text);
|
||||
}
|
||||
|
||||
uint8_t variable_item_get_current_value_index(VariableItem* item) {
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user