From 42af1a788ec81d50125fbe90bf8355bf00135d42 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Wed, 20 Mar 2024 05:51:39 +0000 Subject: [PATCH] Initial fixes for new canvas + furi checks --- applications/main/momentum_app/momentum_app.c | 4 +- applications/services/gui/elements.c | 89 +++++++++---------- applications/services/gui/elements.h | 83 ++++++++--------- applications/services/gui/modules/menu.c | 4 +- lib/flipper_application/flipper_application.c | 3 +- targets/f7/api_symbols.csv | 32 +++---- 6 files changed, 104 insertions(+), 111 deletions(-) diff --git a/applications/main/momentum_app/momentum_app.c b/applications/main/momentum_app/momentum_app.c index 362caf64ac..d8a1184731 100644 --- a/applications/main/momentum_app/momentum_app.c +++ b/applications/main/momentum_app/momentum_app.c @@ -245,6 +245,7 @@ MomentumApp* momentum_app_alloc() { Stream* stream = file_stream_alloc(storage); FuriString* line = furi_string_alloc(); uint32_t version; + uint8_t* unused_icon = malloc(FAP_MANIFEST_MAX_ICON_SIZE); if(file_stream_open(stream, MAINMENU_APPS_PATH, FSAM_READ, FSOM_OPEN_EXISTING) && stream_read_line(stream, line) && sscanf(furi_string_get_cstr(line), "MenuAppList Version %lu", &version) == 1 && @@ -260,7 +261,7 @@ MomentumApp* momentum_app_alloc() { } } CharList_push_back(app->mainmenu_app_exes, strdup(furi_string_get_cstr(line))); - flipper_application_load_name_and_icon(line, storage, NULL, line); + flipper_application_load_name_and_icon(line, storage, &unused_icon, line); if(!furi_string_cmp(line, "Momentum")) { furi_string_set(line, "MNTM"); } else if(!furi_string_cmp(line, "125 kHz RFID")) { @@ -276,6 +277,7 @@ MomentumApp* momentum_app_alloc() { CharList_push_back(app->mainmenu_app_labels, strdup(furi_string_get_cstr(line))); } } + free(unused_icon); furi_string_free(line); file_stream_close(stream); stream_free(stream); diff --git a/applications/services/gui/elements.c b/applications/services/gui/elements.c index 47f5802626..1160ed70af 100644 --- a/applications/services/gui/elements.c +++ b/applications/services/gui/elements.c @@ -27,7 +27,7 @@ typedef struct { const char* text; } ElementTextBoxLine; -void elements_progress_bar(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, float progress) { +void elements_progress_bar(Canvas* canvas, int32_t x, int32_t y, size_t width, float progress) { furi_check(canvas); furi_check((progress >= 0.0f) && (progress <= 1.0f)); uint8_t height = 9; @@ -44,9 +44,9 @@ void elements_progress_bar(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, void elements_progress_bar_with_text( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, float progress, const char* text) { furi_check(canvas); @@ -69,9 +69,9 @@ void elements_progress_bar_with_text( void elements_scrollbar_pos( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t height, + int32_t x, + int32_t y, + size_t height, uint16_t pos, uint16_t total) { furi_check(canvas); @@ -92,9 +92,9 @@ void elements_scrollbar_pos( void elements_scrollbar_horizontal( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, uint16_t pos, uint16_t total) { furi_check(canvas); @@ -133,7 +133,7 @@ void elements_scrollbar(Canvas* canvas, uint16_t pos, uint16_t total) { } } -void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height) { +void elements_frame(Canvas* canvas, int32_t x, int32_t y, size_t width, size_t height) { furi_check(canvas); canvas_draw_line(canvas, x + 2, y, x + width - 2, y); @@ -284,8 +284,8 @@ static size_t void elements_multiline_text_aligned( Canvas* canvas, - uint8_t x, - uint8_t y, + int32_t x, + int32_t y, Align horizontal, Align vertical, const char* text) { @@ -316,7 +316,7 @@ void elements_multiline_text_aligned( if((start[chars_fit] == '\n') || (start[chars_fit] == 0)) { line = furi_string_alloc_printf("%.*s", chars_fit, start); - } else if((y + font_height) > canvas_height(canvas)) { + } else if((y + font_height) > (int32_t)canvas_height(canvas)) { line = furi_string_alloc_printf("%.*s...\n", chars_fit, start); } else { chars_fit -= 1; // account for the dash @@ -325,7 +325,7 @@ void elements_multiline_text_aligned( 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)) { + if(y > (int32_t)canvas_height(canvas)) { break; } @@ -334,7 +334,7 @@ void elements_multiline_text_aligned( } } -void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* text) { +void elements_multiline_text(Canvas* canvas, int32_t x, int32_t y, const char* text) { furi_check(canvas); furi_check(text); @@ -357,7 +357,7 @@ void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* t furi_string_free(str); } -void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const char* text) { +void elements_multiline_text_framed(Canvas* canvas, int32_t x, int32_t y, const char* text) { furi_check(canvas); furi_check(text); @@ -384,30 +384,25 @@ void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const void elements_slightly_rounded_frame( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, - uint8_t height) { + int32_t x, + int32_t y, + size_t width, + size_t height) { furi_check(canvas); canvas_draw_rframe(canvas, x, y, width, height, 1); } void elements_slightly_rounded_box( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, - uint8_t height) { + int32_t x, + int32_t y, + size_t width, + size_t height) { furi_check(canvas); canvas_draw_rbox(canvas, x, y, width, height, 1); } -void elements_bold_rounded_frame( - Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, - uint8_t height) { +void elements_bold_rounded_frame(Canvas* canvas, int32_t x, int32_t y, size_t width, size_t height) { furi_check(canvas); canvas_set_color(canvas, ColorWhite); @@ -456,8 +451,8 @@ void elements_bubble(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_ void elements_bubble_str( Canvas* canvas, - uint8_t x, - uint8_t y, + int32_t x, + int32_t y, const char* text, Align horizontal, Align vertical) { @@ -605,9 +600,9 @@ void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width void elements_scrollable_text_line_str( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, const char* string, size_t scroll, bool ellipsis, @@ -666,9 +661,9 @@ void elements_scrollable_text_line_str( void elements_scrollable_text_line( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, FuriString* string, size_t scroll, bool ellipsis) { @@ -678,9 +673,9 @@ void elements_scrollable_text_line( void elements_scrollable_text_line_centered( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, FuriString* string, size_t scroll, bool ellipsis, @@ -691,10 +686,10 @@ void elements_scrollable_text_line_centered( void elements_text_box( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, - uint8_t height, + int32_t x, + int32_t y, + size_t width, + size_t height, Align horizontal, Align vertical, const char* text, @@ -885,7 +880,7 @@ void elements_text_box( } else { if((i == line_num - 1) && strip_to_dots) { uint8_t next_symbol_width = canvas_glyph_width(canvas, line[i].text[j]); - if(line[i].x + next_symbol_width + dots_width > x + width) { + if(line[i].x + next_symbol_width + dots_width > x + (int32_t)width) { canvas_draw_str(canvas, line[i].x, line[i].y, "..."); break; } diff --git a/applications/services/gui/elements.h b/applications/services/gui/elements.h index 56c6807d0c..d01b2a8f88 100644 --- a/applications/services/gui/elements.h +++ b/applications/services/gui/elements.h @@ -29,7 +29,7 @@ extern "C" { * @param width progress bar width * @param progress progress (0.0 - 1.0) */ -void elements_progress_bar(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, float progress); +void elements_progress_bar(Canvas* canvas, int32_t x, int32_t y, size_t width, float progress); /** Draw progress bar with text. * @@ -42,9 +42,9 @@ void elements_progress_bar(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, */ void elements_progress_bar_with_text( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, float progress, const char* text); @@ -59,9 +59,9 @@ void elements_progress_bar_with_text( */ void elements_scrollbar_pos( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t height, + int32_t x, + int32_t y, + size_t height, uint16_t pos, uint16_t total); @@ -76,9 +76,9 @@ void elements_scrollbar_pos( */ void elements_scrollbar_horizontal( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, uint16_t pos, uint16_t total); @@ -97,7 +97,7 @@ void elements_scrollbar(Canvas* canvas, uint16_t pos, uint16_t total); * @param x, y top left corner coordinates * @param width, height frame width and height */ -void elements_frame(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_t height); +void elements_frame(Canvas* canvas, int32_t x, int32_t y, size_t width, size_t height); /** Draw button in left corner * @@ -129,8 +129,8 @@ void elements_button_center(Canvas* canvas, const char* str); */ void elements_multiline_text_aligned( Canvas* canvas, - uint8_t x, - uint8_t y, + int32_t x, + int32_t y, Align horizontal, Align vertical, const char* text); @@ -141,7 +141,7 @@ void elements_multiline_text_aligned( * @param x, y top left corner coordinates * @param text string (possible multiline) */ -void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* text); +void elements_multiline_text(Canvas* canvas, int32_t x, int32_t y, const char* text); /** Draw framed multiline text * @@ -149,7 +149,7 @@ void elements_multiline_text(Canvas* canvas, uint8_t x, uint8_t y, const char* t * @param x, y top left corner coordinates * @param text string (possible multiline) */ -void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const char* text); +void elements_multiline_text_framed(Canvas* canvas, int32_t x, int32_t y, const char* text); /** Draw slightly rounded frame * @@ -159,10 +159,10 @@ void elements_multiline_text_framed(Canvas* canvas, uint8_t x, uint8_t y, const */ void elements_slightly_rounded_frame( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, - uint8_t height); + int32_t x, + int32_t y, + size_t width, + size_t height); /** Draw slightly rounded box * @@ -172,10 +172,10 @@ void elements_slightly_rounded_frame( */ void elements_slightly_rounded_box( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, - uint8_t height); + int32_t x, + int32_t y, + size_t width, + size_t height); /** Draw bold rounded frame * @@ -183,12 +183,7 @@ void elements_slightly_rounded_box( * @param x, y top left corner coordinates * @param width, height size of frame */ -void elements_bold_rounded_frame( - Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, - uint8_t height); +void elements_bold_rounded_frame(Canvas* canvas, int32_t x, int32_t y, size_t width, size_t height); /** Draw bubble frame for text * @@ -211,8 +206,8 @@ void elements_bubble(Canvas* canvas, uint8_t x, uint8_t y, uint8_t width, uint8_ */ void elements_bubble_str( Canvas* canvas, - uint8_t x, - uint8_t y, + int32_t x, + int32_t y, const char* text, Align horizontal, Align vertical); @@ -238,26 +233,26 @@ void elements_string_fit_width(Canvas* canvas, FuriString* string, uint8_t width */ void elements_scrollable_text_line_str( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, const char* string, size_t scroll, bool ellipsis, bool centered); void elements_scrollable_text_line( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, FuriString* string, size_t scroll, bool ellipsis); void elements_scrollable_text_line_centered( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, + int32_t x, + int32_t y, + size_t width, FuriString* string, size_t scroll, bool ellipsis, @@ -280,10 +275,10 @@ void elements_scrollable_text_line_centered( */ void elements_text_box( Canvas* canvas, - uint8_t x, - uint8_t y, - uint8_t width, - uint8_t height, + int32_t x, + int32_t y, + size_t width, + size_t height, Align horizontal, Align vertical, const char* text, diff --git a/applications/services/gui/modules/menu.c b/applications/services/gui/modules/menu.c index ecf9a7e3de..2b3d8dba54 100644 --- a/applications/services/gui/modules/menu.c +++ b/applications/services/gui/modules/menu.c @@ -162,8 +162,8 @@ static void menu_draw_callback(Canvas* canvas, void* _model) { item = MenuItemArray_get(model->items, shift_position); size_t width = 24; size_t height = 26; - size_t pos_x = 64; - size_t pos_y = 36; + int32_t pos_x = 64; + int32_t pos_y = 36; if(i == 0) { width += 6; height += 4; diff --git a/lib/flipper_application/flipper_application.c b/lib/flipper_application/flipper_application.c index e9550f1a89..b0fa9e5600 100644 --- a/lib/flipper_application/flipper_application.c +++ b/lib/flipper_application/flipper_application.c @@ -364,13 +364,14 @@ bool flipper_application_load_name_and_icon( preload_res == FlipperApplicationPreloadStatusApiTooOld || preload_res == FlipperApplicationPreloadStatusApiTooNew) { const FlipperApplicationManifest* manifest = flipper_application_get_manifest(app); - if(manifest->has_icon && icon_ptr != NULL && *icon_ptr != NULL) { + if(manifest->has_icon) { memcpy(*icon_ptr, manifest->icon, FAP_MANIFEST_MAX_ICON_SIZE); } furi_string_set(item_name, manifest->name); load_success = true; } else { FURI_LOG_E(TAG, "Failed to preload %s", furi_string_get_cstr(path)); + load_success = false; } flipper_application_free(app); diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index cb4cb813db..9aca0da54b 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -969,28 +969,28 @@ Function,-,dprintf,int,"int, const char*, ..." Function,-,drand48,double, Function,-,drem,double,"double, double" Function,-,dremf,float,"float, float" -Function,+,elements_bold_rounded_frame,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t" +Function,+,elements_bold_rounded_frame,void,"Canvas*, int32_t, int32_t, size_t, size_t" Function,+,elements_bubble,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t" -Function,+,elements_bubble_str,void,"Canvas*, uint8_t, uint8_t, const char*, Align, Align" +Function,+,elements_bubble_str,void,"Canvas*, int32_t, int32_t, const char*, Align, Align" Function,+,elements_button_center,void,"Canvas*, const char*" Function,+,elements_button_left,void,"Canvas*, const char*" Function,+,elements_button_right,void,"Canvas*, const char*" -Function,+,elements_frame,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t" -Function,+,elements_multiline_text,void,"Canvas*, uint8_t, uint8_t, const char*" -Function,+,elements_multiline_text_aligned,void,"Canvas*, uint8_t, uint8_t, Align, Align, const char*" -Function,+,elements_multiline_text_framed,void,"Canvas*, uint8_t, uint8_t, const char*" -Function,+,elements_progress_bar,void,"Canvas*, uint8_t, uint8_t, uint8_t, float" -Function,+,elements_progress_bar_with_text,void,"Canvas*, uint8_t, uint8_t, uint8_t, float, const char*" -Function,+,elements_scrollable_text_line,void,"Canvas*, uint8_t, uint8_t, uint8_t, FuriString*, size_t, _Bool" -Function,+,elements_scrollable_text_line_centered,void,"Canvas*, uint8_t, uint8_t, uint8_t, FuriString*, size_t, _Bool, _Bool" -Function,+,elements_scrollable_text_line_str,void,"Canvas*, uint8_t, uint8_t, uint8_t, const char*, size_t, _Bool, _Bool" +Function,+,elements_frame,void,"Canvas*, int32_t, int32_t, size_t, size_t" +Function,+,elements_multiline_text,void,"Canvas*, int32_t, int32_t, const char*" +Function,+,elements_multiline_text_aligned,void,"Canvas*, int32_t, int32_t, Align, Align, const char*" +Function,+,elements_multiline_text_framed,void,"Canvas*, int32_t, int32_t, const char*" +Function,+,elements_progress_bar,void,"Canvas*, int32_t, int32_t, size_t, float" +Function,+,elements_progress_bar_with_text,void,"Canvas*, int32_t, int32_t, size_t, float, const char*" +Function,+,elements_scrollable_text_line,void,"Canvas*, int32_t, int32_t, size_t, FuriString*, size_t, _Bool" +Function,+,elements_scrollable_text_line_centered,void,"Canvas*, int32_t, int32_t, size_t, FuriString*, size_t, _Bool, _Bool" +Function,+,elements_scrollable_text_line_str,void,"Canvas*, int32_t, int32_t, size_t, const char*, size_t, _Bool, _Bool" Function,+,elements_scrollbar,void,"Canvas*, uint16_t, uint16_t" -Function,+,elements_scrollbar_horizontal,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint16_t, uint16_t" -Function,+,elements_scrollbar_pos,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint16_t, uint16_t" -Function,+,elements_slightly_rounded_box,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t" -Function,+,elements_slightly_rounded_frame,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t" +Function,+,elements_scrollbar_horizontal,void,"Canvas*, int32_t, int32_t, size_t, uint16_t, uint16_t" +Function,+,elements_scrollbar_pos,void,"Canvas*, int32_t, int32_t, size_t, uint16_t, uint16_t" +Function,+,elements_slightly_rounded_box,void,"Canvas*, int32_t, int32_t, size_t, size_t" +Function,+,elements_slightly_rounded_frame,void,"Canvas*, int32_t, int32_t, size_t, size_t" Function,+,elements_string_fit_width,void,"Canvas*, FuriString*, uint8_t" -Function,+,elements_text_box,void,"Canvas*, uint8_t, uint8_t, uint8_t, uint8_t, Align, Align, const char*, _Bool" +Function,+,elements_text_box,void,"Canvas*, int32_t, int32_t, size_t, size_t, Align, Align, const char*, _Bool" Function,+,elf_resolve_from_hashtable,_Bool,"const ElfApiInterface*, uint32_t, Elf32_Addr*" Function,+,elf_symbolname_hash,uint32_t,const char* Function,+,empty_screen_alloc,EmptyScreen*,