lfrfid_app_scene_exit_confirm.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "lfrfid_app_scene_exit_confirm.h"
  2. #include "../view/elements/button_element.h"
  3. #include "../view/elements/icon_element.h"
  4. #include "../view/elements/string_element.h"
  5. void LfRfidAppSceneExitConfirm::on_enter(LfRfidApp* app, bool need_restore) {
  6. auto container = app->view_controller.get<ContainerVM>();
  7. auto button = container->add<ButtonElement>();
  8. button->set_type(ButtonElement::Type::Left, "Exit");
  9. button->set_callback(app, LfRfidAppSceneExitConfirm::exit_callback);
  10. button = container->add<ButtonElement>();
  11. button->set_type(ButtonElement::Type::Right, "Stay");
  12. button->set_callback(app, LfRfidAppSceneExitConfirm::stay_callback);
  13. auto line_1 = container->add<StringElement>();
  14. auto line_2 = container->add<StringElement>();
  15. line_1->set_text("Exit to RFID menu?", 64, 19, 128 - 2, AlignCenter, AlignBottom, FontPrimary);
  16. line_2->set_text(
  17. "All unsaved data will be lost", 64, 29, 0, AlignCenter, AlignBottom, FontSecondary);
  18. app->view_controller.switch_to<ContainerVM>();
  19. }
  20. bool LfRfidAppSceneExitConfirm::on_event(LfRfidApp* app, LfRfidApp::Event* event) {
  21. bool consumed = false;
  22. if(event->type == LfRfidApp::EventType::Next) {
  23. app->scene_controller.search_and_switch_to_previous_scene({LfRfidApp::SceneType::Start});
  24. consumed = true;
  25. } else if(event->type == LfRfidApp::EventType::Stay) {
  26. app->scene_controller.switch_to_previous_scene();
  27. consumed = true;
  28. } else if(event->type == LfRfidApp::EventType::Back) {
  29. consumed = true;
  30. }
  31. return consumed;
  32. }
  33. void LfRfidAppSceneExitConfirm::on_exit(LfRfidApp* app) {
  34. app->view_controller.get<ContainerVM>()->clean();
  35. }
  36. void LfRfidAppSceneExitConfirm::exit_callback(void* context) {
  37. LfRfidApp* app = static_cast<LfRfidApp*>(context);
  38. LfRfidApp::Event event;
  39. event.type = LfRfidApp::EventType::Next;
  40. app->view_controller.send_event(&event);
  41. }
  42. void LfRfidAppSceneExitConfirm::stay_callback(void* context) {
  43. LfRfidApp* app = static_cast<LfRfidApp*>(context);
  44. LfRfidApp::Event event;
  45. event.type = LfRfidApp::EventType::Stay;
  46. app->view_controller.send_event(&event);
  47. }