2
2
#include "../helpers/hex_viewer_custom_event.h"
3
3
#include "../views/hex_viewer_scene_1.h"
4
4
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 );
9
8
}
10
9
11
10
void hex_viewer_scene_scene_1_on_enter (void * context ) {
12
11
furi_assert (context );
13
12
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
+ // }
16
46
}
17
47
18
48
bool hex_viewer_scene_scene_1_on_event (void * context , SceneManagerEvent event ) {
19
- HexViewer * app = context ;
49
+ HexViewer * app = ( HexViewer * ) context ;
20
50
bool consumed = false;
21
-
51
+
22
52
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;
41
87
}
42
88
}
43
-
44
89
return consumed ;
45
90
}
46
91
47
92
void hex_viewer_scene_scene_1_on_exit (void * context ) {
48
- HexViewer * app = context ;
49
- UNUSED (app );
50
- }
93
+ UNUSED (context );
94
+ }
0 commit comments