aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLarry Jr <larry.olj@gmail.com>2016-07-01 20:57:42 -0300
committerVitor Sousa <vitorsousasilva@gmail.com>2016-07-05 14:13:03 -0300
commit132f8f1f375ae8bf376c5b46f04fc67e7986c7d2 (patch)
tree27c94ca7628e2ff1f0ba5dcf83e8575a0eb241e4
parentelementary: add model connect in elm_layout (diff)
downloadefl-132f8f1f375ae8bf376c5b46f04fc67e7986c7d2.tar.gz
elementary: add example layout_model_connect
-rw-r--r--src/examples/elementary/Makefile.am2
-rw-r--r--src/examples/elementary/layout_model_connect.c149
2 files changed, 151 insertions, 0 deletions
diff --git a/src/examples/elementary/Makefile.am b/src/examples/elementary/Makefile.am
index 08f5e13f1c..19b65f7b55 100644
--- a/src/examples/elementary/Makefile.am
+++ b/src/examples/elementary/Makefile.am
@@ -116,6 +116,7 @@ layout_example.edc \
layout_example_01.c \
layout_example_02.c \
layout_example_03.c \
+layout_model_connect.c \
list_example_01.c \
list_example_02.c \
list_example_03.c \
@@ -313,6 +314,7 @@ label_example_01 \
layout_example_01 \
layout_example_02 \
layout_example_03 \
+layout_model_connect \
list_example_01 \
list_example_02 \
list_example_03 \
diff --git a/src/examples/elementary/layout_model_connect.c b/src/examples/elementary/layout_model_connect.c
new file mode 100644
index 0000000000..5cfd43c396
--- /dev/null
+++ b/src/examples/elementary/layout_model_connect.c
@@ -0,0 +1,149 @@
+// gcc -o layout_model_connect layout_model_connect.c `pkg-config --cflags --libs elementary`
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# define EFL_BETA_API_SUPPORT 1
+# define EFL_EO_API_SUPPORT 1
+#endif
+
+#include <Elementary.h>
+#include <Efl.h>
+#include <Eio.h>
+#include <stdio.h>
+#include <Eio.h>
+
+#define EFL_MODEL_TEST_FILENAME_PATH "/tmp"
+
+struct _Layout_Model_Data
+{
+ Eo *fileview;
+ Eo *model;
+ Evas_Object *label;
+ Evas_Object *entry;
+};
+typedef struct _Layout_Model_Data Layout_Model_Data;
+
+static void
+_cleanup_cb(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
+{
+ Layout_Model_Data *priv = (Layout_Model_Data*)data;
+ eo_unref(priv->fileview);
+ eo_unref(priv->model);
+}
+
+static void
+_list_selected_cb(void *data EINA_UNUSED, const Eo_Event *event)
+{
+ Layout_Model_Data *priv = data;
+ Eo *child = event->info;
+
+ printf("LIST selected model\n");
+ efl_ui_view_model_set(priv->label, child);
+ efl_ui_view_model_set(priv->entry, child);
+}
+
+
+static void
+_update_cb(void *data, Evas_Object *obj, void *ev)
+{
+ Layout_Model_Data *priv = data;
+
+ const char *text = elm_object_text_get(priv->entry);
+ elm_layout_text_set(priv->label, "default", text);
+}
+
+static void
+_widget_init(Evas_Object *widget)
+{
+ evas_object_size_hint_weight_set(widget, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(widget);
+}
+
+Evas_Object *
+_label_init(Evas_Object *win, Evas_Object *box, const char *text)
+{
+ Evas_Object *widget = elm_label_add(win);
+ elm_label_line_wrap_set(widget, ELM_WRAP_CHAR);
+ elm_object_text_set(widget, text);
+ elm_box_pack_end(box, widget);
+ evas_object_size_hint_weight_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_size_hint_align_set(widget, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(widget);
+
+ return widget;
+}
+
+EAPI_MAIN int
+elm_main(int argc, char **argv)
+{
+ Layout_Model_Data *priv;
+ Evas_Object *win, *panes, *bxr, *genlist, *bt;
+ char *dirname;
+
+ priv = alloca(sizeof(Layout_Model_Data));
+ memset(priv, 0, sizeof(Layout_Model_Data));
+
+ //win
+ win = elm_win_util_standard_add("viewlist", "Viewlist");
+ elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
+ elm_win_autodel_set(win, EINA_TRUE);
+
+ panes = elm_panes_add(win);
+ evas_object_size_hint_weight_set(panes, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+ elm_win_resize_object_add(win, panes);
+
+ if(argv[1] != NULL) dirname = argv[1];
+ else dirname = EFL_MODEL_TEST_FILENAME_PATH;
+
+ priv->model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(eo_self, dirname));
+
+ genlist = elm_genlist_add(win);
+ priv->fileview = eo_add(ELM_VIEW_LIST_CLASS, NULL, elm_view_list_genlist_set(eo_self, genlist, ELM_GENLIST_ITEM_NONE, NULL));
+ elm_view_list_property_connect(priv->fileview, "filename", "elm.text");
+ elm_view_list_model_set(priv->fileview, priv->model);
+ _widget_init(genlist);
+ elm_object_part_content_set(panes, "left", genlist);
+ elm_obj_panes_content_left_size_set(panes, 0.3);
+ eo_event_callback_add(priv->fileview, ELM_VIEW_LIST_EVENT_MODEL_SELECTED, _list_selected_cb, priv);
+
+ bxr = elm_box_add(win);
+ _widget_init(bxr);
+ elm_object_part_content_set(panes, "right", bxr);
+
+ /*Label widget */
+
+ _label_init(win, bxr, "FILENAME:");
+ priv->label = _label_init(win, bxr, "");
+ efl_ui_model_connect(priv->label, "default", "path"); //connect "default" to "filename" property
+
+ /* Entry widget */
+ priv->entry = elm_entry_add(win);
+ efl_ui_model_connect(priv->entry, "elm.text", "path"); //connect "elm.text" to "path" property
+ elm_entry_single_line_set(priv->entry, EINA_TRUE);
+ elm_box_pack_end(bxr, priv->entry);
+ evas_object_size_hint_weight_set(priv->entry, EVAS_HINT_FILL, 0);
+ evas_object_size_hint_align_set(priv->entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
+ evas_object_show(priv->entry);
+
+ /* Button widget */
+ bt = elm_button_add(win);
+ elm_box_pack_end(bxr, bt);
+ elm_object_text_set(bt, "update model");
+ evas_object_smart_callback_add(bt, "clicked", _update_cb, priv);
+ evas_object_show(bt);
+
+ evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _cleanup_cb, priv);
+ //showall
+ evas_object_resize(win, 800, 400);
+ evas_object_show(panes);
+ evas_object_show(win);
+
+ elm_run();
+ elm_shutdown();
+ ecore_shutdown();
+
+ return 0;
+}
+ELM_MAIN()