SensorNameEdit_view.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/text_input.h>
  17. //Окно ввода текста
  18. static TextInput* text_input;
  19. //Текущий редактируемый датчик
  20. static Sensor* editable_sensor;
  21. #define VIEW_ID UnitempViewSensorNameEdit
  22. static void _sensor_name_changed_callback(void* context) {
  23. UNUSED(context);
  24. unitemp_SensorEdit_switch(editable_sensor);
  25. }
  26. void unitemp_SensorNameEdit_alloc(void) {
  27. text_input = text_input_alloc();
  28. view_dispatcher_add_view(app->view_dispatcher, VIEW_ID, text_input_get_view(text_input));
  29. text_input_set_header_text(text_input, "Sensor name");
  30. }
  31. void unitemp_SensorNameEdit_switch(Sensor* sensor) {
  32. editable_sensor = sensor;
  33. text_input_set_result_callback(
  34. text_input, _sensor_name_changed_callback, app, sensor->name, 11, true);
  35. view_dispatcher_switch_to_view(app->view_dispatcher, VIEW_ID);
  36. }
  37. void unitemp_SensorNameEdit_free(void) {
  38. view_dispatcher_remove_view(app->view_dispatcher, VIEW_ID);
  39. text_input_free(text_input);
  40. }