Jelajahi Sumber

feat: Dirty way of doing go to

Roman Shchekin 2 tahun lalu
induk
melakukan
4496f44993

+ 4 - 0
hex_viewer.h

@@ -11,6 +11,7 @@
 #include <notification/notification_messages.h>
 #include <gui/view_dispatcher.h>
 #include <gui/modules/submenu.h>
+#include <gui/modules/text_input.h>
 #include <gui/scene_manager.h>
 #include <gui/modules/variable_item_list.h>
 #include <gui/modules/button_menu.h>
@@ -33,6 +34,7 @@
 
 #define HEX_VIEWER_APP_PATH_FOLDER "/any" // TODO ANY_PATH
 #define HEX_VIEWER_APP_EXTENSION "*"
+#define HEX_VIEWER_PERCENT_INPUT 16
 
 #define HEX_VIEWER_BYTES_PER_LINE 4u
 #define HEX_VIEWER_LINES_ON_SCREEN 4u
@@ -59,6 +61,7 @@ typedef struct {
     NotificationApp* notification;
     ViewDispatcher* view_dispatcher;
     Submenu* submenu;
+    TextInput* text_input;
     SceneManager* scene_manager;
     VariableItemList* variable_item_list;
     HexViewerStartscreen* hex_viewer_startscreen;
@@ -71,6 +74,7 @@ typedef struct {
     uint32_t led;
     uint32_t save_settings;
     ButtonMenu* button_menu; // Button Menu
+    char percent_buf[HEX_VIEWER_PERCENT_INPUT];
 } HexViewer;
 
 typedef enum {

+ 2 - 2
scenes/hex_viewer_scene_menu.c

@@ -34,10 +34,9 @@ void hex_viewer_scene_menu_on_enter(void* context) {
 
 bool hex_viewer_scene_menu_on_event(void* context, SceneManagerEvent event) {
     HexViewer* app = context;
-    UNUSED(app);
+
     if(event.type == SceneManagerEventTypeBack) {
         //exit app
-        // TODO Check Return to main view
         // scene_manager_stop(app->scene_manager);
         // view_dispatcher_stop(app->view_dispatcher);
         scene_manager_previous_scene(app->scene_manager);
@@ -68,6 +67,7 @@ bool hex_viewer_scene_menu_on_event(void* context, SceneManagerEvent event) {
             //     return true;
         }
     }
+
     return false;
 }
 

+ 74 - 30
scenes/hex_viewer_scene_scene_1.c

@@ -2,49 +2,93 @@
 #include "../helpers/hex_viewer_custom_event.h"
 #include "../views/hex_viewer_scene_1.h"
 
-void hex_viewer_scene_1_callback(HexViewerCustomEvent event, void* context) {
-    furi_assert(context);
-    HexViewer* app = context;
-    view_dispatcher_send_custom_event(app->view_dispatcher, event);
+void hex_viewer_scene_scene_1_callback(void* context) {
+    HexViewer* app = (HexViewer*)context;
+    view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_RENAME_CUSTOM_EVENT);
 }
 
 void hex_viewer_scene_scene_1_on_enter(void* context) {
     furi_assert(context);
     HexViewer* app = context;
-    hex_viewer_scene_1_set_callback(app->hex_viewer_scene_1, hex_viewer_scene_1_callback, app);
-    view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdScene1);
+    
+    TextInput* text_input = app->text_input;
+
+    text_input_set_header_text(text_input, "Go to percent (0..100)");
+    text_input_set_result_callback(
+        text_input,
+        hex_viewer_scene_scene_1_callback,
+        app,
+        app->percent_buf,
+        HEX_VIEWER_PERCENT_INPUT,
+        false);
+
+    // ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
+    //     IBUTTON_APP_FOLDER, IBUTTON_APP_FILENAME_EXTENSION, ibutton->key_name);
+    // text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerSceneScene1);
+
+
+    // if(success) {
+    //     // 
+    // }
+
+    // if(success) {
+    //     // Load page to do something with result
+    //     //scene_manager_next_scene(app->scene_manager, HexViewerViewIdMenu);
+    //     //scene_manager_previous_scene(app->scene_manager); // temp for showcase
+    //     scene_manager_search_and_switch_to_previous_scene(
+    //         app->scene_manager, HexViewerViewIdStartscreen);
+    // } else {
+    //     // This is basically if someone quites the browser
+    //     scene_manager_previous_scene(app->scene_manager);
+    // }
 }
 
 bool hex_viewer_scene_scene_1_on_event(void* context, SceneManagerEvent event) {
-    HexViewer* app = context;
+    HexViewer* app = (HexViewer*)context;
     bool consumed = false;
-    
+
     if(event.type == SceneManagerEventTypeCustom) {
-        switch(event.event) {
-            case HexViewerCustomEventScene1Left:
-            case HexViewerCustomEventScene1Right:
-                break;
-            case HexViewerCustomEventScene1Up:
-            case HexViewerCustomEventScene1Down:
-                break;
-            case HexViewerCustomEventScene1Back:
-                notification_message(app->notification, &sequence_reset_red);
-                notification_message(app->notification, &sequence_reset_green);
-                notification_message(app->notification, &sequence_reset_blue);
-                if(!scene_manager_search_and_switch_to_previous_scene(
-                    app->scene_manager, HexViewerSceneMenu)) {
-                        scene_manager_stop(app->scene_manager);
-                        view_dispatcher_stop(app->view_dispatcher);
-                    }
-                consumed = true;
-                break;
+        if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
+
+            float percent = atof(app->percent_buf);
+            percent = MIN(percent, 100.0);
+            percent = MAX(percent, 0);
+            percent = percent / 100;
+
+            uint32_t line_count = model->file_size / HEX_VIEWER_BYTES_PER_LINE;
+            if(model->file_size % HEX_VIEWER_BYTES_PER_LINE != 0) line_count += 1;
+            uint32_t scrollable_lines = line_count - HEX_VIEWER_LINES_ON_SCREEN;
+            uint32_t target_line = (uint32_t)(percent * scrollable_lines);
+
+            // uint32_t first_line_on_screen = model->file_offset / HEX_VIEWER_BYTES_PER_LINE;
+            // if(line_count > HEX_VIEWER_LINES_ON_SCREEN) {
+            //     uint8_t width = canvas_width(canvas);
+            //     elements_scrollbar_pos(
+            //         canvas,
+            //         width,
+            //         0,
+            //         ROW_HEIGHT * HEX_VIEWER_LINES_ON_SCREEN,
+            //         first_line_on_screen, // TODO
+            //         line_count - (HEX_VIEWER_LINES_ON_SCREEN - 1));
+            // }
+
+            uint32_t new_file_offset = target_line * HEX_VIEWER_BYTES_PER_LINE;
+            if(app->model->file_size > new_file_offset) {
+                app->model->file_offset = new_file_offset;
+                if(!hex_viewer_read_file(app)) break; // TODO Do smth
+            }
+
+            scene_manager_search_and_switch_to_previous_scene(
+                app->scene_manager, HexViewerViewIdStartscreen);
+
+            consumed = true;
         }
     }
-    
     return consumed;
 }
 
 void hex_viewer_scene_scene_1_on_exit(void* context) {
-    HexViewer* app = context;
-    UNUSED(app);
-}
+    UNUSED(context);
+}

+ 0 - 11
scenes/hex_viewer_scene_scene_4.c

@@ -3,17 +3,6 @@
 void hex_viewer_scene_scene_4_on_enter(void* context) {
     furi_assert(context);
     HexViewer* app = context;
-    // DialogsFileBrowserOptions browser_options;
-    // This will filter the browser to only show one file type and also add an icon
-    // dialog_file_browser_set_basic_options(&browser_options, SUBGHZ_APP_EXTENSION, &I_sub1_10px);
-    // Get the Folder you want to browse
-    // browser_options.base_path = SUBGHZ_APP_FOLDER;
-    // FuriString* path;
-    // path = furi_string_alloc();
-    // furi_string_set(path, SUBGHZ_APP_FOLDER);
-    // bool success = dialog_file_browser_show(
-    //     app->dialogs, app->file_path, path, &browser_options);
-    // furi_string_free(path);
 
     FuriString* initial_path;
     initial_path = furi_string_alloc();

+ 0 - 1
views/hex_viewer_startscreen.c

@@ -215,7 +215,6 @@ void hex_viewer_startscreen_enter(void* context) {
         instance->view,
         HexViewerStartscreenModel * model,
         {
-            //hex_viewer_startscreen_model_init(model);
             update_local_model_from_app(instance->context, model);
         },
         true);