Skip to content

Commit 4496f44

Browse files
committed
feat: Dirty way of doing go to
1 parent 72465ac commit 4496f44

5 files changed

+80
-44
lines changed

hex_viewer.h

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <notification/notification_messages.h>
1212
#include <gui/view_dispatcher.h>
1313
#include <gui/modules/submenu.h>
14+
#include <gui/modules/text_input.h>
1415
#include <gui/scene_manager.h>
1516
#include <gui/modules/variable_item_list.h>
1617
#include <gui/modules/button_menu.h>
@@ -33,6 +34,7 @@
3334

3435
#define HEX_VIEWER_APP_PATH_FOLDER "/any" // TODO ANY_PATH
3536
#define HEX_VIEWER_APP_EXTENSION "*"
37+
#define HEX_VIEWER_PERCENT_INPUT 16
3638

3739
#define HEX_VIEWER_BYTES_PER_LINE 4u
3840
#define HEX_VIEWER_LINES_ON_SCREEN 4u
@@ -59,6 +61,7 @@ typedef struct {
5961
NotificationApp* notification;
6062
ViewDispatcher* view_dispatcher;
6163
Submenu* submenu;
64+
TextInput* text_input;
6265
SceneManager* scene_manager;
6366
VariableItemList* variable_item_list;
6467
HexViewerStartscreen* hex_viewer_startscreen;
@@ -71,6 +74,7 @@ typedef struct {
7174
uint32_t led;
7275
uint32_t save_settings;
7376
ButtonMenu* button_menu; // Button Menu
77+
char percent_buf[HEX_VIEWER_PERCENT_INPUT];
7478
} HexViewer;
7579

7680
typedef enum {

scenes/hex_viewer_scene_menu.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ void hex_viewer_scene_menu_on_enter(void* context) {
3434

3535
bool hex_viewer_scene_menu_on_event(void* context, SceneManagerEvent event) {
3636
HexViewer* app = context;
37-
UNUSED(app);
37+
3838
if(event.type == SceneManagerEventTypeBack) {
3939
//exit app
40-
// TODO Check Return to main view
4140
// scene_manager_stop(app->scene_manager);
4241
// view_dispatcher_stop(app->view_dispatcher);
4342
scene_manager_previous_scene(app->scene_manager);
@@ -68,6 +67,7 @@ bool hex_viewer_scene_menu_on_event(void* context, SceneManagerEvent event) {
6867
// return true;
6968
}
7069
}
70+
7171
return false;
7272
}
7373

scenes/hex_viewer_scene_scene_1.c

+74-30
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,93 @@
22
#include "../helpers/hex_viewer_custom_event.h"
33
#include "../views/hex_viewer_scene_1.h"
44

5-
void hex_viewer_scene_1_callback(HexViewerCustomEvent event, void* context) {
6-
furi_assert(context);
7-
HexViewer* app = context;
8-
view_dispatcher_send_custom_event(app->view_dispatcher, event);
5+
void hex_viewer_scene_scene_1_callback(void* context) {
6+
HexViewer* app = (HexViewer*)context;
7+
view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_RENAME_CUSTOM_EVENT);
98
}
109

1110
void hex_viewer_scene_scene_1_on_enter(void* context) {
1211
furi_assert(context);
1312
HexViewer* app = context;
14-
hex_viewer_scene_1_set_callback(app->hex_viewer_scene_1, hex_viewer_scene_1_callback, app);
15-
view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdScene1);
13+
14+
TextInput* text_input = app->text_input;
15+
16+
text_input_set_header_text(text_input, "Go to percent (0..100)");
17+
text_input_set_result_callback(
18+
text_input,
19+
hex_viewer_scene_scene_1_callback,
20+
app,
21+
app->percent_buf,
22+
HEX_VIEWER_PERCENT_INPUT,
23+
false);
24+
25+
// ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
26+
// IBUTTON_APP_FOLDER, IBUTTON_APP_FILENAME_EXTENSION, ibutton->key_name);
27+
// text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
28+
29+
view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerSceneScene1);
30+
31+
32+
// if(success) {
33+
// //
34+
// }
35+
36+
// if(success) {
37+
// // Load page to do something with result
38+
// //scene_manager_next_scene(app->scene_manager, HexViewerViewIdMenu);
39+
// //scene_manager_previous_scene(app->scene_manager); // temp for showcase
40+
// scene_manager_search_and_switch_to_previous_scene(
41+
// app->scene_manager, HexViewerViewIdStartscreen);
42+
// } else {
43+
// // This is basically if someone quites the browser
44+
// scene_manager_previous_scene(app->scene_manager);
45+
// }
1646
}
1747

1848
bool hex_viewer_scene_scene_1_on_event(void* context, SceneManagerEvent event) {
19-
HexViewer* app = context;
49+
HexViewer* app = (HexViewer*)context;
2050
bool consumed = false;
21-
51+
2252
if(event.type == SceneManagerEventTypeCustom) {
23-
switch(event.event) {
24-
case HexViewerCustomEventScene1Left:
25-
case HexViewerCustomEventScene1Right:
26-
break;
27-
case HexViewerCustomEventScene1Up:
28-
case HexViewerCustomEventScene1Down:
29-
break;
30-
case HexViewerCustomEventScene1Back:
31-
notification_message(app->notification, &sequence_reset_red);
32-
notification_message(app->notification, &sequence_reset_green);
33-
notification_message(app->notification, &sequence_reset_blue);
34-
if(!scene_manager_search_and_switch_to_previous_scene(
35-
app->scene_manager, HexViewerSceneMenu)) {
36-
scene_manager_stop(app->scene_manager);
37-
view_dispatcher_stop(app->view_dispatcher);
38-
}
39-
consumed = true;
40-
break;
53+
if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
54+
55+
float percent = atof(app->percent_buf);
56+
percent = MIN(percent, 100.0);
57+
percent = MAX(percent, 0);
58+
percent = percent / 100;
59+
60+
uint32_t line_count = model->file_size / HEX_VIEWER_BYTES_PER_LINE;
61+
if(model->file_size % HEX_VIEWER_BYTES_PER_LINE != 0) line_count += 1;
62+
uint32_t scrollable_lines = line_count - HEX_VIEWER_LINES_ON_SCREEN;
63+
uint32_t target_line = (uint32_t)(percent * scrollable_lines);
64+
65+
// uint32_t first_line_on_screen = model->file_offset / HEX_VIEWER_BYTES_PER_LINE;
66+
// if(line_count > HEX_VIEWER_LINES_ON_SCREEN) {
67+
// uint8_t width = canvas_width(canvas);
68+
// elements_scrollbar_pos(
69+
// canvas,
70+
// width,
71+
// 0,
72+
// ROW_HEIGHT * HEX_VIEWER_LINES_ON_SCREEN,
73+
// first_line_on_screen, // TODO
74+
// line_count - (HEX_VIEWER_LINES_ON_SCREEN - 1));
75+
// }
76+
77+
uint32_t new_file_offset = target_line * HEX_VIEWER_BYTES_PER_LINE;
78+
if(app->model->file_size > new_file_offset) {
79+
app->model->file_offset = new_file_offset;
80+
if(!hex_viewer_read_file(app)) break; // TODO Do smth
81+
}
82+
83+
scene_manager_search_and_switch_to_previous_scene(
84+
app->scene_manager, HexViewerViewIdStartscreen);
85+
86+
consumed = true;
4187
}
4288
}
43-
4489
return consumed;
4590
}
4691

4792
void hex_viewer_scene_scene_1_on_exit(void* context) {
48-
HexViewer* app = context;
49-
UNUSED(app);
50-
}
93+
UNUSED(context);
94+
}

scenes/hex_viewer_scene_scene_4.c

-11
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,6 @@
33
void hex_viewer_scene_scene_4_on_enter(void* context) {
44
furi_assert(context);
55
HexViewer* app = context;
6-
// DialogsFileBrowserOptions browser_options;
7-
// This will filter the browser to only show one file type and also add an icon
8-
// dialog_file_browser_set_basic_options(&browser_options, SUBGHZ_APP_EXTENSION, &I_sub1_10px);
9-
// Get the Folder you want to browse
10-
// browser_options.base_path = SUBGHZ_APP_FOLDER;
11-
// FuriString* path;
12-
// path = furi_string_alloc();
13-
// furi_string_set(path, SUBGHZ_APP_FOLDER);
14-
// bool success = dialog_file_browser_show(
15-
// app->dialogs, app->file_path, path, &browser_options);
16-
// furi_string_free(path);
176

187
FuriString* initial_path;
198
initial_path = furi_string_alloc();

views/hex_viewer_startscreen.c

-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ void hex_viewer_startscreen_enter(void* context) {
215215
instance->view,
216216
HexViewerStartscreenModel * model,
217217
{
218-
//hex_viewer_startscreen_model_init(model);
219218
update_local_model_from_app(instance->context, model);
220219
},
221220
true);

0 commit comments

Comments
 (0)