MainMenu_view.c 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Unitemp - Universal temperature reader
  3. Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "UnitempViews.h"
  16. #include <gui/modules/variable_item_list.h>
  17. //Текущий вид
  18. static View* view;
  19. //Список
  20. static VariableItemList* variable_item_list;
  21. #define VIEW_ID UnitempViewMainMenu
  22. /**
  23. * @brief Функция обработки нажатия кнопки "Назад"
  24. *
  25. * @param context Указатель на данные приложения
  26. * @return ID вида в который нужно переключиться
  27. */
  28. static uint32_t _exit_callback(void* context) {
  29. UNUSED(context);
  30. //Возврат в общий вид
  31. return UnitempViewGeneral;
  32. }
  33. /**
  34. * @brief Функция обработки нажатия средней кнопки
  35. *
  36. * @param context Указатель на данные приложения
  37. * @param index На каком элементе списка была нажата кнопка
  38. */
  39. static void _enter_callback(void* context, uint32_t index) {
  40. UNUSED(context);
  41. if(index == 0) { //Add new sensor
  42. unitemp_SensorsList_switch();
  43. }
  44. if(index == 1) { //Settings
  45. unitemp_Settings_switch();
  46. }
  47. if(index == 2) {
  48. unitemp_widget_help_switch();
  49. }
  50. if(index == 3) {
  51. unitemp_widget_about_switch();
  52. }
  53. }
  54. /**
  55. * @brief Создание списка действий с указанным датчиком
  56. */
  57. void unitemp_MainMenu_alloc(void) {
  58. variable_item_list = variable_item_list_alloc();
  59. //Сброс всех элементов меню
  60. variable_item_list_reset(variable_item_list);
  61. variable_item_list_add(variable_item_list, "Add new sensor", 1, NULL, NULL);
  62. variable_item_list_add(variable_item_list, "Settings", 1, NULL, NULL);
  63. variable_item_list_add(variable_item_list, "Help", 1, NULL, NULL);
  64. variable_item_list_add(variable_item_list, "About", 1, NULL, NULL);
  65. //Добавление колбека на нажатие средней кнопки
  66. variable_item_list_set_enter_callback(variable_item_list, _enter_callback, app);
  67. //Создание вида из списка
  68. view = variable_item_list_get_view(variable_item_list);
  69. //Добавление колбека на нажатие кнопки "Назад"
  70. view_set_previous_callback(view, _exit_callback);
  71. //Добавление вида в диспетчер
  72. view_dispatcher_add_view(app->view_dispatcher, VIEW_ID, view);
  73. }
  74. void unitemp_MainMenu_switch(void) {
  75. //Обнуление последнего выбранного пункта
  76. variable_item_list_set_selected_item(variable_item_list, 0);
  77. //Переключение в вид
  78. view_dispatcher_switch_to_view(app->view_dispatcher, VIEW_ID);
  79. }
  80. void unitemp_MainMenu_free(void) {
  81. //Удаление вида после обработки
  82. view_dispatcher_remove_view(app->view_dispatcher, VIEW_ID);
  83. //Очистка списка элементов
  84. variable_item_list_free(variable_item_list);
  85. }