This is lame...  Another try.

On Fri, Jan 22, 2010 at 10:24 AM, Brian Wang <brian.wang.0...@gmail.com> wrote:
> Hello all,
>
> The attached (hopefully, it's attached) is my try to implement the
> homogeneous mode for elm_genlist.  I know it's far from perfect (e.g.
> it still walks through the list to gather the width and height) and it
> might contain bugs.   It's ok with valgrind reports on x86 though.
>
> The patch is also contaminated with my elm_button autorepeat stuff in
> Elementary.h.in...
>
> I know it's far from being perfect, so please take a look and modify
> it to its correctness as it seems to be a nice-to-have feature.
>
> Cheers,
>
>
> brian
>
> --
> brian
> ------------------
>
> Cool-Karaoke - The smallest recording studio, in your palm, open-sourced
> http://cool-idea.com.tw/
>
> iMaGiNaTiOn iS mOrE iMpOrTaNt tHaN kNoWlEdGe
>



-- 
brian
------------------

Cool-Karaoke - The smallest recording studio, in your palm, open-sourced
http://cool-idea.com.tw/

iMaGiNaTiOn iS mOrE iMpOrTaNt tHaN kNoWlEdGe
Index: lib/Elementary.h.in
===================================================================
--- lib/Elementary.h.in (revision 45349)
+++ lib/Elementary.h.in (working copy)
@@ -374,6 +374,9 @@
    EAPI const char  *elm_button_label_get(Evas_Object *obj);
    EAPI void         elm_button_icon_set(Evas_Object *obj, Evas_Object *icon);
    EAPI Evas_Object *elm_button_icon_get(Evas_Object *obj);
+   EAPI void         elm_button_autorepeat_set(Evas_Object *obj, Eina_Bool on);
+   EAPI void         elm_button_autorepeat_initital_timeout_set(Evas_Object 
*obj, double t);
+   EAPI void         elm_button_autorepeat_gap_timeout_set(Evas_Object *obj, 
double t);
    EINA_DEPRECATED EAPI void elm_button_style_set(Evas_Object *obj, const char 
*style);
    /* available styles:
     * default
@@ -383,6 +386,7 @@
     */
    /* smart callbacks called:
     * "clicked" - the user clicked the button
+    * "repeated" - the user pressed the button without releasing it
     */
 
    typedef enum _Elm_Scroller_Policy
@@ -882,6 +886,8 @@
    EAPI void              elm_genlist_no_select_mode_set(Evas_Object *obj, 
Eina_Bool no_select);
    EAPI void              elm_genlist_compress_mode_set(Evas_Object *obj, 
Eina_Bool compress);
    EAPI void              elm_genlist_bounce_set(Evas_Object *obj, Eina_Bool 
h_bounce, Eina_Bool v_bounce);
+   EAPI void              elm_genlist_homogeneous_set(Evas_Object *obj, 
Eina_Bool homogeneous);
+   EAPI void              elm_genlist_block_count_set(Evas_Object *obj, int n);
    /* available item styles:
     * default
     * default_style - The text part is a textblock
Index: lib/elm_genlist.c
===================================================================
--- lib/elm_genlist.c   (revision 45349)
+++ lib/elm_genlist.c   (working copy)
@@ -1,3 +1,7 @@
+/*
+ *
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
 #include <Elementary.h>
 #include "elm_priv.h"
 
@@ -237,6 +241,7 @@
  * have a specific style that overrides any theme the user or system sets up
  * you can use elm_theme_overlay_add() to add such a file.
  */
+
 typedef struct _Widget_Data Widget_Data;
 typedef struct _Item_Block Item_Block;
 typedef struct _Pan Pan;
@@ -260,6 +265,10 @@
    Eina_Bool no_select : 1;
    Eina_Bool bring_in : 1;
    Eina_Bool compress : 1;
+   Eina_Bool homogeneous : 1;
+   int item_width;
+   int item_height;
+   int max_items_per_block;
 };
 
 struct _Item_Block
@@ -736,71 +745,91 @@
          edje_object_signal_emit(it->base, "elm,state,expanded", "elm");
      }
 
-   if (it->itc->func.label_get)
+   if (calc && it->wd->homogeneous && it->wd->item_width)
      {
-       const Eina_List *l;
-       const char *key;
+       /* homogenous genlist shortcut */
+       if (!it->mincalcd)
+         {
+            it->w = it->minw = it->wd->item_width;
+            it->h = it->minh = it->wd->item_height;
+            it->mincalcd = EINA_TRUE;
+         }
+     }
+   else
+     {
 
-       it->labels = _stringlist_get(edje_object_data_get(it->base, "labels"));
-       EINA_LIST_FOREACH(it->labels, l, key)
+       if (it->itc->func.label_get)
          {
-            char *s = it->itc->func.label_get(it->data, it->wd->obj, l->data);
+            const Eina_List *l;
+            const char *key;
 
-            if (s)
+            it->labels = _stringlist_get(edje_object_data_get(it->base, 
"labels"));
+            EINA_LIST_FOREACH(it->labels, l, key)
               {
-                 edje_object_part_text_set(it->base, l->data, s);
-                 free(s);
+                 char *s = it->itc->func.label_get(it->data, it->wd->obj, 
l->data);
+
+                 if (s)
+                   {
+                      edje_object_part_text_set(it->base, l->data, s);
+                      free(s);
+                   }
               }
          }
-     }
-   if (it->itc->func.icon_get)
-     {
-       const Eina_List *l;
-       const char *key;
+       if (it->itc->func.icon_get)
+         {
+            const Eina_List *l;
+            const char *key;
 
-       it->icons = _stringlist_get(edje_object_data_get(it->base, "icons"));
-       EINA_LIST_FOREACH(it->icons, l, key)
+            it->icons = _stringlist_get(edje_object_data_get(it->base, 
"icons"));
+            EINA_LIST_FOREACH(it->icons, l, key)
+              {
+                 Evas_Object *ic = it->itc->func.icon_get(it->data, 
it->wd->obj, l->data);
+
+                 if (ic)
+                   {
+                      it->icon_objs = eina_list_append(it->icon_objs, ic);
+                      edje_object_part_swallow(it->base, key, ic);
+                      evas_object_show(ic);
+                      elm_widget_sub_object_add(it->wd->obj, ic);
+                   }
+              }
+         }
+       if (it->itc->func.state_get)
          {
-            Evas_Object *ic = it->itc->func.icon_get(it->data, it->wd->obj, 
l->data);
+            const Eina_List *l;
+            const char *key;
 
-            if (ic)
+            it->states = _stringlist_get(edje_object_data_get(it->base, 
"states"));
+            EINA_LIST_FOREACH(it->states, l, key)
               {
-                 it->icon_objs = eina_list_append(it->icon_objs, ic);
-                 edje_object_part_swallow(it->base, key, ic);
-                 evas_object_show(ic);
-                 elm_widget_sub_object_add(it->wd->obj, ic);
+                 Eina_Bool on = it->itc->func.state_get(it->data, it->wd->obj, 
l->data);
+
+                 if (on)
+                   {
+                      snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
+                      edje_object_signal_emit(it->base, buf, "elm");
+                   }
               }
          }
-     }
-   if (it->itc->func.state_get)
-     {
-       const Eina_List *l;
-       const char *key;
-
-       it->states = _stringlist_get(edje_object_data_get(it->base, "states"));
-       EINA_LIST_FOREACH(it->states, l, key)
+       if (!it->mincalcd)
          {
-            Eina_Bool on = it->itc->func.state_get(it->data, it->wd->obj, 
l->data);
+            Evas_Coord mw = -1, mh = -1;
 
-            if (on)
+            elm_coords_finger_size_adjust(1, &mw, 1, &mh);
+            edje_object_size_min_restricted_calc(it->base, &mw, &mh, mw, mh);
+            elm_coords_finger_size_adjust(1, &mw, 1, &mh);
+            it->w = it->minw = mw;
+            it->h = it->minh = mh;
+            it->mincalcd = EINA_TRUE;
+
+            if (in == 0 && it->wd->homogeneous)
               {
-                 snprintf(buf, sizeof(buf), "elm,state,%s,active", key);
-                 edje_object_signal_emit(it->base, buf, "elm");
+                 it->wd->item_width = mw;
+                 it->wd->item_height = mh;
               }
          }
+       if (!calc) evas_object_show(it->base);
      }
-   if (!it->mincalcd)
-     {
-       Evas_Coord mw = -1, mh = -1;
-
-       elm_coords_finger_size_adjust(1, &mw, 1, &mh);
-       edje_object_size_min_restricted_calc(it->base, &mw, &mh, mw, mh);
-       elm_coords_finger_size_adjust(1, &mw, 1, &mh);
-       it->w = it->minw = mw;
-       it->h = it->minh = mh;
-       it->mincalcd = EINA_TRUE;
-     }
-   if (!calc) evas_object_show(it->base);
    it->realized = EINA_TRUE;
 }
 
@@ -1302,6 +1331,7 @@
 
    wd->obj = obj;
    wd->mode = ELM_LIST_SCROLL;
+   wd->max_items_per_block = 32;
 
    evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj);
    evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj);
@@ -1493,7 +1523,7 @@
                  if (wd->blocks)
                    {
                       itb = (Item_Block *)(wd->blocks);
-                      if (itb->count >= 32)
+                      if (itb->count >= wd->max_items_per_block)
                         {
                            itb = calloc(1, sizeof(Item_Block));
                            if (!itb) return;
@@ -1518,7 +1548,7 @@
                  if (wd->blocks)
                    {
                       itb = (Item_Block *)(wd->blocks->last);
-                      if (itb->count >= 32)
+                      if (itb->count >= wd->max_items_per_block)
                         {
                            itb = calloc(1, sizeof(Item_Block));
                            if (!itb) return;
@@ -1561,7 +1591,7 @@
          _item_del(it->rel);
        it->rel = NULL;
      }
-   if (itb->count > 32)
+   if (itb->count > itb->wd->max_items_per_block)
      {
         int newc;
         Item_Block *itb2;
@@ -2710,3 +2740,43 @@
    Widget_Data *wd = elm_widget_data_get(obj);
    elm_smart_scroller_bounce_allow_set(wd->scr, h_bounce, v_bounce);
 }
+
+/**
+ * Set homogenous mode
+ *
+ * This will enable the homogeneous mode where items are of the same height 
and width
+ * so that genlist may do the lazy-loading at its maximum.  This implies 
'compressed' mode
+ *
+ * @param obj The genlist object
+ * @param homogeneous Assume the items within the genlist are of the same 
height and width
+ *
+ * @ingroup Genlist
+ */
+EAPI void
+elm_genlist_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+
+   if (homogeneous)
+      elm_genlist_compress_mode_set(obj, 1);
+   wd->homogeneous = homogeneous;
+}
+
+/**
+ * Set the maximum number of items within an item block
+ *
+ * This will configure the block count to tune to the target with particular 
performance matrix.
+ *
+ * @param obj The genlist object
+ * @param n   Maximum number of items within an item block
+ *
+ * @ingroup Genlist
+ */
+EAPI void
+elm_genlist_block_count_set(Evas_Object *obj, int n)
+{
+   Widget_Data *wd = elm_widget_data_get(obj);
+   wd->max_items_per_block = n;
+}
+
+
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to