Efl.Ui.Clock: Add elm module & theme

Summary: depends on D3938

Reviewers: yashu21985, bu5hm4n, woohyun, Hermet, raster, jpeg

Subscribers: gohwoon.jeong, cedric, seoz, jpeg

Differential Revision: https://phab.enlightenment.org/D3939
This commit is contained in:
Amitesh Singh 2016-11-03 11:59:31 +05:30
parent c425140a67
commit b0d2e987f3
4 changed files with 635 additions and 0 deletions

View File

@ -37,6 +37,7 @@ collections {
#include "edc/elm/photo.edc"
#include "edc/elm/focus.edc"
#include "edc/elm/datetime.edc"
#include "edc/elm/uiclock.edc"
#include "edc/elm/player.edc"
#include "edc/elm/thumb.edc"
#include "edc/elm/pointer.edc"

View File

@ -0,0 +1,207 @@
#define DATETIME_FIELD(_pos) \
part { \
name: "field"#_pos; type: SWALLOW; \
scale: 1; \
clip_to: "clip"; \
description { state: "default" 0.0; \
visible: 0; \
min: 0 0; \
align: 0.0 0.5; \
fixed: 1 1; \
rel1.relative: 1.0 0.0; \
rel1.to: "separator"#_pos; \
rel2.relative: 1.0 1.0; \
rel2.to: "separator"#_pos; \
} \
description { state: "enable" 0.0; \
inherit: "default" 0.0; \
visible: 1; \
min: 8 10; \
} \
} \
programs{ \
program { name: "field_"#_pos"enabled"; \
signal: "field"#_pos",enable"; source: "elm"; \
action: STATE_SET "enable" 0.0; \
target: "field"#_pos; \
} \
program { name: "field_"#_pos"disabled"; \
signal: "field"#_pos",disable"; source: "elm"; \
action: STATE_SET "default" 0.0; \
target: "field"#_pos; \
} \
}
#define DATETIME_SEPARATOR(_pos, _after) \
part { \
name: "separator"#_pos; type: TEXT; \
scale: 1; \
effect: SHADOW BOTTOM; \
clip_to: "disclip"; \
description { state: "default" 0.0; \
visible: 0; \
min: 0 0; \
align: 0.0 0.5; \
fixed: 1 0; \
rel1 { \
relative: 1.0 0.0; \
to: "field"#_after; \
} \
rel2 { \
relative: 1.0 1.0; \
to: "field"#_after; \
} \
color_class: "datetime_separator_text"; \
text { \
font: "Sans"; size: 10; \
min: 1 0; \
ellipsis: -1; \
align: 0.5 0.5; \
text_class: "datetime_separator_text"; \
} \
} \
description { state: "enable" 0.0; \
inherit: "default" 0.0; \
visible: 1; \
min: 8 10; \
} \
} \
part { \
name: "separator"#_pos"d"; type: TEXT; \
scale: 1; \
effect: SHADOW BOTTOM; \
clip_to: "disclip2"; \
description { state: "default" 0.0; \
visible: 0; \
rel1.to: "separator"#_pos; \
rel2.to: "separator"#_pos; \
color_class: "datetime_separator_text_disabled"; \
text { \
text_source: "separator"#_pos; \
font: "Sans"; size: 10; \
text_class: "datetime_separator_text_disabled"; \
} \
} \
description { state: "enable" 0.0; \
inherit: "default" 0.0; \
visible: 1; \
} \
} \
programs { \
program { \
signal: "field"#_after",enable"; source: "elm"; \
action: STATE_SET "enable" 0.0; \
target: "separator"#_pos; \
target: "separator"#_pos"d"; \
} \
program { \
signal: "field"#_after",disable"; source: "elm"; \
action: STATE_SET "default" 0.0; \
target: "separator"#_pos; \
target: "separator"#_pos"d"; \
} \
}
group { name: "elm/uiclock/base/default";
parts {
part { name: "bg"; type: RECT;
description { state: "default" 0.0;
color_class: "datetime_bg";
}
}
part { name: "clip"; type: RECT;
description { state: "default" 0.0;
rel1.to: "separator0";
rel2.to: "separator7";
}
}
part { name: "disclip"; type: RECT;
clip_to: "clip";
description { state: "default" 0.0;
rel1.to: "separator0";
rel2.to: "separator7";
}
description { state: "disabled" 0.0;
inherit: "default" 0.0;
visible: 0;
}
}
part { name: "disclip2"; type: RECT;
clip_to: "clip";
description { state: "default" 0.0;
rel1.to: "separator0";
rel2.to: "separator7";
visible: 0;
}
description { state: "disabled" 0.0;
inherit: "default" 0.0;
visible: 1;
}
}
part { name: "separator0"; type: SPACER;
scale: 1;
description { state: "default" 0.0;
min: 8 10;
align: 0.0 0.5;
fixed: 1 0;
rel2.relative: 0.0 1.0;
}
}
DATETIME_FIELD(0)
DATETIME_SEPARATOR(1,0)
DATETIME_FIELD(1)
DATETIME_SEPARATOR(2,1)
DATETIME_FIELD(2)
DATETIME_SEPARATOR(3,2)
DATETIME_FIELD(3)
DATETIME_SEPARATOR(4,3)
DATETIME_FIELD(4)
DATETIME_SEPARATOR(5,4)
DATETIME_FIELD(5)
DATETIME_SEPARATOR(6,5)
DATETIME_FIELD(6)
DATETIME_SEPARATOR(7,6)
DATETIME_FIELD(7)
DATETIME_SEPARATOR(8,7)
part { name: "separator9"; type: SPACER;
description { state: "default" 0.0;
rel1.to: "separator7";
rel1.relative: 1.0 0.0;
min: 8 10;
}
}
part { name: "discover"; type: RECT;
description { state: "default" 0.0;
rel1.to: "separator0";
rel2.to: "separator7";
visible: 0;
color: 0 0 0 0;
}
description { state: "disabled" 0.0;
inherit: "default" 0.0;
visible: 1;
}
}
part { name: "elm.access"; type: RECT; repeat_events: 1;
description { state: "default" 0.0;
color: 0 0 0 0;
}
}
}
programs {
program {
signal: "elm,state,disabled"; source: "elm";
action: STATE_SET "disabled" 0.0;
target: "disclip";
target: "disclip2";
target: "discover";
}
program {
signal: "elm,state,enabled"; source: "elm";
action: STATE_SET "default" 0.0;
target: "disclip";
target: "disclip2";
target: "discover";
}
}
}
#undef DATETIME_SEPARATOR
#undef DATETIME_FIELD

View File

@ -992,6 +992,34 @@ modules_elementary_datetime_input_ctxpopup_module_la_DEPENDENCIES = @USE_ELEMENT
modules_elementary_datetime_input_ctxpopup_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
modules_elementary_datetime_input_ctxpopup_module_la_LIBTOOLFLAGS = --tag=disable-static
## clock_input_ctxpopup
moduleclock_input_ctxpopuppkgdir = $(libdir)/elementary/modules/clock_input_ctxpopup/$(MODULE_ARCH)
moduleclock_input_ctxpopuppkg_LTLIBRARIES = modules/elementary/clock_input_ctxpopup/module.la
# Workaround for broken parallel install support in automake (relink issue)
# http://debbugs.gnu.org/cgi/bugreport.cgi?bug=7328
install_moduleclock_input_ctxpopuppkgLTLIBRARIES = install-moduleclock_input_ctxpopuppkgLTLIBRARIES
$(install_moduleclock_input_ctxpopuppkgLTLIBRARIES): install-libLTLIBRARIES
modules_elementary_clock_input_ctxpopup_module_la_SOURCES = \
modules/elementary/clock_input_ctxpopup/clock_input_ctxpopup.c
modules_elementary_clock_input_ctxpopup_module_la_CPPFLAGS = \
-DELM_INTERNAL_API_ARGESFSDFEFC=1 \
-I. \
-I$(top_builddir) \
-I$(top_srcdir) \
-I$(top_srcdir)/src/lib/elementary \
-I$(top_builddir)/src/lib/elementary \
-DPACKAGE_DATA_DIR=\"$(pkgdatadir)\" \
-DPACKAGE_LIB_DIR=\"$(libdir)\" \
-DELEMENTARY_BUILD \
@ELEMENTARY_CFLAGS@
modules_elementary_clock_input_ctxpopup_module_la_LIBADD = @USE_ELEMENTARY_LIBS@
modules_elementary_clock_input_ctxpopup_module_la_DEPENDENCIES = @USE_ELEMENTARY_INTERNAL_LIBS@
modules_elementary_clock_input_ctxpopup_module_la_LDFLAGS = -module @EFL_LTMODULE_FLAGS@
modules_elementary_clock_input_ctxpopup_module_la_LIBTOOLFLAGS = --tag=disable-static
## prefs
moduleprefspkgdir = $(libdir)/elementary/modules/prefs/$(MODULE_ARCH)

View File

@ -0,0 +1,399 @@
#ifdef HAVE_CONFIG_H
#include "elementary_config.h"
#endif
#include <Elementary.h>
#include "elm_widget.h"
#include "efl_ui_clock_private.h"
#define CLOCK_FIELD_COUNT 8
#define FIELD_FORMAT_LEN 3
#define DISKSELECTOR_MIN_ITEMS 4
#define BUFF_SIZE 1024
typedef struct _Ctxpopup_Module_Data Ctxpopup_Module_Data;
typedef struct _DiskItem_Data DiskItem_Data;
struct _Ctxpopup_Module_Data
{
Efl_Ui_Clock_Module_Data mod_data;
Evas_Object *ctxpopup;
};
struct _DiskItem_Data
{
Ctxpopup_Module_Data *ctx_mod;
Efl_Ui_Clock_Type sel_field_type;
unsigned int sel_field_value;
};
static void
_diskselector_item_free_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
free(data);
}
static void
_ctxpopup_dismissed_cb(void *data, const Efl_Event *event)
{
Ctxpopup_Module_Data *ctx_mod;
ctx_mod = (Ctxpopup_Module_Data *)data;
evas_object_del(event->object);
ctx_mod->ctxpopup = NULL;
}
static void
_clock_resize_cb(void *data, Evas *e EINA_UNUSED,Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ctxpopup_Module_Data *ctx_mod;
ctx_mod = (Ctxpopup_Module_Data *)data;
if (!ctx_mod || !ctx_mod->ctxpopup) return;
evas_object_hide(ctx_mod->ctxpopup);
}
static void
_clock_move_cb(void *data, Evas *e EINA_UNUSED,Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ctxpopup_Module_Data *ctx_mod;
ctx_mod = (Ctxpopup_Module_Data *)data;
if (!ctx_mod || !ctx_mod->ctxpopup) return;
evas_object_hide(ctx_mod->ctxpopup);
}
static void
_field_value_set(struct tm *tim, Efl_Ui_Clock_Type field_type, int val)
{
if (field_type >= (CLOCK_FIELD_COUNT - 1)) return;
int *timearr[]= { &tim->tm_year, &tim->tm_mon, &tim->tm_mday, &tim->tm_hour,
&tim->tm_min, &tim->tm_sec, &tim->tm_wday };
*timearr[field_type] = val;
}
static int
_field_value_get(struct tm *tim, Efl_Ui_Clock_Type field_type)
{
if (field_type >= (CLOCK_FIELD_COUNT - 1)) return -1;
int *timearr[]= { &tim->tm_year, &tim->tm_mon, &tim->tm_mday, &tim->tm_hour,
&tim->tm_min, &tim->tm_sec, &tim->tm_wday };
return (*timearr[field_type]);
}
static void
_diskselector_cb(void *data EINA_UNUSED, const Efl_Event *event)
{
DiskItem_Data *disk_data;
struct tm curr_time;
const char *fmt;
disk_data = (DiskItem_Data *)elm_object_item_data_get(event->info);
if (!disk_data || !(disk_data->ctx_mod)) return;
efl_ui_clock_value_get(disk_data->ctx_mod->mod_data.base, &curr_time);
fmt = disk_data->ctx_mod->mod_data.field_format_get(disk_data->ctx_mod->mod_data.base, disk_data->sel_field_type);
if ((disk_data->sel_field_type == EFL_UI_CLOCK_TYPE_HOUR) && ((!strncmp(fmt, "%I", FIELD_FORMAT_LEN)) ||
(!strncmp(fmt, "%l", FIELD_FORMAT_LEN))) && (curr_time.tm_hour >= 12))
disk_data->sel_field_value += 12;
_field_value_set(&curr_time, disk_data->sel_field_type, disk_data->sel_field_value);
efl_ui_clock_value_set(disk_data->ctx_mod->mod_data.base, &curr_time);
evas_object_hide(disk_data->ctx_mod->ctxpopup);
}
static void
_ampm_clicked_cb(void *data, const Efl_Event *event EINA_UNUSED)
{
Ctxpopup_Module_Data *ctx_mod;
struct tm curr_time;
ctx_mod = (Ctxpopup_Module_Data *)data;
if (!ctx_mod) return;
efl_ui_clock_value_get(ctx_mod->mod_data.base, &curr_time);
if (curr_time.tm_hour >= 12) curr_time.tm_hour -= 12;
else curr_time.tm_hour += 12;
efl_ui_clock_value_set(ctx_mod->mod_data.base, &curr_time);
}
static void
_field_clicked_cb(void *data, const Efl_Event *event)
{
Ctxpopup_Module_Data *ctx_mod;
Evas_Object *diskselector;
Elm_Object_Item *item;
DiskItem_Data *disk_data;
Efl_Ui_Clock_Type field_type;
time_t t;
struct tm time1;
char buf[BUFF_SIZE], label[BUFF_SIZE];
const char *fmt;
int idx, min, max, val;
unsigned int display_item_num, text_len = 0;
Evas_Coord x = 0, y = 0, w = 0, h = 0, width;
ctx_mod = (Ctxpopup_Module_Data *)data;
if (!ctx_mod) return;
if (!efl_ui_clock_edit_mode_get(ctx_mod->mod_data.base))
return;
snprintf(buf, sizeof(buf), "datetime/%s", elm_object_style_get(event->object));
if (ctx_mod->ctxpopup)
evas_object_del(ctx_mod->ctxpopup);
ctx_mod->ctxpopup = elm_ctxpopup_add(event->object);
elm_object_style_set(ctx_mod->ctxpopup, buf);
elm_ctxpopup_horizontal_set(ctx_mod->ctxpopup, EINA_TRUE);
evas_object_size_hint_weight_set(ctx_mod->ctxpopup, EVAS_HINT_EXPAND,
EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(ctx_mod->ctxpopup, EVAS_HINT_FILL, 0.5);
efl_event_callback_add
(ctx_mod->ctxpopup, ELM_CTXPOPUP_EVENT_DISMISSED, _ctxpopup_dismissed_cb, ctx_mod);
elm_ctxpopup_hover_parent_set(ctx_mod->ctxpopup, elm_widget_top_get(event->object));
diskselector = elm_diskselector_add(elm_widget_top_get(ctx_mod->mod_data.base));
efl_event_callback_add
(diskselector, EFL_UI_EVENT_CLICKED, _diskselector_cb, NULL);
elm_object_style_set(diskselector, buf);
elm_object_content_set(ctx_mod->ctxpopup, diskselector);
t = time(NULL);
localtime_r(&t, &time1);
field_type = (Efl_Ui_Clock_Type )evas_object_data_get(event->object, "_field_type");
fmt = ctx_mod->mod_data.field_format_get(ctx_mod->mod_data.base, field_type);
efl_ui_clock_value_get(ctx_mod->mod_data.base, &time1);
val = _field_value_get(&time1, field_type);
ctx_mod->mod_data.field_limit_get(ctx_mod->mod_data.base, field_type, &min, &max);
time1.tm_mday = 1; // To avoid month wrapping, set the first day of the month to start with.
if ((field_type == EFL_UI_CLOCK_TYPE_HOUR) && ((!strncmp(fmt, "%I", FIELD_FORMAT_LEN)) ||
(!strncmp(fmt, "%l", FIELD_FORMAT_LEN))))
{
if (max >= 12) max -= 12;
if (val >= 12) val -= 12;
if (min >= 12) min -= 12;
}
for (idx = min; idx <= max; idx++)
{
_field_value_set(&time1, field_type, idx);
strftime(label, BUFF_SIZE, fmt, &time1);
if (strlen(label) > text_len) text_len = strlen(label);
if (idx == val)
{
item = elm_diskselector_item_append(diskselector, label, NULL, NULL, NULL);
elm_diskselector_item_selected_set(item, EINA_TRUE);
}
else
{
disk_data = (DiskItem_Data *) malloc (sizeof(DiskItem_Data));
disk_data->ctx_mod = ctx_mod;
disk_data->sel_field_type = field_type;
disk_data->sel_field_value = idx;
item = elm_diskselector_item_append(diskselector, label, NULL, NULL, disk_data);
elm_object_item_del_cb_set(item, _diskselector_item_free_cb);
}
}
elm_diskselector_side_text_max_length_set(diskselector, text_len);
evas_object_geometry_get(event->object, &x, &y, &w, &h);
evas_object_geometry_get(elm_widget_top_get(ctx_mod->mod_data.base), NULL, NULL, &width, NULL);
evas_object_size_hint_min_set(ctx_mod->ctxpopup, width, -1);
display_item_num = width / (w + elm_config_finger_size_get());
// always display even number of items to avoid autoselection
if (display_item_num % 2) display_item_num -= 1;
if (display_item_num < DISKSELECTOR_MIN_ITEMS)
display_item_num = DISKSELECTOR_MIN_ITEMS;
elm_diskselector_display_item_num_set(diskselector, display_item_num);
elm_diskselector_round_enabled_set(diskselector, EINA_TRUE);
elm_ctxpopup_direction_priority_set(ctx_mod->ctxpopup, ELM_CTXPOPUP_DIRECTION_DOWN,
ELM_CTXPOPUP_DIRECTION_UP, -1, -1);
evas_object_move(ctx_mod->ctxpopup, (x+w/2), (y+h));
// if the direction of Ctxpopup is upwards, move it to the top of datetime
if (elm_ctxpopup_direction_get(ctx_mod->ctxpopup) == ELM_CTXPOPUP_DIRECTION_UP)
{
elm_ctxpopup_direction_priority_set(ctx_mod->ctxpopup, ELM_CTXPOPUP_DIRECTION_UP,
ELM_CTXPOPUP_DIRECTION_DOWN, -1, -1);
evas_object_move(ctx_mod->ctxpopup, (x + w / 2), y);
}
evas_object_show(ctx_mod->ctxpopup);
}
static void
_access_set(Evas_Object *obj, Efl_Ui_Clock_Type field_type)
{
const char* type = NULL;
switch (field_type)
{
case EFL_UI_CLOCK_TYPE_YEAR:
type = "datetime field, year";
break;
case EFL_UI_CLOCK_TYPE_MONTH:
type = "datetime field, month";
break;
case EFL_UI_CLOCK_TYPE_DATE:
type = "datetime field, date";
break;
case EFL_UI_CLOCK_TYPE_HOUR:
type = "datetime field, hour";
break;
case EFL_UI_CLOCK_TYPE_MINUTE:
type = "datetime field, minute";
break;
case EFL_UI_CLOCK_TYPE_AMPM:
type = "datetime field, AM PM";
break;
default:
break;
}
_elm_access_text_set
(_elm_access_info_get(obj), ELM_ACCESS_TYPE, type);
_elm_access_callback_set
(_elm_access_info_get(obj), ELM_ACCESS_STATE, NULL, NULL);
}
// module funcs for the specific module type
EAPI void
field_value_display(Efl_Ui_Clock_Module_Data *module_data, Evas_Object *obj)
{
Ctxpopup_Module_Data *ctx_mod;
Efl_Ui_Clock_Type field_type;
struct tm tim;
char buf[BUFF_SIZE];
const char *fmt;
ctx_mod = (Ctxpopup_Module_Data *)module_data;
if (!ctx_mod || !obj) return;
efl_ui_clock_value_get(ctx_mod->mod_data.base, &tim);
field_type = (Efl_Ui_Clock_Type )evas_object_data_get(obj, "_field_type");
fmt = ctx_mod->mod_data.field_format_get(ctx_mod->mod_data.base, field_type);
buf[0] = 0;
strftime(buf, sizeof(buf), fmt, &tim);
if ((!buf[0]) && ((!strcmp(fmt, "%p")) || (!strcmp(fmt, "%P"))))
{
// yes BUFF_SIZE is more than 2 bytes!
if (tim.tm_hour < 12) strcpy(buf, "AM");
else strcpy(buf, "PM");
}
elm_object_text_set(obj, buf);
}
EAPI Evas_Object *
field_create(Efl_Ui_Clock_Module_Data *module_data, Efl_Ui_Clock_Type field_type)
{
Ctxpopup_Module_Data *ctx_mod;
Evas_Object *field_obj;
ctx_mod = (Ctxpopup_Module_Data *)module_data;
if (!ctx_mod) return NULL;
if (field_type == EFL_UI_CLOCK_TYPE_AMPM)
{
field_obj = elm_button_add(ctx_mod->mod_data.base);
efl_event_callback_add
(field_obj, EFL_UI_EVENT_CLICKED, _ampm_clicked_cb, ctx_mod);
}
else
{
field_obj = elm_entry_add(ctx_mod->mod_data.base);
elm_entry_single_line_set(field_obj, EINA_TRUE);
elm_entry_editable_set(field_obj, EINA_FALSE);
elm_entry_input_panel_enabled_set(field_obj, EINA_FALSE);
elm_entry_context_menu_disabled_set(field_obj, EINA_TRUE);
efl_event_callback_add
(field_obj, EFL_UI_EVENT_CLICKED, _field_clicked_cb, ctx_mod);
}
evas_object_data_set(field_obj, "_field_type", (void *)field_type);
// ACCESS
_access_set(field_obj, field_type);
return field_obj;
}
EAPI Efl_Ui_Clock_Module_Data *
obj_hook(Evas_Object *obj)
{
Ctxpopup_Module_Data *ctx_mod;
ctx_mod = calloc(1, sizeof(Ctxpopup_Module_Data));
if (!ctx_mod) return NULL;
evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE,
_clock_resize_cb, ctx_mod);
evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE,
_clock_move_cb, ctx_mod);
return ((Efl_Ui_Clock_Module_Data*)ctx_mod);
}
EAPI void
obj_unhook(Efl_Ui_Clock_Module_Data *module_data)
{
Ctxpopup_Module_Data *ctx_mod;
ctx_mod = (Ctxpopup_Module_Data *)module_data;
if (!ctx_mod) return;
if (ctx_mod->ctxpopup)
evas_object_del(ctx_mod->ctxpopup);
free(ctx_mod);
ctx_mod = NULL;
}
EAPI void
obj_hide(Efl_Ui_Clock_Module_Data *module_data)
{
Ctxpopup_Module_Data *ctx_mod;
ctx_mod = (Ctxpopup_Module_Data *)module_data;
if (!ctx_mod) return;
if (ctx_mod->ctxpopup)
evas_object_hide(ctx_mod->ctxpopup);
}
// module api funcs needed
EAPI int
elm_modapi_init(void *m EINA_UNUSED)
{
return 1; // succeed always
}
EAPI int
elm_modapi_shutdown(void *m EINA_UNUSED)
{
return 1; // succeed always
}
static Eina_Bool
_module_init(void)
{
return EINA_TRUE;
}
static void
_module_shutdown(void)
{
}
EINA_MODULE_INIT(_module_init);
EINA_MODULE_SHUTDOWN(_module_shutdown);