1 /**
2  * @file lv_page.h
3  *
4  */
5 
6 #ifndef LV_PAGE_H
7 #define LV_PAGE_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #ifdef LV_CONF_INCLUDE_SIMPLE
17 #include "lv_conf.h"
18 #else
19 #include "../../lv_conf.h"
20 #endif
21 
22 #if LV_USE_PAGE != 0
23 
24 /*Testing of dependencies*/
25 #if LV_USE_CONT == 0
26 #error "lv_page: lv_cont is required. Enable it in lv_conf.h (LV_USE_CONT  1) "
27 #endif
28 
29 #include "lv_cont.h"
30 #include "../lv_core/lv_indev.h"
31 #include "../lv_misc/lv_anim.h"
32 
33 /*********************
34  *      DEFINES
35  *********************/
36 
37 /**********************
38  *      TYPEDEFS
39  **********************/
40 
41 /** Scrollbar modes: shows when should the scrollbars be visible*/
42 enum {
43     LV_SB_MODE_OFF    = 0x0, /**< Never show scrollbars*/
44     LV_SB_MODE_ON     = 0x1, /**< Always show scrollbars*/
45     LV_SB_MODE_DRAG   = 0x2, /**< Show scrollbars when page is being dragged*/
46     LV_SB_MODE_AUTO   = 0x3, /**< Show scrollbars when the scrollable container is large enough to be scrolled*/
47     LV_SB_MODE_HIDE   = 0x4, /**< Hide the scroll bar temporally*/
48     LV_SB_MODE_UNHIDE = 0x5, /**< Unhide the previously hidden scrollbar. Recover it's type too*/
49 };
50 typedef uint8_t lv_sb_mode_t;
51 
52 /** Edges: describes the four edges of the page*/
53 enum { LV_PAGE_EDGE_LEFT = 0x1, LV_PAGE_EDGE_TOP = 0x2, LV_PAGE_EDGE_RIGHT = 0x4, LV_PAGE_EDGE_BOTTOM = 0x8 };
54 typedef uint8_t lv_page_edge_t;
55 
56 /*Data of page*/
57 typedef struct
58 {
59     lv_cont_ext_t bg; /*Ext. of ancestor*/
60     /*New data for this type */
61     lv_obj_t * scrl; /*The scrollable object on the background*/
62     struct
63     {
64         const lv_style_t * style; /*Style of scrollbars*/
65         lv_area_t hor_area;       /*Horizontal scrollbar area relative to the page. (Handled by the library) */
66         lv_area_t ver_area;       /*Vertical scrollbar area relative to the page (Handled by the library)*/
67         uint8_t hor_draw : 1;     /*1: horizontal scrollbar is visible now (Handled by the library)*/
68         uint8_t ver_draw : 1;     /*1: vertical scrollbar is visible now (Handled by the library)*/
69         lv_sb_mode_t mode : 3;    /*Scrollbar visibility from 'lv_page_sb_mode_t'*/
70     } sb;
71 #if LV_USE_ANIMATION
72     struct
73     {
74         lv_anim_value_t state;    /*Store the current size of the edge flash effect*/
75         const lv_style_t * style; /*Style of edge flash effect (usually homogeneous circle)*/
76         uint8_t enabled : 1;      /*1: Show a flash animation on the edge*/
77         uint8_t top_ip : 1;       /*Used internally to show that top most position is reached (flash is In
78                                      Progress)*/
79         uint8_t bottom_ip : 1;    /*Used internally to show that bottom most position is reached (flash
80                                      is In Progress)*/
81         uint8_t right_ip : 1;     /*Used internally to show that right most position is reached (flash
82                                      is In Progress)*/
83         uint8_t left_ip : 1;      /*Used internally to show that left most position is reached (flash is
84                                      In Progress)*/
85     } edge_flash;
86 
87     uint16_t anim_time; /*Scroll animation time*/
88 #endif
89 
90     uint8_t scroll_prop : 1;    /*1: Propagate the scrolling the the parent if the edge is reached*/
91     uint8_t scroll_prop_ip : 1; /*1: Scroll propagation is in progress (used by the library)*/
92 } lv_page_ext_t;
93 
94 enum {
95     LV_PAGE_STYLE_BG,
96     LV_PAGE_STYLE_SCRL,
97     LV_PAGE_STYLE_SB,
98     LV_PAGE_STYLE_EDGE_FLASH,
99 };
100 typedef uint8_t lv_page_style_t;
101 
102 /**********************
103  * GLOBAL PROTOTYPES
104  **********************/
105 
106 /**
107  * Create a page objects
108  * @param par pointer to an object, it will be the parent of the new page
109  * @param copy pointer to a page object, if not NULL then the new object will be copied from it
110  * @return pointer to the created page
111  */
112 lv_obj_t * lv_page_create(lv_obj_t * par, const lv_obj_t * copy);
113 
114 /**
115  * Delete all children of the scrl object, without deleting scrl child.
116  * @param obj pointer to an object
117  */
118 void lv_page_clean(lv_obj_t * obj);
119 
120 /**
121  * Get the scrollable object of a page
122  * @param page pointer to a page object
123  * @return pointer to a container which is the scrollable part of the page
124  */
125 lv_obj_t * lv_page_get_scrl(const lv_obj_t * page);
126 
127 /**
128  * Get the animation time
129  * @param page pointer to a page object
130  * @return the animation time in milliseconds
131  */
132 uint16_t lv_page_get_anim_time(const lv_obj_t * page);
133 
134 /*=====================
135  * Setter functions
136  *====================*/
137 
138 /**
139  * Set the scroll bar mode on a page
140  * @param page pointer to a page object
141  * @param sb_mode the new mode from 'lv_page_sb.mode_t' enum
142  */
143 void lv_page_set_sb_mode(lv_obj_t * page, lv_sb_mode_t sb_mode);
144 
145 /**
146  * Set the animation time for the page
147  * @param page pointer to a page object
148  * @param anim_time animation time in milliseconds
149  */
150 void lv_page_set_anim_time(lv_obj_t * page, uint16_t anim_time);
151 
152 /**
153  * Enable the scroll propagation feature. If enabled then the page will move its parent if there is
154  * no more space to scroll.
155  * @param page pointer to a Page
156  * @param en true or false to enable/disable scroll propagation
157  */
158 void lv_page_set_scroll_propagation(lv_obj_t * page, bool en);
159 
160 /**
161  * Enable the edge flash effect. (Show an arc when the an edge is reached)
162  * @param page pointer to a Page
163  * @param en true or false to enable/disable end flash
164  */
165 void lv_page_set_edge_flash(lv_obj_t * page, bool en);
166 
167 /**
168  * Set the fit policy in all 4 directions separately.
169  * It tell how to change the page size automatically.
170  * @param page pointer to a page object
171  * @param left left fit policy from `lv_fit_t`
172  * @param right right fit policy from `lv_fit_t`
173  * @param top bottom fit policy from `lv_fit_t`
174  * @param bottom bottom fit policy from `lv_fit_t`
175  */
lv_page_set_scrl_fit4(lv_obj_t * page,lv_fit_t left,lv_fit_t right,lv_fit_t top,lv_fit_t bottom)176 static inline void lv_page_set_scrl_fit4(lv_obj_t * page, lv_fit_t left, lv_fit_t right, lv_fit_t top, lv_fit_t bottom)
177 {
178     lv_cont_set_fit4(lv_page_get_scrl(page), left, right, top, bottom);
179 }
180 
181 /**
182  * Set the fit policy horizontally and vertically separately.
183  * It tell how to change the page size automatically.
184  * @param page pointer to a page object
185  * @param hot horizontal fit policy from `lv_fit_t`
186  * @param ver vertical fit policy from `lv_fit_t`
187  */
lv_page_set_scrl_fit2(lv_obj_t * page,lv_fit_t hor,lv_fit_t ver)188 static inline void lv_page_set_scrl_fit2(lv_obj_t * page, lv_fit_t hor, lv_fit_t ver)
189 {
190     lv_cont_set_fit2(lv_page_get_scrl(page), hor, ver);
191 }
192 
193 /**
194  * Set the fit policyin all 4 direction at once.
195  * It tell how to change the page size automatically.
196  * @param page pointer to a button object
197  * @param fit fit policy from `lv_fit_t`
198  */
lv_page_set_scrl_fit(lv_obj_t * page,lv_fit_t fit)199 static inline void lv_page_set_scrl_fit(lv_obj_t * page, lv_fit_t fit)
200 {
201     lv_cont_set_fit(lv_page_get_scrl(page), fit);
202 }
203 
204 /**
205  * Set width of the scrollable part of a page
206  * @param page pointer to a page object
207  * @param w the new width of the scrollable (it ha no effect is horizontal fit is enabled)
208  */
lv_page_set_scrl_width(lv_obj_t * page,lv_coord_t w)209 static inline void lv_page_set_scrl_width(lv_obj_t * page, lv_coord_t w)
210 {
211     lv_obj_set_width(lv_page_get_scrl(page), w);
212 }
213 
214 /**
215  * Set height of the scrollable part of a page
216  * @param page pointer to a page object
217  * @param h the new height of the scrollable (it ha no effect is vertical fit is enabled)
218  */
lv_page_set_scrl_height(lv_obj_t * page,lv_coord_t h)219 static inline void lv_page_set_scrl_height(lv_obj_t * page, lv_coord_t h)
220 {
221     lv_obj_set_height(lv_page_get_scrl(page), h);
222 }
223 
224 /**
225  * Set the layout of the scrollable part of the page
226  * @param page pointer to a page object
227  * @param layout a layout from 'lv_cont_layout_t'
228  */
lv_page_set_scrl_layout(lv_obj_t * page,lv_layout_t layout)229 static inline void lv_page_set_scrl_layout(lv_obj_t * page, lv_layout_t layout)
230 {
231     lv_cont_set_layout(lv_page_get_scrl(page), layout);
232 }
233 
234 /**
235  * Set a style of a page
236  * @param page pointer to a page object
237  * @param type which style should be set
238  * @param style pointer to a style
239  */
240 void lv_page_set_style(lv_obj_t * page, lv_page_style_t type, const lv_style_t * style);
241 
242 /*=====================
243  * Getter functions
244  *====================*/
245 
246 /**
247  * Set the scroll bar mode on a page
248  * @param page pointer to a page object
249  * @return the mode from 'lv_page_sb.mode_t' enum
250  */
251 lv_sb_mode_t lv_page_get_sb_mode(const lv_obj_t * page);
252 
253 /**
254  * Get the scroll propagation property
255  * @param page pointer to a Page
256  * @return true or false
257  */
258 bool lv_page_get_scroll_propagation(lv_obj_t * page);
259 
260 /**
261  * Get the edge flash effect property.
262  * @param page pointer to a Page
263  * return true or false
264  */
265 bool lv_page_get_edge_flash(lv_obj_t * page);
266 
267 /**
268  * Get that width which can be set to the children to still not cause overflow (show scrollbars)
269  * @param page pointer to a page object
270  * @return the width which still fits into the page
271  */
272 lv_coord_t lv_page_get_fit_width(lv_obj_t * page);
273 
274 /**
275  * Get that height which can be set to the children to still not cause overflow (show scrollbars)
276  * @param page pointer to a page object
277  * @return the height which still fits into the page
278  */
279 lv_coord_t lv_page_get_fit_height(lv_obj_t * page);
280 
281 /**
282  * Get width of the scrollable part of a page
283  * @param page pointer to a page object
284  * @return the width of the scrollable
285  */
lv_page_get_scrl_width(const lv_obj_t * page)286 static inline lv_coord_t lv_page_get_scrl_width(const lv_obj_t * page)
287 {
288     return lv_obj_get_width(lv_page_get_scrl(page));
289 }
290 
291 /**
292  * Get height of the scrollable part of a page
293  * @param page pointer to a page object
294  * @return the height of the scrollable
295  */
lv_page_get_scrl_height(const lv_obj_t * page)296 static inline lv_coord_t lv_page_get_scrl_height(const lv_obj_t * page)
297 {
298     return lv_obj_get_height(lv_page_get_scrl(page));
299 }
300 
301 /**
302  * Get the layout of the scrollable part of a page
303  * @param page pointer to page object
304  * @return the layout from 'lv_cont_layout_t'
305  */
lv_page_get_scrl_layout(const lv_obj_t * page)306 static inline lv_layout_t lv_page_get_scrl_layout(const lv_obj_t * page)
307 {
308     return lv_cont_get_layout(lv_page_get_scrl(page));
309 }
310 
311 /**
312  * Get the left fit mode
313  * @param page pointer to a page object
314  * @return an element of `lv_fit_t`
315  */
lv_page_get_scrl_fit_left(const lv_obj_t * page)316 static inline lv_fit_t lv_page_get_scrl_fit_left(const lv_obj_t * page)
317 {
318     return lv_cont_get_fit_left(lv_page_get_scrl(page));
319 }
320 
321 /**
322  * Get the right fit mode
323  * @param page pointer to a page object
324  * @return an element of `lv_fit_t`
325  */
lv_page_get_scrl_fit_right(const lv_obj_t * page)326 static inline lv_fit_t lv_page_get_scrl_fit_right(const lv_obj_t * page)
327 {
328     return lv_cont_get_fit_right(lv_page_get_scrl(page));
329 }
330 
331 /**
332  * Get the top fit mode
333  * @param page pointer to a page object
334  * @return an element of `lv_fit_t`
335  */
lv_page_get_scrl_fit_top(const lv_obj_t * page)336 static inline lv_fit_t lv_page_get_scrl_fit_top(const lv_obj_t * page)
337 {
338     return lv_cont_get_fit_top(lv_page_get_scrl(page));
339 }
340 
341 /**
342  * Get the bottom fit mode
343  * @param page pointer to a page object
344  * @return an element of `lv_fit_t`
345  */
lv_page_get_scrl_fit_bottom(const lv_obj_t * page)346 static inline lv_fit_t lv_page_get_scrl_fit_bottom(const lv_obj_t * page)
347 {
348     return lv_cont_get_fit_bottom(lv_page_get_scrl(page));
349 }
350 
351 /**
352  * Get a style of a page
353  * @param page pointer to page object
354  * @param type which style should be get
355  * @return style pointer to a style
356  */
357 const lv_style_t * lv_page_get_style(const lv_obj_t * page, lv_page_style_t type);
358 
359 /*=====================
360  * Other functions
361  *====================*/
362 
363 /**
364  * Find whether the page has been scrolled to a certain edge.
365  * @param page Page object
366  * @param edge Edge to check
367  * @return true if the page is on the specified edge
368  */
369 bool lv_page_on_edge(lv_obj_t * page, lv_page_edge_t edge);
370 
371 /**
372  * Glue the object to the page. After it the page can be moved (dragged) with this object too.
373  * @param obj pointer to an object on a page
374  * @param glue true: enable glue, false: disable glue
375  */
376 void lv_page_glue_obj(lv_obj_t * obj, bool glue);
377 
378 /**
379  * Focus on an object. It ensures that the object will be visible on the page.
380  * @param page pointer to a page object
381  * @param obj pointer to an object to focus (must be on the page)
382  * @param anim_en LV_ANIM_ON to focus with animation; LV_ANIM_OFF to focus without animation
383  */
384 void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, lv_anim_enable_t anim_en);
385 
386 /**
387  * Scroll the page horizontally
388  * @param page pointer to a page object
389  * @param dist the distance to scroll (< 0: scroll left; > 0 scroll right)
390  */
391 void lv_page_scroll_hor(lv_obj_t * page, lv_coord_t dist);
392 
393 /**
394  * Scroll the page vertically
395  * @param page pointer to a page object
396  * @param dist the distance to scroll (< 0: scroll down; > 0 scroll up)
397  */
398 void lv_page_scroll_ver(lv_obj_t * page, lv_coord_t dist);
399 
400 /**
401  * Not intended to use directly by the user but by other object types internally.
402  * Start an edge flash animation. Exactly one `ext->edge_flash.xxx_ip` should be set
403  * @param page
404  */
405 void lv_page_start_edge_flash(lv_obj_t * page);
406 /**********************
407  *      MACROS
408  **********************/
409 
410 #endif /*LV_USE_PAGE*/
411 
412 #ifdef __cplusplus
413 } /* extern "C" */
414 #endif
415 
416 #endif /*LV_PAGE_H*/
417