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 #ifdef LV_CONF_INCLUDE_SIMPLE
17 #include "lv_conf.h"
18 #else
19 #include "../../lv_conf.h"
20 #endif
21 
22 #if LV_USE_CONT != 0
23 
24 #include "../lv_core/lv_obj.h"
25 
26 /*********************
27  *      DEFINES
28  *********************/
29 
30 /**********************
31  *      TYPEDEFS
32  **********************/
33 
34 /** Container layout options*/
35 enum {
36     LV_LAYOUT_OFF = 0, /**< No layout */
37     LV_LAYOUT_CENTER, /**< Center objects */
38     LV_LAYOUT_COL_L,  /**< Column left align*/
39     LV_LAYOUT_COL_M,  /**< Column middle align*/
40     LV_LAYOUT_COL_R,  /**< Column right align*/
41     LV_LAYOUT_ROW_T,  /**< Row top align*/
42     LV_LAYOUT_ROW_M,  /**< Row middle align*/
43     LV_LAYOUT_ROW_B,  /**< Row bottom align*/
44     LV_LAYOUT_PRETTY, /**< Put as many object as possible in row and begin a new row*/
45     LV_LAYOUT_GRID,   /**< Align same-sized object into a grid*/
46     _LV_LAYOUT_NUM
47 };
48 typedef uint8_t lv_layout_t;
49 
50 /**
51  * How to resize the container around the children.
52  */
53 enum {
54     LV_FIT_NONE,  /**< Do not change the size automatically*/
55     LV_FIT_TIGHT, /**< Shrink wrap around the children */
56     LV_FIT_FLOOD, /**< Align the size to the parent's edge*/
57     LV_FIT_FILL,  /**< Align the size to the parent's edge first but if there is an object out of it
58                      then get larger */
59     _LV_FIT_NUM
60 };
61 typedef uint8_t lv_fit_t;
62 
63 typedef struct
64 {
65     /*Inherited from 'base_obj' so no inherited ext. */ /*Ext. of ancestor*/
66     /*New data for this type */
67     uint8_t layout : 4;     /*A layout from 'lv_layout_t' enum*/
68     uint8_t fit_left : 2;   /*A fit type from `lv_fit_t` enum */
69     uint8_t fit_right : 2;  /*A fit type from `lv_fit_t` enum */
70     uint8_t fit_top : 2;    /*A fit type from `lv_fit_t` enum */
71     uint8_t fit_bottom : 2; /*A fit type from `lv_fit_t` enum */
72 } lv_cont_ext_t;
73 
74 /*Styles*/
75 enum {
76     LV_CONT_STYLE_MAIN,
77 };
78 typedef uint8_t lv_cont_style_t;
79 
80 /**********************
81  * GLOBAL PROTOTYPES
82  **********************/
83 
84 /**
85  * Create a container objects
86  * @param par pointer to an object, it will be the parent of the new container
87  * @param copy pointer to a container object, if not NULL then the new object will be copied from it
88  * @return pointer to the created container
89  */
90 lv_obj_t * lv_cont_create(lv_obj_t * par, const lv_obj_t * copy);
91 
92 /*=====================
93  * Setter functions
94  *====================*/
95 
96 /**
97  * Set a layout on a container
98  * @param cont pointer to a container object
99  * @param layout a layout from 'lv_cont_layout_t'
100  */
101 void lv_cont_set_layout(lv_obj_t * cont, lv_layout_t layout);
102 
103 /**
104  * Set the fit policy in all 4 directions separately.
105  * It tell how to change the container's size automatically.
106  * @param cont pointer to a container object
107  * @param left left fit policy from `lv_fit_t`
108  * @param right right fit policy from `lv_fit_t`
109  * @param top top fit policy from `lv_fit_t`
110  * @param bottom bottom fit policy from `lv_fit_t`
111  */
112 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);
113 
114 /**
115  * Set the fit policy horizontally and vertically separately.
116  * It tells how to change the container's size automatically.
117  * @param cont pointer to a container object
118  * @param hor horizontal fit policy from `lv_fit_t`
119  * @param ver vertical fit policy from `lv_fit_t`
120  */
lv_cont_set_fit2(lv_obj_t * cont,lv_fit_t hor,lv_fit_t ver)121 static inline void lv_cont_set_fit2(lv_obj_t * cont, lv_fit_t hor, lv_fit_t ver)
122 {
123     lv_cont_set_fit4(cont, hor, hor, ver, ver);
124 }
125 
126 /**
127  * Set the fit policy in all 4 direction at once.
128  * It tells how to change the container's size automatically.
129  * @param cont pointer to a container object
130  * @param fit fit policy from `lv_fit_t`
131  */
lv_cont_set_fit(lv_obj_t * cont,lv_fit_t fit)132 static inline void lv_cont_set_fit(lv_obj_t * cont, lv_fit_t fit)
133 {
134     lv_cont_set_fit4(cont, fit, fit, fit, fit);
135 }
136 
137 /**
138  * Set the style of a container
139  * @param cont pointer to a container object
140  * @param type which style should be set (can be only `LV_CONT_STYLE_MAIN`)
141  * @param style pointer to the new style
142  */
lv_cont_set_style(lv_obj_t * cont,lv_cont_style_t type,const lv_style_t * style)143 static inline void lv_cont_set_style(lv_obj_t * cont, lv_cont_style_t type, const lv_style_t * style)
144 {
145     (void)type; /*Unused*/
146     lv_obj_set_style(cont, style);
147 }
148 
149 /*=====================
150  * Getter functions
151  *====================*/
152 
153 /**
154  * Get the layout of a container
155  * @param cont pointer to container object
156  * @return the layout from 'lv_cont_layout_t'
157  */
158 lv_layout_t lv_cont_get_layout(const lv_obj_t * cont);
159 
160 /**
161  * Get left fit mode of a container
162  * @param cont pointer to a container object
163  * @return an element of `lv_fit_t`
164  */
165 lv_fit_t lv_cont_get_fit_left(const lv_obj_t * cont);
166 
167 /**
168  * Get right fit mode of a container
169  * @param cont pointer to a container object
170  * @return an element of `lv_fit_t`
171  */
172 lv_fit_t lv_cont_get_fit_right(const lv_obj_t * cont);
173 
174 /**
175  * Get top fit mode of a container
176  * @param cont pointer to a container object
177  * @return an element of `lv_fit_t`
178  */
179 lv_fit_t lv_cont_get_fit_top(const lv_obj_t * cont);
180 
181 /**
182  * Get bottom fit mode of a container
183  * @param cont pointer to a container object
184  * @return an element of `lv_fit_t`
185  */
186 lv_fit_t lv_cont_get_fit_bottom(const lv_obj_t * cont);
187 
188 /**
189  * Get the style of a container
190  * @param cont pointer to a container object
191  * @param type which style should be get (can be only `LV_CONT_STYLE_MAIN`)
192  * @return pointer to the container's style
193  */
lv_cont_get_style(const lv_obj_t * cont,lv_cont_style_t type)194 static inline const lv_style_t * lv_cont_get_style(const lv_obj_t * cont, lv_cont_style_t type)
195 {
196     (void)type; /*Unused*/
197     return lv_obj_get_style(cont);
198 }
199 
200 /**********************
201  *      MACROS
202  **********************/
203 
204 #endif /*LV_USE_CONT*/
205 
206 #ifdef __cplusplus
207 } /* extern "C" */
208 #endif
209 
210 #endif /*LV_CONT_H*/
211