text_input.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @file text_input.h
  3. * GUI: TextInput keyboard view module API
  4. */
  5. #pragma once
  6. #include <gui/view.h>
  7. #include <gui/modules/validators.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /** Text input anonymous structure */
  12. typedef struct TextInput TextInput;
  13. typedef void (*TextInputCallback)(void* context);
  14. typedef bool (*TextInputValidatorCallback)(const char* text, FuriString* error, void* context);
  15. /** Allocate and initialize text input
  16. *
  17. * This text input is used to enter string
  18. *
  19. * @return TextInput instance
  20. */
  21. TextInput* text_input_alloc(void);
  22. /** Deinitialize and free text input
  23. *
  24. * @param text_input TextInput instance
  25. */
  26. void text_input_free(TextInput* text_input);
  27. /** Clean text input view Note: this function does not free memory
  28. *
  29. * @param text_input Text input instance
  30. */
  31. void text_input_reset(TextInput* text_input);
  32. /** Get text input view
  33. *
  34. * @param text_input TextInput instance
  35. *
  36. * @return View instance that can be used for embedding
  37. */
  38. View* text_input_get_view(TextInput* text_input);
  39. /** Set text input result callback
  40. *
  41. * @param text_input TextInput instance
  42. * @param callback callback fn
  43. * @param callback_context callback context
  44. * @param text_buffer pointer to YOUR text buffer, that we going
  45. * to modify
  46. * @param text_buffer_size YOUR text buffer size in bytes. Max string
  47. * length will be text_buffer_size-1.
  48. * @param clear_default_text clear text from text_buffer on first OK
  49. * event
  50. */
  51. void text_input_set_result_callback(
  52. TextInput* text_input,
  53. TextInputCallback callback,
  54. void* callback_context,
  55. char* text_buffer,
  56. size_t text_buffer_size,
  57. bool clear_default_text);
  58. /**
  59. * @brief Sets the minimum length of a TextInput
  60. * @param [in] text_input TextInput
  61. * @param [in] minimum_length Minimum input length
  62. */
  63. void text_input_set_minimum_length(TextInput* text_input, size_t minimum_length);
  64. void text_input_set_validator(
  65. TextInput* text_input,
  66. TextInputValidatorCallback callback,
  67. void* callback_context);
  68. /**
  69. * @brief Show the 9 illegal (windows) symbols <>:"/\|?* in the symbols keyboard instead of the numbers
  70. * @param [in] text_input TextInput
  71. * @param [in] show Whether to show the illegal symbols or not
  72. */
  73. void text_input_show_illegal_symbols(TextInput* text_input, bool show);
  74. TextInputValidatorCallback text_input_get_validator_callback(TextInput* text_input);
  75. void* text_input_get_validator_callback_context(TextInput* text_input);
  76. /** Set text input header text
  77. *
  78. * @param text_input TextInput instance
  79. * @param text text to be shown
  80. */
  81. void text_input_set_header_text(TextInput* text_input, const char* text);
  82. #ifdef __cplusplus
  83. }
  84. #endif