nfc_apdu_runner_scene_card_placement.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include "../nfc_apdu_runner.h"
  2. #include "nfc_apdu_runner_scene.h"
  3. #include <gui/elements.h>
  4. // 卡片放置场景按钮回调
  5. static void nfc_apdu_runner_scene_card_placement_widget_callback(
  6. GuiButtonType result,
  7. InputType type,
  8. void* context) {
  9. NfcApduRunner* app = context;
  10. if(type == InputTypeShort) {
  11. view_dispatcher_send_custom_event(app->view_dispatcher, result);
  12. }
  13. }
  14. // 卡片放置场景进入回调
  15. void nfc_apdu_runner_scene_card_placement_on_enter(void* context) {
  16. NfcApduRunner* app = context;
  17. Widget* widget = app->widget;
  18. widget_reset(widget);
  19. // 添加图标 - 使用内置元素
  20. widget_add_string_element(widget, 64, 5, AlignCenter, AlignTop, FontPrimary, "Place card on");
  21. widget_add_string_element(
  22. widget, 64, 20, AlignCenter, AlignTop, FontPrimary, "the Flipper's back");
  23. // 添加按钮
  24. widget_add_button_element(
  25. widget,
  26. GuiButtonTypeLeft,
  27. "Back",
  28. nfc_apdu_runner_scene_card_placement_widget_callback,
  29. app);
  30. widget_add_button_element(
  31. widget,
  32. GuiButtonTypeRight,
  33. "Run",
  34. nfc_apdu_runner_scene_card_placement_widget_callback,
  35. app);
  36. view_dispatcher_switch_to_view(app->view_dispatcher, NfcApduRunnerViewWidget);
  37. }
  38. // 卡片放置场景事件回调
  39. bool nfc_apdu_runner_scene_card_placement_on_event(void* context, SceneManagerEvent event) {
  40. NfcApduRunner* app = context;
  41. bool consumed = false;
  42. if(event.type == SceneManagerEventTypeCustom) {
  43. if(event.event == GuiButtonTypeLeft) {
  44. // 返回上一个场景
  45. scene_manager_previous_scene(app->scene_manager);
  46. consumed = true;
  47. } else if(event.event == GuiButtonTypeRight) {
  48. // 进入运行场景
  49. scene_manager_next_scene(app->scene_manager, NfcApduRunnerSceneRunning);
  50. consumed = true;
  51. }
  52. }
  53. return consumed;
  54. }
  55. // 卡片放置场景退出回调
  56. void nfc_apdu_runner_scene_card_placement_on_exit(void* context) {
  57. NfcApduRunner* app = context;
  58. widget_reset(app->widget);
  59. }