- Elementary
- Main
- Authors
- Examples
- Files
- Pages
- Types
- Modules

Calendar - Calendar marks.

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(&current_time, &selected_time);

Or if it's an absolute date, you can just declare the struct like:

struct tm sunday = { 0, 0, 12, 7, 0, 0, 0, 0, -1, 0, NULL };
/* tm {sec, min, hour, mday, mon, year, wday, yday, isdst } */
/* weekdays since Sunday, range 0 to 6 */
struct tm christmas;
christmas.tm_mday = 25;
/* months since Jan, in the range 0 to 11 */
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 = { 0, 0, 12, 7, 0, 0, 0, 0, -1, 0, NULL };
/* tm {sec, min, hour, mday, mon, year, wday, yday, isdst } */
/* weekdays since Sunday, range 0 to 6 */
struct tm christmas;
christmas.tm_mday = 25;
/* months since Jan, in the range 0 to 11 */
christmas.tm_mon = 11;
current_time = time(NULL);
localtime_r(&current_time, &selected_time);
mark = elm_calendar_mark_add(cal, "checked", &selected_time,
ELM_CALENDAR_UNIQUE);
/* check tomorrow */
current_time = time(NULL) + 1 * SECS_DAY;
localtime_r(&current_time, &selected_time);
elm_calendar_mark_add(cal, "checked", &selected_time, ELM_CALENDAR_UNIQUE);
/* mark christmas as holiday */
elm_calendar_mark_add(cal, "holiday", &christmas, ELM_CALENDAR_ANNUALLY);
/* mark Sundays as holidays */
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:

bt = elm_button_add(win);
evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_object_text_set(bt, "Clear marks");
evas_object_smart_callback_add(bt, "clicked", _btn_clear_cb, cal);
elm_box_pack_end(bx, bt);
evas_object_show(bt);

This callback will receive our calendar object, and should clear it:

static void
_btn_clear_cb(void *data, Evas_Object *btn, void *ev)
{
Evas_Object *cal = data;
elm_calendar_marks_clear(cal);
elm_calendar_marks_draw(cal);
}

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.

Copyright ©2000-2014 Enlightenment.org - Samsung Electronics supports the EFL Documentation Project - Generated Wed Jan 8 2014 20:51:07