text_input.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * @file text_input.h
  3. * GUI: TextInput keyboard view module API
  4. */
  5. #pragma once
  6. #include <gui/view.h>
  7. #include "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();
  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. void text_input_set_validator(
  59. TextInput* text_input,
  60. TextInputValidatorCallback callback,
  61. void* callback_context);
  62. TextInputValidatorCallback text_input_get_validator_callback(TextInput* text_input);
  63. void* text_input_get_validator_callback_context(TextInput* text_input);
  64. /** Set text input header text
  65. *
  66. * @param text_input TextInput instance
  67. * @param text text to be shown
  68. */
  69. void text_input_set_header_text(TextInput* text_input, const char* text);
  70. #ifdef __cplusplus
  71. }
  72. #endif