uart_text_input.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. // from https://github.com/xMasterX/all-the-plugins/blob/dev/base_pack/uart_terminal/uart_text_input.c
  2. // all credits to xMasterX for the code
  3. #include "uart_text_input.h"
  4. #include <gui/elements.h>
  5. #include "flip_world_icons.h"
  6. #include <furi.h>
  7. // added by Derek Jamison to lower memory usage
  8. #undef FURI_LOG_E
  9. #define FURI_LOG_E(tag, msg, ...)
  10. #undef FURI_LOG_I
  11. #define FURI_LOG_I(tag, msg, ...)
  12. //
  13. struct UART_TextInput
  14. {
  15. View *view;
  16. FuriTimer *timer;
  17. };
  18. typedef struct
  19. {
  20. const char text;
  21. const uint8_t x;
  22. const uint8_t y;
  23. } UART_TextInputKey;
  24. typedef struct
  25. {
  26. const char *header;
  27. char *text_buffer;
  28. size_t text_buffer_size;
  29. bool clear_default_text;
  30. UART_TextInputCallback callback;
  31. void *callback_context;
  32. uint8_t selected_row;
  33. uint8_t selected_column;
  34. UART_TextInputValidatorCallback validator_callback;
  35. void *validator_callback_context;
  36. FuriString *validator_text;
  37. bool valadator_message_visible;
  38. } UART_TextInputModel;
  39. static const uint8_t keyboard_origin_x = 1;
  40. static const uint8_t keyboard_origin_y = 29;
  41. static const uint8_t keyboard_row_count = 4;
  42. #define mode_AT "Send AT command to UART"
  43. #define ENTER_KEY '\r'
  44. #define BACKSPACE_KEY '\b'
  45. static const UART_TextInputKey keyboard_keys_row_1[] = {
  46. {'{', 1, 0},
  47. {'(', 9, 0},
  48. {'[', 17, 0},
  49. {'|', 25, 0},
  50. {'@', 33, 0},
  51. {'&', 41, 0},
  52. {'#', 49, 0},
  53. {';', 57, 0},
  54. {'^', 65, 0},
  55. {'*', 73, 0},
  56. {'`', 81, 0},
  57. {'"', 89, 0},
  58. {'~', 97, 0},
  59. {'\'', 105, 0},
  60. {'.', 113, 0},
  61. {'/', 120, 0},
  62. };
  63. static const UART_TextInputKey keyboard_keys_row_2[] = {
  64. {'q', 1, 10},
  65. {'w', 9, 10},
  66. {'e', 17, 10},
  67. {'r', 25, 10},
  68. {'t', 33, 10},
  69. {'y', 41, 10},
  70. {'u', 49, 10},
  71. {'i', 57, 10},
  72. {'o', 65, 10},
  73. {'p', 73, 10},
  74. {'0', 81, 10},
  75. {'1', 89, 10},
  76. {'2', 97, 10},
  77. {'3', 105, 10},
  78. {'=', 113, 10},
  79. {'-', 120, 10},
  80. };
  81. static const UART_TextInputKey keyboard_keys_row_3[] = {
  82. {'a', 1, 21},
  83. {'s', 9, 21},
  84. {'d', 18, 21},
  85. {'f', 25, 21},
  86. {'g', 33, 21},
  87. {'h', 41, 21},
  88. {'j', 49, 21},
  89. {'k', 57, 21},
  90. {'l', 65, 21},
  91. {BACKSPACE_KEY, 72, 13},
  92. {'4', 89, 21},
  93. {'5', 97, 21},
  94. {'6', 105, 21},
  95. {'$', 113, 21},
  96. {'%', 120, 21},
  97. };
  98. static const UART_TextInputKey keyboard_keys_row_4[] = {
  99. {'z', 1, 33},
  100. {'x', 9, 33},
  101. {'c', 18, 33},
  102. {'v', 25, 33},
  103. {'b', 33, 33},
  104. {'n', 41, 33},
  105. {'m', 49, 33},
  106. {'_', 57, 33},
  107. {ENTER_KEY, 64, 24},
  108. {'7', 89, 33},
  109. {'8', 97, 33},
  110. {'9', 105, 33},
  111. {'!', 113, 33},
  112. {'+', 120, 33},
  113. };
  114. static uint8_t get_row_size(uint8_t row_index)
  115. {
  116. uint8_t row_size = 0;
  117. switch (row_index + 1)
  118. {
  119. case 1:
  120. row_size = sizeof(keyboard_keys_row_1) / sizeof(UART_TextInputKey);
  121. break;
  122. case 2:
  123. row_size = sizeof(keyboard_keys_row_2) / sizeof(UART_TextInputKey);
  124. break;
  125. case 3:
  126. row_size = sizeof(keyboard_keys_row_3) / sizeof(UART_TextInputKey);
  127. break;
  128. case 4:
  129. row_size = sizeof(keyboard_keys_row_4) / sizeof(UART_TextInputKey);
  130. break;
  131. }
  132. return row_size;
  133. }
  134. static const UART_TextInputKey *get_row(uint8_t row_index)
  135. {
  136. const UART_TextInputKey *row = NULL;
  137. switch (row_index + 1)
  138. {
  139. case 1:
  140. row = keyboard_keys_row_1;
  141. break;
  142. case 2:
  143. row = keyboard_keys_row_2;
  144. break;
  145. case 3:
  146. row = keyboard_keys_row_3;
  147. break;
  148. case 4:
  149. row = keyboard_keys_row_4;
  150. break;
  151. }
  152. return row;
  153. }
  154. static char get_selected_char(UART_TextInputModel *model)
  155. {
  156. return get_row(model->selected_row)[model->selected_column].text;
  157. }
  158. static bool char_is_lowercase(char letter)
  159. {
  160. return (letter >= 0x61 && letter <= 0x7A);
  161. }
  162. static bool char_is_uppercase(char letter)
  163. {
  164. return (letter >= 0x41 && letter <= 0x5A);
  165. }
  166. static char char_to_lowercase(const char letter)
  167. {
  168. switch (letter)
  169. {
  170. case ' ':
  171. return 0x5f;
  172. break;
  173. case ')':
  174. return 0x28;
  175. break;
  176. case '}':
  177. return 0x7b;
  178. break;
  179. case ']':
  180. return 0x5b;
  181. break;
  182. case '\\':
  183. return 0x2f;
  184. break;
  185. case ':':
  186. return 0x3b;
  187. break;
  188. case ',':
  189. return 0x2e;
  190. break;
  191. case '?':
  192. return 0x21;
  193. break;
  194. case '>':
  195. return 0x3c;
  196. break;
  197. }
  198. if (char_is_uppercase(letter))
  199. {
  200. return (letter + 0x20);
  201. }
  202. else
  203. {
  204. return letter;
  205. }
  206. }
  207. static char char_to_uppercase(const char letter)
  208. {
  209. switch (letter)
  210. {
  211. case '_':
  212. return 0x20;
  213. break;
  214. case '(':
  215. return 0x29;
  216. break;
  217. case '{':
  218. return 0x7d;
  219. break;
  220. case '[':
  221. return 0x5d;
  222. break;
  223. case '/':
  224. return 0x5c;
  225. break;
  226. case ';':
  227. return 0x3a;
  228. break;
  229. case '.':
  230. return 0x2c;
  231. break;
  232. case '!':
  233. return 0x3f;
  234. break;
  235. case '<':
  236. return 0x3e;
  237. break;
  238. }
  239. if (char_is_lowercase(letter))
  240. {
  241. return (letter - 0x20);
  242. }
  243. else
  244. {
  245. return letter;
  246. }
  247. }
  248. static void uart_text_input_backspace_cb(UART_TextInputModel *model)
  249. {
  250. uint8_t text_length = model->clear_default_text ? 1 : strlen(model->text_buffer);
  251. if (text_length > 0)
  252. {
  253. model->text_buffer[text_length - 1] = 0;
  254. }
  255. }
  256. static void uart_text_input_view_draw_callback(Canvas *canvas, void *_model)
  257. {
  258. UART_TextInputModel *model = _model;
  259. // uint8_t text_length = model->text_buffer ? strlen(model->text_buffer) : 0;
  260. uint8_t needed_string_width = canvas_width(canvas) - 8;
  261. uint8_t start_pos = 4;
  262. const char *text = model->text_buffer;
  263. canvas_clear(canvas);
  264. canvas_set_color(canvas, ColorBlack);
  265. canvas_draw_str(canvas, 2, 7, model->header);
  266. elements_slightly_rounded_frame(canvas, 1, 8, 126, 12);
  267. if (canvas_string_width(canvas, text) > needed_string_width)
  268. {
  269. canvas_draw_str(canvas, start_pos, 17, "...");
  270. start_pos += 6;
  271. needed_string_width -= 8;
  272. }
  273. while (text != 0 && canvas_string_width(canvas, text) > needed_string_width)
  274. {
  275. text++;
  276. }
  277. if (model->clear_default_text)
  278. {
  279. elements_slightly_rounded_box(
  280. canvas, start_pos - 1, 14, canvas_string_width(canvas, text) + 2, 10);
  281. canvas_set_color(canvas, ColorWhite);
  282. }
  283. else
  284. {
  285. canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 1, 18, "|");
  286. canvas_draw_str(canvas, start_pos + canvas_string_width(canvas, text) + 2, 18, "|");
  287. }
  288. canvas_draw_str(canvas, start_pos, 17, text);
  289. canvas_set_font(canvas, FontKeyboard);
  290. for (uint8_t row = 0; row <= keyboard_row_count; row++)
  291. {
  292. const uint8_t column_count = get_row_size(row);
  293. const UART_TextInputKey *keys = get_row(row);
  294. for (size_t column = 0; column < column_count; column++)
  295. {
  296. if (keys[column].text == ENTER_KEY)
  297. {
  298. canvas_set_color(canvas, ColorBlack);
  299. if (model->selected_row == row && model->selected_column == column)
  300. {
  301. canvas_draw_icon(
  302. canvas,
  303. keyboard_origin_x + keys[column].x,
  304. keyboard_origin_y + keys[column].y,
  305. &I_KeySaveSelected_24x11);
  306. }
  307. else
  308. {
  309. canvas_draw_icon(
  310. canvas,
  311. keyboard_origin_x + keys[column].x,
  312. keyboard_origin_y + keys[column].y,
  313. &I_KeySave_24x11);
  314. }
  315. }
  316. else if (keys[column].text == BACKSPACE_KEY)
  317. {
  318. canvas_set_color(canvas, ColorBlack);
  319. if (model->selected_row == row && model->selected_column == column)
  320. {
  321. canvas_draw_icon(
  322. canvas,
  323. keyboard_origin_x + keys[column].x,
  324. keyboard_origin_y + keys[column].y,
  325. &I_KeyBackspaceSelected_16x9);
  326. }
  327. else
  328. {
  329. canvas_draw_icon(
  330. canvas,
  331. keyboard_origin_x + keys[column].x,
  332. keyboard_origin_y + keys[column].y,
  333. &I_KeyBackspace_16x9);
  334. }
  335. }
  336. else
  337. {
  338. if (model->selected_row == row && model->selected_column == column)
  339. {
  340. canvas_set_color(canvas, ColorBlack);
  341. canvas_draw_box(
  342. canvas,
  343. keyboard_origin_x + keys[column].x - 1,
  344. keyboard_origin_y + keys[column].y - 8,
  345. 7,
  346. 10);
  347. canvas_set_color(canvas, ColorWhite);
  348. }
  349. else
  350. {
  351. canvas_set_color(canvas, ColorBlack);
  352. }
  353. if (0 == strcmp(model->header, mode_AT))
  354. {
  355. canvas_draw_glyph(
  356. canvas,
  357. keyboard_origin_x + keys[column].x,
  358. keyboard_origin_y + keys[column].y,
  359. char_to_uppercase(keys[column].text));
  360. }
  361. else
  362. {
  363. canvas_draw_glyph(
  364. canvas,
  365. keyboard_origin_x + keys[column].x,
  366. keyboard_origin_y + keys[column].y,
  367. keys[column].text);
  368. }
  369. }
  370. }
  371. }
  372. if (model->valadator_message_visible)
  373. {
  374. canvas_set_font(canvas, FontSecondary);
  375. canvas_set_color(canvas, ColorWhite);
  376. canvas_draw_box(canvas, 8, 10, 110, 48);
  377. canvas_set_color(canvas, ColorBlack);
  378. canvas_draw_icon(canvas, 10, 14, &I_WarningDolphin_45x42);
  379. canvas_draw_rframe(canvas, 8, 8, 112, 50, 3);
  380. canvas_draw_rframe(canvas, 9, 9, 110, 48, 2);
  381. elements_multiline_text(canvas, 62, 20, furi_string_get_cstr(model->validator_text));
  382. canvas_set_font(canvas, FontKeyboard);
  383. }
  384. }
  385. static void
  386. uart_text_input_handle_up(UART_TextInput *uart_text_input, UART_TextInputModel *model)
  387. {
  388. UNUSED(uart_text_input);
  389. if (model->selected_row > 0)
  390. {
  391. model->selected_row--;
  392. if (model->selected_column > get_row_size(model->selected_row) - 6)
  393. {
  394. model->selected_column = model->selected_column + 1;
  395. }
  396. }
  397. }
  398. static void
  399. uart_text_input_handle_down(UART_TextInput *uart_text_input, UART_TextInputModel *model)
  400. {
  401. UNUSED(uart_text_input);
  402. if (model->selected_row < keyboard_row_count - 1)
  403. {
  404. model->selected_row++;
  405. if (model->selected_column > get_row_size(model->selected_row) - 4)
  406. {
  407. model->selected_column = model->selected_column - 1;
  408. }
  409. }
  410. }
  411. static void
  412. uart_text_input_handle_left(UART_TextInput *uart_text_input, UART_TextInputModel *model)
  413. {
  414. UNUSED(uart_text_input);
  415. if (model->selected_column > 0)
  416. {
  417. model->selected_column--;
  418. }
  419. else
  420. {
  421. model->selected_column = get_row_size(model->selected_row) - 1;
  422. }
  423. }
  424. static void
  425. uart_text_input_handle_right(UART_TextInput *uart_text_input, UART_TextInputModel *model)
  426. {
  427. UNUSED(uart_text_input);
  428. if (model->selected_column < get_row_size(model->selected_row) - 1)
  429. {
  430. model->selected_column++;
  431. }
  432. else
  433. {
  434. model->selected_column = 0;
  435. }
  436. }
  437. static void uart_text_input_handle_ok(
  438. UART_TextInput *uart_text_input,
  439. UART_TextInputModel *model,
  440. bool shift)
  441. {
  442. char selected = get_selected_char(model);
  443. uint8_t text_length = strlen(model->text_buffer);
  444. if (0 == strcmp(model->header, mode_AT))
  445. {
  446. selected = char_to_uppercase(selected);
  447. }
  448. if (shift)
  449. {
  450. if (0 == strcmp(model->header, mode_AT))
  451. {
  452. selected = char_to_lowercase(selected);
  453. }
  454. else
  455. {
  456. selected = char_to_uppercase(selected);
  457. }
  458. }
  459. if (selected == ENTER_KEY)
  460. {
  461. if (model->validator_callback &&
  462. (!model->validator_callback(
  463. model->text_buffer, model->validator_text, model->validator_callback_context)))
  464. {
  465. model->valadator_message_visible = true;
  466. furi_timer_start(uart_text_input->timer, furi_kernel_get_tick_frequency() * 4);
  467. }
  468. else if (model->callback != 0 && text_length > 0)
  469. {
  470. model->callback(model->callback_context);
  471. }
  472. }
  473. else if (selected == BACKSPACE_KEY)
  474. {
  475. uart_text_input_backspace_cb(model);
  476. }
  477. else
  478. {
  479. if (model->clear_default_text)
  480. {
  481. text_length = 0;
  482. }
  483. if (text_length < (model->text_buffer_size - 1))
  484. {
  485. model->text_buffer[text_length] = selected;
  486. model->text_buffer[text_length + 1] = 0;
  487. }
  488. }
  489. model->clear_default_text = false;
  490. }
  491. static bool uart_text_input_view_input_callback(InputEvent *event, void *context)
  492. {
  493. UART_TextInput *uart_text_input = context;
  494. furi_assert(uart_text_input);
  495. bool consumed = false;
  496. // Acquire model
  497. UART_TextInputModel *model = view_get_model(uart_text_input->view);
  498. if ((!(event->type == InputTypePress) && !(event->type == InputTypeRelease)) &&
  499. model->valadator_message_visible)
  500. {
  501. model->valadator_message_visible = false;
  502. consumed = true;
  503. }
  504. else if (event->type == InputTypeShort)
  505. {
  506. consumed = true;
  507. switch (event->key)
  508. {
  509. case InputKeyUp:
  510. uart_text_input_handle_up(uart_text_input, model);
  511. break;
  512. case InputKeyDown:
  513. uart_text_input_handle_down(uart_text_input, model);
  514. break;
  515. case InputKeyLeft:
  516. uart_text_input_handle_left(uart_text_input, model);
  517. break;
  518. case InputKeyRight:
  519. uart_text_input_handle_right(uart_text_input, model);
  520. break;
  521. case InputKeyOk:
  522. uart_text_input_handle_ok(uart_text_input, model, false);
  523. break;
  524. default:
  525. consumed = false;
  526. break;
  527. }
  528. }
  529. else if (event->type == InputTypeLong)
  530. {
  531. consumed = true;
  532. switch (event->key)
  533. {
  534. case InputKeyUp:
  535. uart_text_input_handle_up(uart_text_input, model);
  536. break;
  537. case InputKeyDown:
  538. uart_text_input_handle_down(uart_text_input, model);
  539. break;
  540. case InputKeyLeft:
  541. uart_text_input_handle_left(uart_text_input, model);
  542. break;
  543. case InputKeyRight:
  544. uart_text_input_handle_right(uart_text_input, model);
  545. break;
  546. case InputKeyOk:
  547. uart_text_input_handle_ok(uart_text_input, model, true);
  548. break;
  549. case InputKeyBack:
  550. uart_text_input_backspace_cb(model);
  551. break;
  552. default:
  553. consumed = false;
  554. break;
  555. }
  556. }
  557. else if (event->type == InputTypeRepeat)
  558. {
  559. consumed = true;
  560. switch (event->key)
  561. {
  562. case InputKeyUp:
  563. uart_text_input_handle_up(uart_text_input, model);
  564. break;
  565. case InputKeyDown:
  566. uart_text_input_handle_down(uart_text_input, model);
  567. break;
  568. case InputKeyLeft:
  569. uart_text_input_handle_left(uart_text_input, model);
  570. break;
  571. case InputKeyRight:
  572. uart_text_input_handle_right(uart_text_input, model);
  573. break;
  574. case InputKeyBack:
  575. uart_text_input_backspace_cb(model);
  576. break;
  577. default:
  578. consumed = false;
  579. break;
  580. }
  581. }
  582. // Commit model
  583. view_commit_model(uart_text_input->view, consumed);
  584. return consumed;
  585. }
  586. void uart_text_input_timer_callback(void *context)
  587. {
  588. furi_assert(context);
  589. UART_TextInput *uart_text_input = context;
  590. with_view_model(
  591. uart_text_input->view,
  592. UART_TextInputModel * model,
  593. { model->valadator_message_visible = false; },
  594. true);
  595. }
  596. UART_TextInput *uart_text_input_alloc()
  597. {
  598. UART_TextInput *uart_text_input = malloc(sizeof(UART_TextInput));
  599. uart_text_input->view = view_alloc();
  600. view_set_context(uart_text_input->view, uart_text_input);
  601. view_allocate_model(uart_text_input->view, ViewModelTypeLocking, sizeof(UART_TextInputModel));
  602. view_set_draw_callback(uart_text_input->view, uart_text_input_view_draw_callback);
  603. view_set_input_callback(uart_text_input->view, uart_text_input_view_input_callback);
  604. uart_text_input->timer =
  605. furi_timer_alloc(uart_text_input_timer_callback, FuriTimerTypeOnce, uart_text_input);
  606. with_view_model(
  607. uart_text_input->view,
  608. UART_TextInputModel * model,
  609. { model->validator_text = furi_string_alloc(); },
  610. false);
  611. uart_text_input_reset(uart_text_input);
  612. return uart_text_input;
  613. }
  614. void uart_text_input_free(UART_TextInput *uart_text_input)
  615. {
  616. furi_assert(uart_text_input);
  617. with_view_model(
  618. uart_text_input->view,
  619. UART_TextInputModel * model,
  620. { furi_string_free(model->validator_text); },
  621. false);
  622. // Send stop command
  623. furi_timer_stop(uart_text_input->timer);
  624. // Release allocated memory
  625. furi_timer_free(uart_text_input->timer);
  626. view_free(uart_text_input->view);
  627. free(uart_text_input);
  628. }
  629. void uart_text_input_reset(UART_TextInput *uart_text_input)
  630. {
  631. furi_assert(uart_text_input);
  632. with_view_model(
  633. uart_text_input->view,
  634. UART_TextInputModel * model,
  635. {
  636. model->text_buffer_size = 0;
  637. model->header = "";
  638. model->selected_row = 0;
  639. model->selected_column = 0;
  640. model->clear_default_text = false;
  641. model->text_buffer = NULL;
  642. model->text_buffer_size = 0;
  643. model->callback = NULL;
  644. model->callback_context = NULL;
  645. model->validator_callback = NULL;
  646. model->validator_callback_context = NULL;
  647. furi_string_reset(model->validator_text);
  648. model->valadator_message_visible = false;
  649. },
  650. true);
  651. }
  652. View *uart_text_input_get_view(UART_TextInput *uart_text_input)
  653. {
  654. furi_assert(uart_text_input);
  655. return uart_text_input->view;
  656. }
  657. void uart_text_input_set_result_callback(
  658. UART_TextInput *uart_text_input,
  659. UART_TextInputCallback callback,
  660. void *callback_context,
  661. char *text_buffer,
  662. size_t text_buffer_size,
  663. bool clear_default_text)
  664. {
  665. with_view_model(
  666. uart_text_input->view,
  667. UART_TextInputModel * model,
  668. {
  669. model->callback = callback;
  670. model->callback_context = callback_context;
  671. model->text_buffer = text_buffer;
  672. model->text_buffer_size = text_buffer_size;
  673. model->clear_default_text = clear_default_text;
  674. if (text_buffer && text_buffer[0] != '\0')
  675. {
  676. // Set focus on Save
  677. model->selected_row = 2;
  678. model->selected_column = 8;
  679. }
  680. },
  681. true);
  682. }
  683. void uart_text_input_set_validator(
  684. UART_TextInput *uart_text_input,
  685. UART_TextInputValidatorCallback callback,
  686. void *callback_context)
  687. {
  688. with_view_model(
  689. uart_text_input->view,
  690. UART_TextInputModel * model,
  691. {
  692. model->validator_callback = callback;
  693. model->validator_callback_context = callback_context;
  694. },
  695. true);
  696. }
  697. UART_TextInputValidatorCallback
  698. uart_text_input_get_validator_callback(UART_TextInput *uart_text_input)
  699. {
  700. UART_TextInputValidatorCallback validator_callback = NULL;
  701. with_view_model(
  702. uart_text_input->view,
  703. UART_TextInputModel * model,
  704. { validator_callback = model->validator_callback; },
  705. false);
  706. return validator_callback;
  707. }
  708. void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input)
  709. {
  710. void *validator_callback_context = NULL;
  711. with_view_model(
  712. uart_text_input->view,
  713. UART_TextInputModel * model,
  714. { validator_callback_context = model->validator_callback_context; },
  715. false);
  716. return validator_callback_context;
  717. }
  718. void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text)
  719. {
  720. with_view_model(
  721. uart_text_input->view, UART_TextInputModel * model, { model->header = text; }, true);
  722. }