Item : initial version
authorJin Yoon <jinny.yoon@samsung.com>
Tue, 14 Jul 2015 02:45:22 +0000 (11:45 +0900)
committerJin Yoon <jinny.yoon@samsung.com>
Tue, 14 Jul 2015 02:45:22 +0000 (11:45 +0900)
inc/item.h [new file with mode: 0644]
inc/item_info.h [new file with mode: 0644]
inc/scroller.h
res/edje/item.edc [new file with mode: 0644]
src/initial.c
src/item.c [new file with mode: 0644]
src/item_info.c [new file with mode: 0644]
src/loading.c

diff --git a/inc/item.h b/inc/item.h
new file mode 100644 (file)
index 0000000..ecfe389
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __ITEM_H__
+#define __ITEM_H__
+
+#include <Elementary.h>
+#include "item_info.h"
+
+extern Evas_Object *item_create(Evas_Object *parent, item_info_s *item_info);
+extern void item_destroy(Evas_Object *item);
+
+#endif /* __ITEM_H__ */
diff --git a/inc/item_info.h b/inc/item_info.h
new file mode 100644 (file)
index 0000000..1a2cbf6
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef __ITEM_INFO_H__
+#define __ITEM_INFO_H__
+
+struct _item_info_s {
+       /* Innate features */
+       char *id;
+       char *name;
+       char *icon_path;
+
+       /* Acquire features */
+       Evas_Object *icon;
+       int width;
+       int height;
+};
+typedef struct _item_info_s item_info_s;
+
+extern item_info_s *item_info_create(const char *id);
+extern void item_info_destroy(item_info_s *item_info);
+
+#endif /* __ITEM_INFO_H__ */
index bb2168f..beb7c62 100644 (file)
@@ -1,3 +1,6 @@
+#ifndef __SCROLLER_INFO_H__
+#define __SCROLLER_INFO_H__
+
 #include <Elementary.h>
 
 typedef enum {
@@ -18,3 +21,5 @@ extern void scroller_bring_in_item(Evas_Object *scroller, Evas_Object *item);
 
 extern int scroller_register_event_cb(Evas_Object *scroller, int event_type, void (*event_cb)(Evas_Object *scroller, int event_type, void *event_info, void *user_data), void *user_data);
 extern int scroller_unregister_event_cb(Evas_Object *scroller, int event_type, void (*event_cb)(Evas_Object *scroller, int event_type, void *event_info, void *user_data));
+
+#endif /* __SCROLLER_INFO_H__ */
diff --git a/res/edje/item.edc b/res/edje/item.edc
new file mode 100644 (file)
index 0000000..660bbb5
--- /dev/null
@@ -0,0 +1,78 @@
+
+styles {
+       style {
+               /* Font size is changed from 24 to 20 because of resolution issues. */
+               name: "text_style";
+               base: "font=Tizen:style=Regular font_size=20 color=#ffffff align=center style=shadow shadow_color=#000000bf wrap=mixed ellipsis=-1";
+               tag:  "br" "\n";
+               tag:  "hilight" "+ font_weight=Bold";
+               tag:  "b" "+ font_weight=Bold";
+               tag:  "tab" "\t";
+       }
+}
+
+collections {
+       base_scale: 1.7;
+       group {
+               name: "item";
+               parts {
+                       part {
+                               name: "bg";
+                               type: SWALLOW;
+                               mouse_events: 1;
+                               description {
+                                       state: "default" 0.0;
+                                       rel1 { relative: 0.0 0.0; }
+                                       rel2 { relative: 1.0 1.0; }
+                               }
+                       }
+                       part {
+                               name: "icon";
+                               type: SWALLOW;
+                               mouse_events: 1;
+                               scale: 1;
+                               description {
+                                       state: "default" 0.0;
+                                       rel1 { relative: 0.1 0.1; to: "bg"; }
+                                       rel2 { relative: 0.9 0.66; to: "bg"; }
+                                       color: 255 255 255 255;
+                                       visible: 1;
+                               }
+                               description {
+                                       state: "pressed" 0.0;
+                                       inherit: "default" 0.0;
+                                       color: 100 100 100 255;
+                               }
+                       }
+                       part {
+                               name: "name";
+                               type: TEXTBLOCK;
+                               mouse_events: 1;
+                               scale: 1;
+                               description {
+                                       state: "default" 0.0;
+                                       rel1 { relative: 0.0 0.7; to: "bg"; }
+                                       rel2 { relative: 1.0 1.0; to: "bg"; }
+                                       align: 0.5 0.0;
+                                       color: 0 0 0 100;
+                                       text {
+                                               style: "text_style";
+                                               align: 0.5 0.0;
+                                       }
+                                       visible: 1;
+                               }
+                       }
+                       part {
+                               name: "button";
+                               type: SWALLOW;
+                               mouse_events: 1;
+                               description {
+                                       state: "default" 0.0;
+                                       rel1 { relative: 0.0 0.0; to: "bg"; }
+                                       rel2 { relative: 1.0 1.0; to: "bg"; }
+                                       visible: 1;
+                               }
+                       }
+               } //parts
+       }
+} //collections
index 4ed8d23..08acf8a 100644 (file)
@@ -3,7 +3,7 @@
 #include "log.h"
 #include "util.h"
 
-const char *const INITIAL_EDC = "initial.edj";
+const char *const INITIAL_EDJE = "initial.edj";
 
 
 
@@ -19,7 +19,8 @@ Evas_Object *initial_create(Evas_Object *parent, int width, int height)
        path = app_get_resource_path();
        retv_if(!path, NULL);
 
-       snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, INITIAL_EDC);
+       snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, INITIAL_EDJE);
+       free(path);
 
        initial = elm_layout_add(parent);
        retv_if(!initial, NULL);
diff --git a/src/item.c b/src/item.c
new file mode 100644 (file)
index 0000000..8a468c2
--- /dev/null
@@ -0,0 +1,143 @@
+#include <Elementary.h>
+#include <app.h>
+
+#include "util.h"
+#include "log.h"
+#include "item.h"
+#include "item_info.h"
+
+
+
+#define DEFAULT_ICON "/usr/share/icons/A01-1_icon_Menu.png"
+#define ITEM_ICON_WIDTH 112
+#define ITEM_ICON_HEIGHT 112
+
+
+
+const char *const ITEM_EDJE = "item.edj";
+
+
+
+static Evas_Object *__add_icon(Evas_Object *parent, const char *file)
+{
+       Evas_Object *icon = NULL;
+
+       retv_if(!parent, NULL);
+
+       icon = elm_icon_add(parent);
+       retv_if(!icon, NULL);
+
+       if (elm_image_file_set(icon, file, NULL) == EINA_FALSE) {
+               _E("Icon file is not accessible (%s)", file);
+               evas_object_del(icon);
+               return NULL;
+       }
+
+       evas_object_size_hint_min_set(icon, ELM_SCALE_SIZE(ITEM_ICON_WIDTH), ELM_SCALE_SIZE(ITEM_ICON_HEIGHT));
+
+       elm_image_preload_disabled_set(icon, EINA_TRUE);
+       elm_image_smooth_set(icon, EINA_TRUE);
+       elm_image_no_scale_set(icon, EINA_FALSE);
+       evas_object_show(icon);
+
+       return icon;
+}
+
+
+
+static void __item_clicked_cb(void *data, Evas_Object *obj, void *event_info)
+{
+       item_info_s *item_info = data;
+
+       ret_if(!item_info);
+}
+
+
+
+Evas_Object *item_create(Evas_Object *parent, item_info_s *item_info)
+{
+       Evas_Object *item = NULL;
+       Evas_Object *item_bg = NULL;
+       Evas_Object *icon = NULL;
+       Evas_Object *button = NULL;
+       Evas *e = NULL;
+
+       char *path = NULL;
+       char *name = NULL;
+       char full_path[PATH_LEN] = {0, };
+
+       retv_if(!parent, NULL);
+
+       path = app_get_resource_path();
+       retv_if(!path, NULL);
+
+       snprintf(full_path, sizeof(full_path), "%s/edje/%s", path, ITEM_EDJE);
+       free(path);
+
+       item = elm_layout_add(parent);
+       retv_if(!item, NULL);
+       elm_layout_file_set(item, full_path, "item");
+
+       e = evas_object_evas_get(parent);
+       goto_if(!e, ERROR);
+
+       item_bg = evas_object_rectangle_add(e);
+       goto_if(!item_bg, ERROR);
+       evas_object_size_hint_weight_set(item_bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_size_hint_min_set(item_bg, ELM_SCALE_SIZE(item_info->width), ELM_SCALE_SIZE(item_info->height));
+       evas_object_color_set(item_bg, 0, 0, 0, 0);
+       evas_object_repeat_events_set(item_bg, EINA_TRUE);
+       evas_object_show(item_bg);
+       elm_object_part_content_set(item, "bg", item_bg);
+       evas_object_show(item);
+
+       icon = __add_icon(item, item_info->icon_path);
+       goto_if(!icon, ERROR);
+       elm_object_part_content_set(item, "icon", icon);
+
+       name = item_info->name;
+       goto_if(!name, ERROR);
+       elm_object_part_text_set(item, "name", name);
+
+       button = elm_button_add(item);
+       goto_if(!button, ERROR);
+
+       elm_object_style_set(button, "focus");
+       elm_object_part_content_set(item, "button", button);
+       evas_object_size_hint_weight_set(button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+       evas_object_show(button);
+       evas_object_smart_callback_add(button, "clicked", __item_clicked_cb, item_info);
+
+       return item;
+
+ERROR:
+       item_destroy(item);
+       return NULL;
+
+}
+
+
+
+void item_destroy(Evas_Object *item)
+{
+       Evas_Object *bg = NULL;
+       Evas_Object *button = NULL;
+       Evas_Object *icon = NULL;
+
+       ret_if(!item);
+
+       button = elm_object_part_content_unset(item, "button");
+       if (button) {
+               evas_object_smart_callback_del(button, "clicked", __item_clicked_cb);
+       }
+
+       icon = elm_object_part_content_unset(item, "icon");
+       if (icon) {
+               evas_object_del(icon);
+       }
+       bg = elm_object_part_content_unset(item, "bg");
+       if (bg) {
+               evas_object_del(bg);
+       }
+       evas_object_del(item);
+}
diff --git a/src/item_info.c b/src/item_info.c
new file mode 100644 (file)
index 0000000..d85c1d1
--- /dev/null
@@ -0,0 +1,28 @@
+#include <Evas.h>
+#include <Elementary.h>
+
+#include "util.h"
+#include "log.h"
+#include "item_info.h"
+
+
+
+item_info_s *item_info_create(const char *id)
+{
+       item_info_s *item_info = NULL;
+
+       retv_if(!id, NULL);
+
+       item_info = calloc(1, sizeof(item_info_s));
+       retv_if(!item_info, NULL);
+
+       return item_info;
+}
+
+
+
+void item_info_destroy(item_info_s *item_info)
+{
+       ret_if(!item_info);
+       free(item_info);
+}
index cbd2fce..bbfc711 100644 (file)
@@ -4,6 +4,8 @@
 #include "adventure.h"
 #include "util.h"
 
+
+
 Evas_Object *loading_create(Evas_Object *parent, int width, int height)
 {
        Evas_Object *loading = NULL;
@@ -16,6 +18,7 @@ Evas_Object *loading_create(Evas_Object *parent, int width, int height)
        retv_if(!path, NULL);
 
        snprintf(full_path, sizeof(full_path), "%s/edje/loading.edj", path);
+       free(path);
 
        loading = elm_layout_add(parent);
        goto_if(!loading, error);
@@ -26,11 +29,9 @@ Evas_Object *loading_create(Evas_Object *parent, int width, int height)
        evas_object_size_hint_min_set(loading, width, height);
        evas_object_show(loading);
 
-       free(path);
        return loading;
 
 error:
-       free(path);
        return NULL;
 }