ob_cardview.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /**
  2. * @file ob_cardview.h
  3. *
  4. */
  5. #ifndef OB_CARDVIEW_H
  6. #define OB_CARDVIEW_H
  7. #ifdef __cplusplus
  8. extern "C" {
  9. #endif
  10. /*********************
  11. * INCLUDES
  12. *********************/
  13. #include "lv_conf.h"
  14. #include "config.h"
  15. #if USE_OB_CARDVIEW != 0
  16. /*Testing of dependencies*/
  17. #if USE_LV_BTNM == 0
  18. #error "ob_cardview: lv_btnm is required. Enable it in lv_conf.h (USE_LV_BTNM 1) "
  19. #endif
  20. #if USE_LV_PAGE == 0
  21. #error "ob_cardview: lv_page is required. Enable it in lv_conf.h (USE_LV_PAGE 1) "
  22. #endif
  23. #include "lvgl/lvgl.h"
  24. /*********************
  25. * DEFINES
  26. *********************/
  27. /**********************
  28. * TYPEDEFS
  29. **********************/
  30. /* parametes: pointer to a cardview object, card_id*/
  31. typedef void (*ob_cardview_action_t)(lv_obj_t *, uint16_t);
  32. /*Data of card*/
  33. typedef struct
  34. {
  35. /*Ext. of ancestor*/
  36. /*New data for this type */
  37. lv_obj_t * content; /*A rectangle to show the current card*/
  38. lv_point_t point_last;
  39. uint16_t card_cur;
  40. uint16_t card_cnt;
  41. uint16_t anim_time;
  42. lv_coord_t bullet_size_act;
  43. lv_coord_t bullet_size_ina;
  44. uint8_t slide_enable :1; /*1: enable horizontal sliding by touch pad*/
  45. uint8_t draging :1;
  46. uint8_t drag_hor :1;
  47. ob_cardview_action_t card_load_action;
  48. lv_style_t * style_bullet_act;
  49. lv_style_t * style_bullet_ina;
  50. }ob_cardview_ext_t;
  51. typedef enum {
  52. OB_CARDVIEW_STYLE_BG,
  53. OB_CARDVIEW_STYLE_BULLET_ACT,
  54. OB_CARDVIEW_STYLE_BULLET_INA,
  55. }ob_cardview_style_t;
  56. /**********************
  57. * GLOBAL PROTOTYPES
  58. **********************/
  59. /**
  60. * Create a Card view object
  61. * @param par pointer to an object, it will be the parent of the new card
  62. * @param copy pointer to a card object, if not NULL then the new object will be copied from it
  63. * @return pointer to the created card
  64. */
  65. lv_obj_t * ob_cardview_create(lv_obj_t * par, lv_obj_t * copy);
  66. /*======================
  67. * Add/remove functions
  68. *=====================*/
  69. /**
  70. * Add a card to the end
  71. */
  72. lv_obj_t * ob_cardview_append_card(lv_obj_t * cardview);
  73. /**
  74. * Add a new card with the given name
  75. * @param cardview pointer to Card view object where to ass the new card
  76. * @return pointer to the created page object (lv_page). You can create your content here
  77. */
  78. lv_obj_t * ob_cardview_add_card(lv_obj_t * cardview, int pos);
  79. void ob_cardview_delete_card(lv_obj_t * cardview, lv_obj_t * card);
  80. /*=====================
  81. * Setter functions
  82. *====================*/
  83. /**
  84. * Set a new card
  85. * @param cardview pointer to Card view object
  86. * @param id index of a card to load
  87. * @param anim_en true: set with sliding animation; false: set immediately
  88. */
  89. void ob_cardview_set_card_act(lv_obj_t * cardview, uint16_t id, bool anim_en);
  90. /**
  91. * Set an action to call when a card is loaded (Good to create content only if required)
  92. * ob_cardview_get_act() still gives the current (old) card (to remove content from here)
  93. * @param cardview pointer to a cardview object
  94. * @param action pointer to a function to call when a card is loaded
  95. */
  96. void ob_cardview_set_card_load_action(lv_obj_t *cardview, ob_cardview_action_t action);
  97. /**
  98. * Enable horizontal sliding with touch pad
  99. * @param cardview pointer to Card view object
  100. * @param en true: enable sliding; false: disable sliding
  101. */
  102. void ob_cardview_set_sliding(lv_obj_t * cardview, bool en);
  103. /**
  104. * Set the animation time of card view when a new card is loaded
  105. * @param cardview pointer to Card view object
  106. * @param anim_time time of animation in milliseconds
  107. */
  108. void ob_cardview_set_anim_time(lv_obj_t * cardview, uint16_t anim_time);
  109. /**
  110. * Set the size of the bullets which indicated the pages
  111. * @param cardview pointer to Card view object
  112. * @param size_act size of the active bullet
  113. * @param size_ina size of the inactive bullet
  114. */
  115. void ob_cardview_set_bullet_size(lv_obj_t * cardview, lv_coord_t size_act, lv_coord_t size_ina);
  116. /**
  117. * Set the style of a card view
  118. * @param cardview pointer to a tan view object
  119. * @param type which style should be set
  120. * @param style pointer to the new style
  121. */
  122. void ob_cardview_set_style(lv_obj_t *cardview, ob_cardview_style_t type, lv_style_t *style);
  123. /*=====================
  124. * Getter functions
  125. *====================*/
  126. /**
  127. * Get the index of the currently active card
  128. * @param cardview pointer to Card view object
  129. * @return the active card index
  130. */
  131. uint16_t ob_cardview_get_card_act(lv_obj_t * cardview);
  132. /**
  133. * Get the free_num index of the currently active card
  134. * @param cardview pointer to Card view object
  135. * @return the active card free_num index
  136. */
  137. uint16_t ob_cardview_get_card_act_fn(lv_obj_t * cardview);
  138. /**
  139. * Get the number of cards
  140. * @param cardview pointer to Card view object
  141. * @return card count
  142. */
  143. uint16_t ob_cardview_get_card_count(lv_obj_t * cardview);
  144. /**
  145. * Get the page (content area) of a card
  146. * @param cardview pointer to Card view object
  147. * @param id index of the card (>= 0)
  148. * @return pointer to page (lv_page) object
  149. */
  150. lv_obj_t * ob_cardview_get_card(lv_obj_t * cardview, uint16_t id);
  151. /**
  152. * Get the card load action
  153. * @param cardview pointer to a cardview object
  154. * @param return the current card load action
  155. */
  156. ob_cardview_action_t ob_cardview_get_card_load_action(lv_obj_t *cardview);
  157. /**
  158. * Get the page (content area) of a card by specifying a matching free_ptr string value
  159. * @param cardview pointer to Tab view object
  160. * @param searchKey string value of free_ptr of matching card
  161. * @return pointer to page (lv_page) object
  162. */
  163. lv_obj_t * ob_cardview_get_card_by_fp_string(lv_obj_t * cardview, char* searchKey);
  164. /**
  165. * Get horizontal sliding is enabled or not
  166. * @param cardview pointer to Card view object
  167. * @return true: enable sliding; false: disable sliding
  168. */
  169. bool ob_cardview_get_sliding(lv_obj_t * cardview);
  170. /**
  171. * Get the animation time of card view when a new card is loaded
  172. * @param cardview pointer to Card view object
  173. * @return time of animation in milliseconds
  174. */
  175. uint16_t ob_cardview_get_anim_time(lv_obj_t * cardview);
  176. /**
  177. * Get the size of the active bullet
  178. * @param cardview pointer to Card view object
  179. * @return size of the bullets (inactive bullets have half size)
  180. */
  181. lv_coord_t ob_cardview_get_bullet_size_act(lv_obj_t * cardview);
  182. /**
  183. * Get the size of the active bullet
  184. * @param cardview pointer to Card view object
  185. * @return size of the bullets (inactive bullets have half size)
  186. */
  187. lv_coord_t ob_cardview_get_bullet_size_ina(lv_obj_t * cardview);
  188. /**
  189. * Get a style of a card view
  190. * @param cardview pointer to a card view object
  191. * @param type which style should be get
  192. * @return style pointer to a style
  193. */
  194. lv_style_t * ob_cardview_get_style(lv_obj_t *cardview, ob_cardview_style_t type);
  195. /**
  196. * Get highest free_num of all cards in carview
  197. * @param cardview pointer to a card view object
  198. * @param type which style should be get
  199. * @return value of highest free_num
  200. */
  201. uint16_t ob_cardview_get_max_free_num(lv_obj_t *cardview);
  202. /**********************
  203. * MACROS
  204. **********************/
  205. #endif /*USE_OB_CARDVIEW*/
  206. #ifdef __cplusplus
  207. } /* extern "C" */
  208. #endif
  209. #endif /*OB_CARDVIEW_H*/