hex_viewer_scene_scene_1.c 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include "../hex_viewer.h"
  2. #include "../helpers/hex_viewer_custom_event.h"
  3. #include "../views/hex_viewer_scene_1.h"
  4. void hex_viewer_scene_scene_1_callback(void* context) {
  5. HexViewer* app = (HexViewer*)context;
  6. view_dispatcher_send_custom_event(app->view_dispatcher, SCENE_RENAME_CUSTOM_EVENT);
  7. }
  8. void hex_viewer_scene_scene_1_on_enter(void* context) {
  9. furi_assert(context);
  10. HexViewer* app = context;
  11. TextInput* text_input = app->text_input;
  12. text_input_set_header_text(text_input, "Go to percent (0..100)");
  13. text_input_set_result_callback(
  14. text_input,
  15. hex_viewer_scene_scene_1_callback,
  16. app,
  17. app->percent_buf,
  18. HEX_VIEWER_PERCENT_INPUT,
  19. false);
  20. // ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
  21. // IBUTTON_APP_FOLDER, IBUTTON_APP_FILENAME_EXTENSION, ibutton->key_name);
  22. // text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
  23. view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerSceneScene1);
  24. // if(success) {
  25. // //
  26. // }
  27. // if(success) {
  28. // // Load page to do something with result
  29. // //scene_manager_next_scene(app->scene_manager, HexViewerViewIdMenu);
  30. // //scene_manager_previous_scene(app->scene_manager); // temp for showcase
  31. // scene_manager_search_and_switch_to_previous_scene(
  32. // app->scene_manager, HexViewerViewIdStartscreen);
  33. // } else {
  34. // // This is basically if someone quites the browser
  35. // scene_manager_previous_scene(app->scene_manager);
  36. // }
  37. }
  38. bool hex_viewer_scene_scene_1_on_event(void* context, SceneManagerEvent event) {
  39. HexViewer* app = (HexViewer*)context;
  40. bool consumed = false;
  41. if(event.type == SceneManagerEventTypeCustom) {
  42. if(event.event == SCENE_RENAME_CUSTOM_EVENT) {
  43. float percent = atof(app->percent_buf);
  44. percent = MIN(percent, 100.0);
  45. percent = MAX(percent, 0);
  46. percent = percent / 100;
  47. uint32_t line_count = model->file_size / HEX_VIEWER_BYTES_PER_LINE;
  48. if(model->file_size % HEX_VIEWER_BYTES_PER_LINE != 0) line_count += 1;
  49. uint32_t scrollable_lines = line_count - HEX_VIEWER_LINES_ON_SCREEN;
  50. uint32_t target_line = (uint32_t)(percent * scrollable_lines);
  51. // uint32_t first_line_on_screen = model->file_offset / HEX_VIEWER_BYTES_PER_LINE;
  52. // if(line_count > HEX_VIEWER_LINES_ON_SCREEN) {
  53. // uint8_t width = canvas_width(canvas);
  54. // elements_scrollbar_pos(
  55. // canvas,
  56. // width,
  57. // 0,
  58. // ROW_HEIGHT * HEX_VIEWER_LINES_ON_SCREEN,
  59. // first_line_on_screen, // TODO
  60. // line_count - (HEX_VIEWER_LINES_ON_SCREEN - 1));
  61. // }
  62. uint32_t new_file_offset = target_line * HEX_VIEWER_BYTES_PER_LINE;
  63. if(app->model->file_size > new_file_offset) {
  64. app->model->file_offset = new_file_offset;
  65. if(!hex_viewer_read_file(app)) break; // TODO Do smth
  66. }
  67. scene_manager_search_and_switch_to_previous_scene(
  68. app->scene_manager, HexViewerViewIdStartscreen);
  69. consumed = true;
  70. }
  71. }
  72. return consumed;
  73. }
  74. void hex_viewer_scene_scene_1_on_exit(void* context) {
  75. UNUSED(context);
  76. }