1 /**
2  * @file lv_cont.h
3  *
4  */
5 
6 #ifndef LV_CONT_H
7 #define LV_CONT_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../lv_conf_internal.h"
17 
18 #if LV_USE_CONT != 0
19 
20 #include "../lv_core/lv_obj.h"
21 
22 /*********************
23  *      DEFINES
24  *********************/
25 
26 /**********************
27  *      TYPEDEFS
28  **********************/
29 
30 /** Container layout options*/
31 enum {
32     LV_LAYOUT_OFF = 0, /**< No layout */
33     LV_LAYOUT_CENTER, /**< Center objects */
34 
35     /**
36      * COULMN:
37      * - Place the object below each other
38      * - Keep `pad_top` space on the top
39      * - Keep `pad_inner` space between the objects
40      */
41     LV_LAYOUT_COLUMN_LEFT,      /**< Column left align*/
42     LV_LAYOUT_COLUMN_MID,       /**< Column middle align*/
43     LV_LAYOUT_COLUMN_RIGHT,     /**< Column right align*/
44 
45     /**
46      * ROW:
47      * - Place the object next to each other
48      * - Keep `pad_left` space on the left
49      * - Keep `pad_inner` space between the objects
50      * - If the object which applies the layout has `base_dir == LV_BIDI_DIR_RTL`
51      *   the row will start from the right applying `pad.right` space
52      */
53     LV_LAYOUT_ROW_TOP,          /**< Row top align*/
54     LV_LAYOUT_ROW_MID,          /**< Row middle align*/
55     LV_LAYOUT_ROW_BOTTOM,       /**< Row bottom align*/
56 
57 
58     /**
59      * PRETTY:
60      * - Place the object next to each other
61      * - If there is no more space start a new row
62      * - Respect `pad_left` and `pad_right` when determining the available space in a row
63      * - Keep `pad_inner` space between the objects in the same row
64      * - Keep `pad_inner` space between the objects in rows
65      * - Divide the remaining horizontal space equally
66      */
67     LV_LAYOUT_PRETTY_TOP,       /**< Row top align*/
68     LV_LAYOUT_PRETTY_MID,       /**< Row middle align*/
69     LV_LAYOUT_PRETTY_BOTTOM,    /**< Row bottom align*/
70 
71     /**
72      * GRID
73      * - Place the object next to each other
74      * - If there is no more space start a new row
75      * - Respect `pad_left` and `pad_right` when determining the available space in a row
76      * - Keep `pad_inner` space between the objects in the same row
77      * - Keep `pad_inner` space between the objects in rows
78      * - Unlike `PRETTY`, `GRID` always keep `pad_inner` space horizontally between objects
79      *   so it doesn't divide the remaining horizontal space equally
80      */
81     LV_LAYOUT_GRID,   /**< Align same-sized object into a grid*/
82 
83     _LV_LAYOUT_LAST
84 };
85 typedef uint8_t lv_layout_t;
86 
87 /**
88  * How to resize the container around the children.
89  */
90 enum {
91     LV_FIT_NONE,  /**< Do not change the size automatically*/
92     LV_FIT_TIGHT, /**< Shrink wrap around the children */
93     LV_FIT_PARENT, /**< Align the size to the parent's edge*/
94     LV_FIT_MAX,  /**< Align the size to the parent's edge first but if there is an object out of it
95                      then get larger */
96     _LV_FIT_LAST
97 };
98 typedef uint8_t lv_fit_t;
99 
100 typedef struct {
101     /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/
102     /*New data for this type */
103     lv_layout_t layout : 4;     /*A layout from 'lv_layout_t' enum*/
104     lv_fit_t fit_left : 2;   /*A fit type from `lv_fit_t` enum */
105     lv_fit_t fit_right : 2;  /*A fit type from `lv_fit_t` enum */
106     lv_fit_t fit_top : 2;    /*A fit type from `lv_fit_t` enum */
107     lv_fit_t fit_bottom : 2; /*A fit type from `lv_fit_t` enum */
108 } lv_cont_ext_t;
109 
110 /*Part of the container*/
111 enum {
112     LV_CONT_PART_MAIN = LV_OBJ_PART_MAIN,
113     _LV_CONT_PART_VIRTUAL_LAST = _LV_OBJ_PART_VIRTUAL_LAST,
114     _LV_CONT_PART_REAL_LAST = _LV_OBJ_PART_REAL_LAST,
115 };
116 
117 /**********************
118  * GLOBAL PROTOTYPES
119  **********************/
120 
121 /**
122  * Create a container objects
123  * @param par pointer to an object, it will be the parent of the new container
124  * @param copy pointer to a container object, if not NULL then the new object will be copied from it
125  * @return pointer to the created container
126  */
127 lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy);
128 
129 /*=====================
130  * Setter functions
131  *====================*/
132 
133 /**
134  * Set a layout on a container
135  * @param cont pointer to a container object
136  * @param layout a layout from 'lv_cont_layout_t'
137  */
138 void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout);
139 
140 /**
141  * Set the fit policy in all 4 directions separately.
142  * It tell how to change the container's size automatically.
143  * @param cont pointer to a container object
144  * @param left left fit policy from `lv_fit_t`
145  * @param right right fit policy from `lv_fit_t`
146  * @param top top fit policy from `lv_fit_t`
147  * @param bottom bottom fit policy from `lv_fit_t`
148  */
149 void lv_cont_set_fit4(lv_obj_t * cont, lv_fit_t left, lv_fit_t right, lv_fit_t top, lv_fit_t bottom);
150 
151 /**
152  * Set the fit policy horizontally and vertically separately.
153  * It tells how to change the container's size automatically.
154  * @param cont pointer to a container object
155  * @param hor horizontal fit policy from `lv_fit_t`
156  * @param ver vertical fit policy from `lv_fit_t`
157  */
lv_cont_set_fit2(lv_obj_t * cont,lv_fit_t hor,lv_fit_t ver)158 static inline void lv_cont_set_fit2(lv_obj_t * cont, lv_fit_t hor, lv_fit_t ver)
159 {
160     lv_cont_set_fit4(cont, hor, hor, ver, ver);
161 }
162 
163 /**
164  * Set the fit policy in all 4 direction at once.
165  * It tells how to change the container's size automatically.
166  * @param cont pointer to a container object
167  * @param fit fit policy from `lv_fit_t`
168  */
lv_cont_set_fit(lv_obj_t * cont,lv_fit_t fit)169 static inline void lv_cont_set_fit(lv_obj_t * cont, lv_fit_t fit)
170 {
171     lv_cont_set_fit4(cont, fit, fit, fit, fit);
172 }
173 
174 /*=====================
175  * Getter functions
176  *====================*/
177 
178 /**
179  * Get the layout of a container
180  * @param cont pointer to container object
181  * @return the layout from 'lv_cont_layout_t'
182  */
183 lv_layout_t lv_cont_get_layout(const lv_obj_t * cont);
184 
185 /**
186  * Get left fit mode of a container
187  * @param cont pointer to a container object
188  * @return an element of `lv_fit_t`
189  */
190 lv_fit_t lv_cont_get_fit_left(const lv_obj_t * cont);
191 
192 /**
193  * Get right fit mode of a container
194  * @param cont pointer to a container object
195  * @return an element of `lv_fit_t`
196  */
197 lv_fit_t lv_cont_get_fit_right(const lv_obj_t * cont);
198 
199 /**
200  * Get top fit mode of a container
201  * @param cont pointer to a container object
202  * @return an element of `lv_fit_t`
203  */
204 lv_fit_t lv_cont_get_fit_top(const lv_obj_t * cont);
205 
206 /**
207  * Get bottom fit mode of a container
208  * @param cont pointer to a container object
209  * @return an element of `lv_fit_t`
210  */
211 lv_fit_t lv_cont_get_fit_bottom(const lv_obj_t * cont);
212 
213 /**********************
214  *      MACROS
215  **********************/
216 
217 #endif /*LV_USE_CONT*/
218 
219 #ifdef __cplusplus
220 } /* extern "C" */
221 #endif
222 
223 #endif /*LV_CONT_H*/
224