luat_airui.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef LUAT_AIRUI_H
  2. #define LUAT_AIRUI_H
  3. #include "luat_base.h"
  4. #include "lvgl.h"
  5. #define JSMN_STATIC
  6. #include "jsmn.h"
  7. typedef struct luat_airui_obj
  8. {
  9. lv_obj_t *lvobj;
  10. }luat_airui_obj_t;
  11. typedef struct luat_airui_ctx
  12. {
  13. const char* screen_name;
  14. int airui_backend_type;
  15. lv_obj_t *scr;
  16. lv_obj_t *objs;
  17. size_t obj_count;
  18. const char* data;
  19. }luat_airui_ctx_t;
  20. typedef int (*airui_parse_cb)(luat_airui_ctx_t* ctx, jsmntok_t *tok, int pos);
  21. typedef struct airui_parser
  22. {
  23. const char* name;
  24. airui_parse_cb cb;
  25. }airui_parser_t;
  26. int luat_airui_load_buff(luat_airui_ctx_t** ctx, int backend, const char* screen_name, const char* buff, size_t len);
  27. int luat_airui_load_file(luat_airui_ctx_t** ctx, int backend, const char* screen_name, const char* path);
  28. int luat_airui_get(luat_airui_ctx_t* ctx, const char* key);
  29. int luat_airui_load_components(luat_airui_ctx_t* ctx, void *tok, size_t tok_count);
  30. // jsmn 的帮助函数
  31. typedef struct c_str
  32. {
  33. size_t len;
  34. char* ptr;
  35. }c_str_t;
  36. typedef struct air_block_info
  37. {
  38. int x;
  39. int y;
  40. int width;
  41. int height;
  42. c_str_t name;
  43. c_str_t body;
  44. }air_block_info_t;
  45. int jsmn_skip_object(jsmntok_t *tok, size_t *cur);
  46. int jsmn_skip_array(jsmntok_t *tok, size_t *cur);
  47. int jsmn_skip_entry(jsmntok_t *tok, size_t *cur);
  48. int jsmn_find_by_key(const char* data, const char* key, jsmntok_t *tok, size_t pos);
  49. int jsmn_toint(const char* data, jsmntok_t *tok);
  50. void jsmn_get_string(const char* data, jsmntok_t *tok, int pos, c_str_t *str);
  51. typedef struct airui_block
  52. {
  53. luat_airui_ctx_t* ctx;
  54. jsmntok_t *tok;
  55. air_block_info_t* info;
  56. int schema_pos;
  57. void* parent;
  58. void* self;
  59. }airui_block_t;
  60. typedef int (*airui_block_cb)(airui_block_t *bl);
  61. #endif