Tizen Native API
5.5
|
In this simple example, we'll explain how to format the label displaying month and year, and also set weekday names.
To format month and year label, we need to create a callback function to create a string given the selected time, declared under a struct tm
.
struct tm
, declared on time.h
, is a structure composed by nine integers:
strftime
. We will get abbreviated month (b) and year (y) (check strftime manpage for more) in our example: static char * _format_month_year(struct tm *format_time) { char buf[32]; /* abbreviates month and year */ if (!strftime(buf, sizeof(buf), "%b %y", format_time)) return NULL; return strdup(buf); }
We need to alloc the string to be returned, and calendar widget will free it when it's not needed, what is done by strdup
. So let's register our callback to calendar object:
elm_calendar_format_function_set(cal, _format_month_year);
To set weekday names, we should declare them as an array of strings:
const char *weekdays[] = { "S", "M", "T", "W", "T", "F", "S" };
And finally set them to calendar:
elm_calendar_weekdays_names_set(cal, weekdays);
Our example will look like this:
See the full source code calendar_example_02::c here.