elm grid obj++
authorraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 18 May 2011 07:15:36 +0000 (07:15 +0000)
committerraster <raster@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Wed, 18 May 2011 07:15:36 +0000 (07:15 +0000)
git-svn-id: https://svn.enlightenment.org/svn/e/trunk/elementary@59483 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/bin/Makefile.am
src/bin/test.c
src/bin/test_grid.c [new file with mode: 0644]
src/lib/Elementary.h.in
src/lib/Makefile.am
src/lib/elm_grid.c [new file with mode: 0644]

index c7276a5..b9ec11f 100644 (file)
@@ -97,7 +97,8 @@ test_tooltip.c \
 test_transit.c \
 test_weather.c \
 test_win_inline.c \
-test_win_state.c
+test_win_state.c \
+test_grid.c
 
 elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la \
        @ELEMENTARY_EWEATHER_LIBS@ \
index eb0a430..d0825b2 100644 (file)
@@ -125,6 +125,7 @@ void test_bubble(void *data, Evas_Object *obj, void *event_info);
 void test_segment_control(void *data, Evas_Object *obj, void *event_info);
 void test_store(void *data, Evas_Object *obj, void *event_info);
 void test_win_inline(void *data, Evas_Object *obj, void *event_info);
+void test_grid(void *data, Evas_Object *obj, void *event_info);
 
 struct elm_test
 {
@@ -382,6 +383,7 @@ my_win_main(char *autorun)
    ADD_TEST("Segment Control", test_segment_control);
    ADD_TEST("Store", test_store);
    ADD_TEST("Window Inline", test_win_inline);
+   ADD_TEST("Grid", test_grid);
 #undef ADD_TEST
 
    if (autorun)
diff --git a/src/bin/test_grid.c b/src/bin/test_grid.c
new file mode 100644 (file)
index 0000000..688968b
--- /dev/null
@@ -0,0 +1,101 @@
+#include <Elementary.h>
+#ifdef HAVE_CONFIG_H
+# include "elementary_config.h"
+#endif
+#ifndef ELM_LIB_QUICKLAUNCH
+static void
+_ch_grid(void *data __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
+{
+   int x, y, w, h;
+   
+   elm_grid_pack_get(obj, &x, &y, &w, &h);
+   elm_grid_pack_set(obj, x - 1, y - 1, w + 2, h + 2);
+}
+
+void
+test_grid(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
+{
+   Evas_Object *win, *bg, *gd, *bt, *rc, *en;
+
+   win = elm_win_add(NULL, "grid", ELM_WIN_BASIC);
+   elm_win_title_set(win, "Grid");
+   elm_win_autodel_set(win, 1);
+
+   bg = elm_bg_add(win);
+   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   elm_win_resize_object_add(win, bg);
+   evas_object_show(bg);
+
+   gd = elm_grid_add(win);
+   elm_grid_size_set(gd, 100, 100);
+   elm_win_resize_object_add(win, gd);
+   evas_object_size_hint_weight_set(gd, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_show(gd);
+
+   en = elm_scrolled_entry_add(win);
+   elm_scrolled_entry_entry_set(en, "Entry text");
+   elm_scrolled_entry_single_line_set(en, 1);
+   elm_grid_pack(gd, en, 50, 10, 40, 10);
+   evas_object_show(en);
+   
+   en = elm_scrolled_entry_add(win);
+   elm_scrolled_entry_entry_set(en, "Entry text 2");
+   elm_scrolled_entry_single_line_set(en, 1);
+   elm_grid_pack(gd, en, 60, 20, 30, 10);
+   evas_object_show(en);
+   
+   bt = elm_button_add(win);
+   elm_button_label_set(bt, "Button");
+   elm_grid_pack(gd, bt,  0,  0, 20, 20);
+   evas_object_show(bt);
+
+   bt = elm_button_add(win);
+   elm_button_label_set(bt, "Button");
+   elm_grid_pack(gd, bt, 10, 10, 40, 20);
+   evas_object_show(bt);
+
+   bt = elm_button_add(win);
+   elm_button_label_set(bt, "Button");
+   elm_grid_pack(gd, bt, 10, 30, 20, 50);
+   evas_object_show(bt);
+
+   bt = elm_button_add(win);
+   elm_button_label_set(bt, "Button");
+   elm_grid_pack(gd, bt, 80, 80, 20, 20);
+   evas_object_show(bt);
+
+   bt = elm_button_add(win);
+   elm_button_label_set(bt, "Change");
+   elm_grid_pack(gd, bt, 40, 40, 20, 20);
+   evas_object_smart_callback_add(bt, "clicked", _ch_grid, gd);
+   evas_object_show(bt);
+   
+   rc = evas_object_rectangle_add(evas_object_evas_get(win));
+   evas_object_color_set(rc, 128, 0, 0, 128);
+   elm_grid_pack(gd, rc, 40, 70, 20, 10);
+   evas_object_show(rc);
+
+   rc = evas_object_rectangle_add(evas_object_evas_get(win));
+   evas_object_color_set(rc, 0, 128, 0, 128);
+   elm_grid_pack(gd, rc, 60, 70, 10, 10);
+   evas_object_show(rc);
+
+   rc = evas_object_rectangle_add(evas_object_evas_get(win));
+   evas_object_color_set(rc, 0, 0, 128, 128);
+   elm_grid_pack(gd, rc, 40, 80, 10, 10);
+   evas_object_show(rc);
+
+   rc = evas_object_rectangle_add(evas_object_evas_get(win));
+   evas_object_color_set(rc, 128, 0, 128, 128);
+   elm_grid_pack(gd, rc, 50, 80, 10, 10);
+   evas_object_show(rc);
+
+   rc = evas_object_rectangle_add(evas_object_evas_get(win));
+   evas_object_color_set(rc, 128, 64, 0, 128);
+   elm_grid_pack(gd, rc, 60, 80, 10, 10);
+   evas_object_show(rc);
+
+   evas_object_resize(win, 480, 480);
+   evas_object_show(win);
+}
+#endif
index c3078ed..472f49a 100644 (file)
@@ -2984,7 +2984,16 @@ extern "C" {
     *            selected and get selected. The event_info parameter is the
     *            segment item index.
     */
-
+   
+   EAPI Evas_Object *elm_grid_add(Evas_Object *parent);
+   EAPI void         elm_grid_size_set(Evas_Object *obj, int w, int h);
+   EAPI void         elm_grid_size_get(Evas_Object *obj, int *w, int *h);
+   EAPI void         elm_grid_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h);
+   EAPI void         elm_grid_unpack(Evas_Object *obj, Evas_Object *subobj);
+   EAPI void         elm_grid_clear(Evas_Object *obj, Eina_Bool clear);
+   EAPI void         elm_grid_pack_set(Evas_Object *subobj, int x, int y, int w, int h);
+   EAPI void         elm_grid_pack_get(Evas_Object *subobj, int *x, int *y, int *w, int *h);
+         
 #ifdef __cplusplus
 }
 #endif
index 895c9c6..5d94f3b 100644 (file)
@@ -67,6 +67,7 @@ elm_font.c \
 elm_frame.c \
 elm_gengrid.c \
 elm_genlist.c \
+elm_grid.c \
 elm_hover.c \
 elm_icon.c \
 elm_image.c \
diff --git a/src/lib/elm_grid.c b/src/lib/elm_grid.c
new file mode 100644 (file)
index 0000000..c64bce5
--- /dev/null
@@ -0,0 +1,220 @@
+#include <Elementary.h>
+#include "elm_priv.h"
+
+/**
+ * @defgroup Grid Grid
+ *
+ * The grid is a grid layout widget that lays out a series of children as a
+ * fixed "grid" of widgets using a given percentage of the grid width and
+ * height each using the child object.
+ * 
+ * The Grid uses a "Virtual resolution" that is stretched to fill the grid
+ * widgets size itself. The default is 100 x 100, so that means the
+ * position and sizes of children will effectively be percentages (0 to 100)
+ * of the width or height of the grid widget
+ *
+ */
+
+typedef struct _Widget_Data Widget_Data;
+
+struct _Widget_Data
+{
+   Evas_Object *obj, *grd;
+};
+
+static const char *widtype = NULL;
+static void _del_hook(Evas_Object *obj);
+static void _theme_hook(Evas_Object *obj);
+
+static void
+_del_hook(Evas_Object *obj)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   free(wd);
+}
+
+static void 
+_mirrored_set(Evas_Object *obj, Eina_Bool rtl)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if ((!wd) || (!wd->grd)) return;
+   evas_object_grid_mirrored_set(wd->grd, rtl);
+}
+
+static void
+_theme_hook(Evas_Object *obj)
+{
+   _elm_widget_mirrored_reload(obj);
+   _mirrored_set(obj, elm_widget_mirrored_get(obj));
+}
+
+/**
+ * Add a new grid to the parent
+ *
+ * @param parent The parent object
+ * @return The new object or NULL if it cannot be created
+ *
+ * @ingroup Grid
+ */
+EAPI Evas_Object *
+elm_grid_add(Evas_Object *parent)
+{
+   Evas_Object *obj;
+   Evas *e;
+   Widget_Data *wd;
+
+   ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
+
+   ELM_SET_WIDTYPE(widtype, "grid");
+   wd->obj = obj;
+   elm_widget_type_set(obj, "grid");
+   elm_widget_sub_object_add(parent, obj);
+   elm_widget_data_set(obj, wd);
+   elm_widget_del_hook_set(obj, _del_hook);
+   elm_widget_theme_hook_set(obj, _theme_hook);
+   elm_widget_can_focus_set(obj, EINA_FALSE);
+
+   wd->grd = evas_object_grid_add(e);
+   evas_object_grid_size_set(wd->grd, 100, 100);
+   elm_widget_resize_object_set(obj, wd->grd);
+   return obj;
+}
+
+/**
+ * Set the virtual size of the grid
+ *
+ * @param obj The grid object
+ * @param w The virtual width of the grid
+ * @param h The virtual height of the grid
+ *
+ * @ingroup Grid
+ */
+EAPI void
+elm_grid_size_set(Evas_Object *obj, int w, int h)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   evas_object_grid_size_set(wd->grd, w, h);
+}
+
+/**
+ * Get the virtual size of the grid
+ * 
+ * @param obj The grid object
+ * @param w Pointer to integer to store the virtual width of the grid
+ * @param h Pointer to integer to store the virtual height of the grid
+ *
+ * @ingroup Grid
+ */
+EAPI void
+elm_grid_size_get(Evas_Object *obj, int *w, int *h)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   evas_object_grid_size_get(wd->grd, w, h);
+}
+
+/**
+ * Pack child at given position and size
+ *
+ * @param obj The grid object
+ * @param subobj The child to pack
+ * @param x The virtual x coord at which to pack it
+ * @param y The virtual y coord at which to pack it
+ * @param w The virtual width at which to pack it
+ * @param h The virtual height at which to pack it
+ *
+ * @ingroup Grid
+ */
+EAPI void
+elm_grid_pack(Evas_Object *obj, Evas_Object *subobj, int x, int y, int w, int h)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
+}
+
+/**
+ * Unpack a child from a grid object
+ * 
+ * @param obj The grid object
+ * @param subobj The child to unpack
+ * 
+ * @ingroup Grid
+ */ 
+EAPI void
+elm_grid_unpack(Evas_Object *obj, Evas_Object *subobj)
+{
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   elm_widget_sub_object_del(obj, subobj);
+   evas_object_grid_unpack(wd->grd, subobj);
+}
+
+/**
+ * Faster way to remove all child objects from a grid object.
+ *
+ * @param obj The grid object
+ * @param clear If true, it will delete just removed children
+ *
+ * @ingroup Grid
+ */
+EAPI void
+elm_grid_clear(Evas_Object *obj, Eina_Bool clear)
+{
+   Eina_List *chld;
+   Evas_Object *o;
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   chld = evas_object_grid_children_get(wd->grd);
+   EINA_LIST_FREE(chld, o) elm_widget_sub_object_del(obj, o);
+   evas_object_grid_clear(wd->grd, clear);
+}
+
+/**
+ * Set packing of an existing child at to position and size
+ *
+ * @param subobj The child to set packing of
+ * @param x The virtual x coord at which to pack it
+ * @param y The virtual y coord at which to pack it
+ * @param w The virtual width at which to pack it
+ * @param h The virtual height at which to pack it
+ *
+ * @ingroup Grid
+ */
+EAPI void
+elm_grid_pack_set(Evas_Object *subobj, int x, int y, int w, int h)
+{
+   Evas_Object *obj = elm_widget_parent_widget_get(subobj);
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   evas_object_grid_pack(wd->grd, subobj, x, y, w, h);
+}
+
+/**
+ * get packing of a child
+ *
+ * @param subobj The child to query
+ * @param x Pointer to integer to store the virtual x coord
+ * @param y Pointer to integer to store the virtual y coord
+ * @param w Pointer to integer to store the virtual width
+ * @param h Pointer to integer to store the virtual height
+ *
+ * @ingroup Grid
+ */
+EAPI void
+elm_grid_pack_get(Evas_Object *subobj, int *x, int *y, int *w, int *h)
+{
+   Evas_Object *obj = elm_widget_parent_widget_get(subobj);
+   ELM_CHECK_WIDTYPE(obj, widtype);
+   Widget_Data *wd = elm_widget_data_get(obj);
+   if (!wd) return;
+   evas_object_grid_pack_get(wd->grd, subobj, x, y, w, h);
+}