text_input.h 2.9 KB

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