Pārlūkot izejas kodu

FM Radio: Fix icon, use API buttons

Willy-JL 11 mēneši atpakaļ
vecāks
revīzija
83d9bd7439

+ 1 - 1
fm_radio/application.fam

@@ -5,7 +5,7 @@ App(
     entry_point="my_fm_radio",
     stack_size=1 * 1024,
     fap_category="GPIO",
-    fap_icon="radio.png",
+    fap_icon="images/radio.png",
     fap_icon_assets="images",
     fap_author="coolshrimp",
     fap_weburl="https://github.com/coolshrimp/flipperzero-firmware-wPlugins/tree/420/applications/external/FM_Radio",

BIN
fm_radio/images/RadioSmall.png


+ 0 - 0
fm_radio/radio.png → fm_radio/images/radio.png


+ 4 - 79
fm_radio/radio.c

@@ -94,80 +94,6 @@ struct Station stations[] = {
     {107.5, "Amor 107.5"},
 };
 
-// Function prototypes for forward declarations
-void elements_button_top_left(Canvas* canvas, const char* str);
-void elements_button_top_right(Canvas* canvas, const char* str);
-//lib can only do bottom left/right
-void elements_button_top_left(Canvas* canvas, const char* str) {
-    const uint8_t button_height = 10; // Define the height of the button
-    const uint8_t vertical_offset = 2; // Define the vertical offset of the text
-    const uint8_t horizontal_offset = 2; // Define the horizontal offset of the text
-    const uint8_t string_width = canvas_string_width(canvas, str);
-    const Icon* icon = &I_ButtonUp;
-    const uint8_t icon_h_offset = 2;
-    const uint8_t icon_width_with_offset = icon->width + icon_h_offset;
-    const uint8_t icon_v_offset = icon->height + vertical_offset;
-    const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
-
-    const uint8_t x = 0;
-    const uint8_t y = 0 + button_height;
-
-    canvas_draw_box(canvas, x, y - button_height, button_width, button_height); // Draw the button
-    canvas_draw_line(
-        canvas,
-        x + button_width + 0,
-        y - button_height,
-        x + button_width + 0,
-        y - 1); // Draw the button border
-    canvas_draw_line(
-        canvas,
-        x + button_width + 1,
-        y - button_height,
-        x + button_width + 1,
-        y - 2); // Draw the button border
-    canvas_draw_line(
-        canvas,
-        x + button_width + 2,
-        y - button_height,
-        x + button_width + 2,
-        y - 3); // Draw the button border
-
-    canvas_invert_color(canvas); // Invert the color of the text and icon
-    canvas_draw_str(
-        canvas,
-        x + horizontal_offset + icon_width_with_offset,
-        y - vertical_offset,
-        str); // Draw the text
-    canvas_draw_icon(canvas, x - horizontal_offset - icon->width, y - icon_v_offset, &I_ButtonUp);
-    canvas_invert_color(canvas); // Invert the color of the text and icon
-}
-
-void elements_button_top_right(Canvas* canvas, const char* str) {
-    const uint8_t button_height = 10;
-    const uint8_t vertical_offset = 2;
-    const uint8_t horizontal_offset = 2;
-    const uint8_t string_width = canvas_string_width(canvas, str);
-    const Icon* icon = &I_ButtonUp;
-    const uint8_t icon_h_offset = 2;
-    const uint8_t icon_width_with_offset = icon->width + icon_h_offset;
-    const uint8_t icon_v_offset = icon->height + vertical_offset;
-    const uint8_t button_width = string_width + horizontal_offset * 2 + icon_width_with_offset;
-
-    const uint8_t x = canvas_width(canvas);
-    const uint8_t y = 0 + button_height;
-
-    canvas_draw_box(canvas, x - button_width, y - button_height, button_width, button_height);
-    canvas_draw_line(canvas, x - button_width - 1, y - button_height, x - button_width - 1, y - 1);
-    canvas_draw_line(canvas, x - button_width - 2, y - button_height, x - button_width - 2, y - 2);
-    canvas_draw_line(canvas, x - button_width - 3, y - button_height, x - button_width - 3, y - 3);
-
-    canvas_invert_color(canvas);
-    canvas_draw_str(canvas, x - button_width + horizontal_offset, y - vertical_offset, str);
-    canvas_draw_icon_ex(
-        canvas, x + horizontal_offset, y - icon_v_offset, &I_ButtonUp, IconRotation180);
-    canvas_invert_color(canvas);
-}
-
 // Enumerations for submenu and view indices
 typedef enum {
     MyAppSubmenuIndexConfigure,
@@ -311,13 +237,13 @@ void my_app_view_draw_callback(Canvas* canvas, void* model) {
 
     // Draw strings on the canvas
     canvas_set_font(canvas, FontPrimary);
-    canvas_draw_str(canvas, 33, 10, "FM Radio");
-    canvas_draw_icon(canvas, 83, 0, &I_RadioSmall);
+    canvas_draw_str(canvas, 35, 10, "FM Radio");
+    canvas_draw_icon(canvas, 84, 0, &I_radio);
 
     // Draw button prompts
     canvas_set_font(canvas, FontSecondary);
-    elements_button_top_left(canvas, "Pre");
-    elements_button_top_right(canvas, "Pre");
+    elements_button_up(canvas, "Pre");
+    elements_button_down(canvas, "Pre");
     elements_button_left(canvas, "Scan-");
     elements_button_center(canvas, "Mute");
     elements_button_right(canvas, "Scan+");
@@ -377,7 +303,6 @@ MyApp* my_app_alloc() {
     Gui* gui = furi_record_open(RECORD_GUI);
     // Initialize the view dispatcher
     app->view_dispatcher = view_dispatcher_alloc();
-    view_dispatcher_enable_queue(app->view_dispatcher);
     view_dispatcher_attach_to_gui(app->view_dispatcher, gui, ViewDispatcherTypeFullscreen);
 
     // Initialize the submenu