uart_text_input.h 2.4 KB

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