Calendar - Calendar marks.

- Main Page
- Related Pages
- Topics
- Data Structures
- Files
- Examples

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;
struct tm christmas;
/*
* At least on Windows, tm has 9 fields.
* As a workaround, set sunday to 0 and set
* th needed fields to correct value
*/
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;
/*
* At least on Windows, tm has 9 fields.
* As a workaround, set sunday to 0 and set
* th needed fields to correct value
*/
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(&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);
elm_button_add
Evas_Object * elm_button_add(Evas_Object *parent)
Add a new button to the parent's canvas.
Definition efl_ui_button.c:459
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);
EVAS_HINT_EXPAND
#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
EVAS_HINT_FILL
#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
elm_box_pack_end
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_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition evas_object_main.c:1814
evas_object_size_hint_weight_set
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_object_size_hint_align_set
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_object_smart_callback_add
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
_btn_clear_cb(void *data, Evas_Object *btn EINA_UNUSED, void *ev EINA_UNUSED)
{
Evas_Object *cal = data;
elm_calendar_marks_clear(cal);
elm_calendar_marks_draw(cal);
}
EINA_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition eina_types.h:339

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.