custom_text_input.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #pragma once
  2. #include <gui/view.h>
  3. #include "custom_validators.h"
  4. #include "cli_gui_icons.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. /** Text input anonymous structure */
  9. typedef struct Custom_TextInput Custom_TextInput;
  10. typedef void (*Custom_TextInputCallback)(void* context);
  11. typedef bool (
  12. *Custom_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 Custom_TextInput instance
  18. */
  19. Custom_TextInput* custom_text_input_alloc();
  20. /** Deinitialize and free text input
  21. *
  22. * @param text_input Custom_TextInput instance
  23. */
  24. void custom_text_input_free(Custom_TextInput* text_input);
  25. /** Clean text input view Note: this function does not free memory
  26. *
  27. * @param text_input Text input instance
  28. */
  29. void custom_text_input_reset(Custom_TextInput* text_input);
  30. /** Get text input view
  31. *
  32. * @param text_input Custom_TextInput instance
  33. *
  34. * @return View instance that can be used for embedding
  35. */
  36. View* custom_text_input_get_view(Custom_TextInput* text_input);
  37. /** Set text input result callback
  38. *
  39. * @param text_input Custom_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 custom_text_input_set_result_callback(
  50. Custom_TextInput* text_input,
  51. Custom_TextInputCallback callback,
  52. void* callback_context,
  53. char* text_buffer,
  54. size_t text_buffer_size,
  55. bool clear_default_text);
  56. void custom_text_input_set_validator(
  57. Custom_TextInput* text_input,
  58. Custom_TextInputValidatorCallback callback,
  59. void* callback_context);
  60. void custom_text_input_set_minimum_length(Custom_TextInput* text_input, size_t minimum_length);
  61. Custom_TextInputValidatorCallback
  62. custom_text_input_get_validator_callback(Custom_TextInput* text_input);
  63. void* custom_text_input_get_validator_callback_context(Custom_TextInput* text_input);
  64. /** Set text input header text
  65. *
  66. * @param text_input Custom_TextInput instance
  67. * @param text text to be shown
  68. */
  69. void custom_text_input_set_header_text(Custom_TextInput* text_input, const char* text);
  70. #ifdef __cplusplus
  71. }
  72. #endif