1 /**
2  * @file lv_calendar.h
3  *
4  */
5 
6 #ifndef LV_CALENDAR_H
7 #define LV_CALENDAR_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_CALENDAR != 0
19 
20 #include "../lv_core/lv_obj.h"
21 
22 /*********************
23  *      DEFINES
24  *********************/
25 
26 /**********************
27  *      TYPEDEFS
28  **********************/
29 
30 /**
31  * Represents a date on the calendar object (platform-agnostic).
32  */
33 typedef struct {
34     uint16_t year;
35     int8_t month;
36     int8_t day;
37 } lv_calendar_date_t;
38 
39 /*Data of calendar*/
40 typedef struct {
41     /*None*/ /*Ext. of ancestor*/
42     /*New data for this type */
43     lv_calendar_date_t today;               /*Date of today*/
44     lv_calendar_date_t showed_date;         /*Currently visible month (day is ignored)*/
45     lv_calendar_date_t * highlighted_dates; /*Apply different style on these days (pointer to an
46                                                array defined by the user)*/
47     int8_t btn_pressing;                    /*-1: prev month pressing, +1 next month pressing on the header*/
48     uint16_t highlighted_dates_num;          /*Number of elements in `highlighted_days`*/
49     lv_calendar_date_t pressed_date;
50     const char ** day_names;   /*Pointer to an array with the name of the days (NULL: use default names)*/
51     const char ** month_names; /*Pointer to an array with the name of the month (NULL. use default names)*/
52 
53     /*Styles*/
54     lv_style_list_t style_header;
55     lv_style_list_t style_day_names;
56     lv_style_list_t style_date_nums;
57 } lv_calendar_ext_t;
58 
59 /** Calendar parts*/
60 enum {
61     LV_CALENDAR_PART_BG, /**< Background and "normal" date numbers style */
62     LV_CALENDAR_PART_HEADER, /** Calendar header style */
63     LV_CALENDAR_PART_DAY_NAMES, /** Day name style */
64     LV_CALENDAR_PART_DATE, /** Day name style */
65 };
66 typedef uint8_t lv_calendar_part_t;
67 
68 /**********************
69  * GLOBAL PROTOTYPES
70  **********************/
71 
72 /**
73  * Create a calendar objects
74  * @param par pointer to an object, it will be the parent of the new calendar
75  * @param copy pointer to a calendar object, if not NULL then the new object will be copied from it
76  * @return pointer to the created calendar
77  */
78 lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy);
79 
80 /*======================
81  * Add/remove functions
82  *=====================*/
83 
84 /*=====================
85  * Setter functions
86  *====================*/
87 
88 /**
89  * Set the today's date
90  * @param calendar pointer to a calendar object
91  * @param today pointer to an `lv_calendar_date_t` variable containing the date of today. The value
92  * will be saved it can be local variable too.
93  */
94 void lv_calendar_set_today_date(lv_obj_t * calendar, lv_calendar_date_t * today);
95 
96 /**
97  * Set the currently showed
98  * @param calendar pointer to a calendar object
99  * @param showed pointer to an `lv_calendar_date_t` variable containing the date to show. The value
100  * will be saved it can be local variable too.
101  */
102 void lv_calendar_set_showed_date(lv_obj_t * calendar, lv_calendar_date_t * showed);
103 
104 /**
105  * Set the the highlighted dates
106  * @param calendar pointer to a calendar object
107  * @param highlighted pointer to an `lv_calendar_date_t` array containing the dates. ONLY A POINTER
108  * WILL BE SAVED! CAN'T BE LOCAL ARRAY.
109  * @param date_num number of dates in the array
110  */
111 void lv_calendar_set_highlighted_dates(lv_obj_t * calendar, lv_calendar_date_t highlighted[], uint16_t date_num);
112 
113 /**
114  * Set the name of the days
115  * @param calendar pointer to a calendar object
116  * @param day_names pointer to an array with the names. E.g. `const char * days[7] = {"Sun", "Mon",
117  * ...}` Only the pointer will be saved so this variable can't be local which will be destroyed
118  * later.
119  */
120 void lv_calendar_set_day_names(lv_obj_t * calendar, const char ** day_names);
121 
122 /**
123  * Set the name of the month
124  * @param calendar pointer to a calendar object
125  * @param month_names pointer to an array with the names. E.g. `const char * days[12] = {"Jan", "Feb",
126  * ...}` Only the pointer will be saved so this variable can't be local which will be destroyed
127  * later.
128  */
129 void lv_calendar_set_month_names(lv_obj_t * calendar, const char ** month_names);
130 
131 /*=====================
132  * Getter functions
133  *====================*/
134 
135 /**
136  * Get the today's date
137  * @param calendar pointer to a calendar object
138  * @return return pointer to an `lv_calendar_date_t` variable containing the date of today.
139  */
140 lv_calendar_date_t * lv_calendar_get_today_date(const lv_obj_t * calendar);
141 
142 /**
143  * Get the currently showed
144  * @param calendar pointer to a calendar object
145  * @return pointer to an `lv_calendar_date_t` variable containing the date is being shown.
146  */
147 lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar);
148 
149 /**
150  * Get the the pressed date.
151  * @param calendar pointer to a calendar object
152  * @return pointer to an `lv_calendar_date_t` variable containing the pressed date.
153  *         `NULL` if not date pressed (e.g. the header)
154  */
155 lv_calendar_date_t * lv_calendar_get_pressed_date(const lv_obj_t * calendar);
156 
157 /**
158  * Get the the highlighted dates
159  * @param calendar pointer to a calendar object
160  * @return pointer to an `lv_calendar_date_t` array containing the dates.
161  */
162 lv_calendar_date_t * lv_calendar_get_highlighted_dates(const lv_obj_t * calendar);
163 
164 /**
165  * Get the number of the highlighted dates
166  * @param calendar pointer to a calendar object
167  * @return number of highlighted days
168  */
169 uint16_t lv_calendar_get_highlighted_dates_num(const lv_obj_t * calendar);
170 
171 /**
172  * Get the name of the days
173  * @param calendar pointer to a calendar object
174  * @return pointer to the array of day names
175  */
176 const char ** lv_calendar_get_day_names(const lv_obj_t * calendar);
177 
178 /**
179  * Get the name of the month
180  * @param calendar pointer to a calendar object
181  * @return pointer to the array of month names
182  */
183 const char ** lv_calendar_get_month_names(const lv_obj_t * calendar);
184 
185 /*=====================
186  * Other functions
187  *====================*/
188 
189 /**********************
190  *      MACROS
191  **********************/
192 
193 #endif /*LV_USE_CALENDAR*/
194 
195 #ifdef __cplusplus
196 } /* extern "C" */
197 #endif
198 
199 #endif /*LV_CALENDAR_H*/
200