On this example marks management will be explained. Functions elm_calendar_mark_add(), elm_calendar_mark_del() and elm_calendar_marks_clear() will be covered.
To add a mark, will be required to choose three things:
- mark style
- mark date, or start date if it will be repeated
- mark periodicity
Style defines the kind of mark will be displayed over marked day, on calendar. Default theme supports holiday and checked. If more is required, is possible to set a new theme to calendar widget using elm_object_style_set(), and use the signal that will be used by such marks.
Date is a struct tm
, as defined by time.h
. More can be read on ctime
manpage. If a date relative from current is required, this struct can be set as:
current_time = time(NULL);
localtime_r(¤t_time, &selected_time);
Or if it's an absolute date, you can just declare the struct like:
struct tm sunday;
struct tm christmas;
memset(&sunday, 0, sizeof(struct tm));
sunday.tm_hour = 12;
sunday.tm_mday = 7;
sunday.tm_isdst = -1;
memset(&christmas, 0, sizeof(struct tm));
christmas.tm_mday = 25;
christmas.tm_mon = 11;
Periodicity is how frequently the mark will be displayed over the calendar. Can be a unique mark (that don't repeat), or it can repeat daily, weekly, monthly or annually. It's enumerated by Elm_Calendar_Mark_Repeat_Type
.
So let's add some marks to our calendar. We will add christmas holiday, set Sundays as holidays, and check current day and day after that.
struct tm sunday;
struct tm christmas;
memset(&sunday, 0, sizeof(struct tm));
sunday.tm_hour = 12;
sunday.tm_mday = 7;
sunday.tm_isdst = -1;
memset(&christmas, 0, sizeof(struct tm));
christmas.tm_mday = 25;
christmas.tm_mon = 11;
current_time = time(NULL);
localtime_r(¤t_time, &selected_time);
mark = elm_calendar_mark_add(cal, "checked", &selected_time,
ELM_CALENDAR_UNIQUE);
current_time = time(NULL) + 1 * SECS_DAY;
localtime_r(¤t_time, &selected_time);
elm_calendar_mark_add(cal, "checked", &selected_time, ELM_CALENDAR_UNIQUE);
elm_calendar_mark_add(cal, "holiday", &christmas, ELM_CALENDAR_ANNUALLY);
elm_calendar_mark_add(cal, "holiday", &sunday, ELM_CALENDAR_WEEKLY);
We kept the return of first mark add, because we don't really won't it to be checked, so let's remove it:
elm_calendar_mark_del(mark);
After all marks are added and removed, is required to draw them:
elm_calendar_marks_draw(cal);
Finally, to clear all marks, let's set a callback for our button:
elm_object_text_set(bt, "Clear marks");
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
#define EVAS_HINT_FILL
Use with evas_object_size_hint_align_set(), evas_object_size_hint_align_get(), evas_object_size_hint_...
Definition: Evas_Common.h:298
void elm_box_pack_end(Elm_Box *obj, Efl_Canvas_Object *subobj)
Add an object at the end of the pack list.
Definition: elm_box_eo.legacy.c:57
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040
This callback will receive our calendar object, and should clear it:
static void
{
elm_calendar_marks_clear(cal);
elm_calendar_marks_draw(cal);
}
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
- Note
- Remember to draw marks after clear the calendar.
Our example will look like this:
See the full source code calendar_example_06.c here.