text_input.h 2.3 KB

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