uart_text_input.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #pragma once
  2. // from https://github.com/xMasterX/all-the-plugins/blob/dev/base_pack/uart_terminal/uart_text_input.c
  3. // all credits to xMasterX for the code
  4. #include <gui/view.h>
  5. #ifdef __cplusplus
  6. extern "C"
  7. {
  8. #endif
  9. /** Text input anonymous structure */
  10. typedef struct UART_TextInput UART_TextInput;
  11. typedef void (*UART_TextInputCallback)(void *context);
  12. typedef bool (*UART_TextInputValidatorCallback)(const char *text, FuriString *error, void *context);
  13. /** Allocate and initialize text input
  14. *
  15. * This text input is used to enter string
  16. *
  17. * @return UART_TextInput instance
  18. */
  19. UART_TextInput *uart_text_input_alloc();
  20. /** Deinitialize and free text input
  21. *
  22. * @param uart_text_input UART_TextInput instance
  23. */
  24. void uart_text_input_free(UART_TextInput *uart_text_input);
  25. /** Clean text input view Note: this function does not free memory
  26. *
  27. * @param uart_text_input Text input instance
  28. */
  29. void uart_text_input_reset(UART_TextInput *uart_text_input);
  30. /** Get text input view
  31. *
  32. * @param uart_text_input UART_TextInput instance
  33. *
  34. * @return View instance that can be used for embedding
  35. */
  36. View *uart_text_input_get_view(UART_TextInput *uart_text_input);
  37. /** Set text input result callback
  38. *
  39. * @param uart_text_input UART_TextInput instance
  40. * @param callback callback fn
  41. * @param callback_context callback context
  42. * @param text_buffer pointer to YOUR text buffer, that we going
  43. * to modify
  44. * @param text_buffer_size YOUR text buffer size in bytes. Max string
  45. * length will be text_buffer_size-1.
  46. * @param clear_default_text clear text from text_buffer on first OK
  47. * event
  48. */
  49. void uart_text_input_set_result_callback(
  50. UART_TextInput *uart_text_input,
  51. UART_TextInputCallback callback,
  52. void *callback_context,
  53. char *text_buffer,
  54. size_t text_buffer_size,
  55. bool clear_default_text);
  56. void uart_text_input_set_validator(
  57. UART_TextInput *uart_text_input,
  58. UART_TextInputValidatorCallback callback,
  59. void *callback_context);
  60. UART_TextInputValidatorCallback
  61. uart_text_input_get_validator_callback(UART_TextInput *uart_text_input);
  62. void *uart_text_input_get_validator_callback_context(UART_TextInput *uart_text_input);
  63. /** Set text input header text
  64. *
  65. * @param uart_text_input UART_TextInput instance
  66. * @param text text to be shown
  67. */
  68. void uart_text_input_set_header_text(UART_TextInput *uart_text_input, const char *text);
  69. #ifdef __cplusplus
  70. }
  71. #endif