edje: add automatic hints update to edje object and min: SOURCE to GROUP part.
authorcedric <cedric>
Mon, 12 Mar 2012 15:28:58 +0000 (15:28 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Mon, 12 Mar 2012 15:28:58 +0000 (15:28 +0000)
NOTE: turning this feature on is costly. Do that only when you require it, really !

git-svn-id: http://svn.enlightenment.org/svn/e/trunk/edje@69254 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
NEWS
src/bin/edje_cc_handlers.c
src/lib/Edje.h
src/lib/edje_calc.c
src/lib/edje_data.c
src/lib/edje_private.h
src/lib/edje_util.c

index d86c212..87de11e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 2012-03-11  Cedric Bail
 
        * Propagate scale factor to GROUP's part.
+
+2012-03-12  Cedric Bail
+
+       * Make it possible for edje to update size hint automatically.
+       * Add min: SOURCE to GROUP's part.
diff --git a/NEWS b/NEWS
index 49933d0..3f6dbe9 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,10 +9,11 @@ Additions:
     * EDJE_ASPECT_PREFER_SOURCE.
     * edje.version() Lua function.
     * minmul edc property.
-    * add min: SOURCE and max: SOURCE.
+    * add min: SOURCE and max: SOURCE to IMAGE and GROUP parts.
     * add edje_object_markup_filter_callback_add/del/delfull().
     * add broadcast_signal: bool.
     * add edje_object_part_text_imf_context_get()
+    * add edje_object_update_hints_set() and edje_object_update_hints_get()
 
 Improvements:
     * speedup load time of Edje file.
index f299114..14ac0b7 100644 (file)
@@ -4665,7 +4665,7 @@ st_collections_group_parts_part_description_fixed(void)
 
         When min is defined to SOURCE, it will look at the original
         image size and enforce it minimal size to match at least the
-        original one. The part must be an IMAGE part.
+        original one. The part must be an IMAGE or a GROUP part.
     @endproperty
 */
 static void
@@ -4677,21 +4677,19 @@ st_collections_group_parts_part_description_min(void)
       current_desc->min.w = parse_float_range(0, 0, 0x7fffffff);
       current_desc->min.h = parse_float_range(1, 0, 0x7fffffff);
    } else {
-      Edje_Part_Description_Image *desc;
       char *tmp;
 
       tmp = parse_str(0);
-      if (current_part->type != EDJE_PART_TYPE_IMAGE ||
+      if ((current_part->type != EDJE_PART_TYPE_IMAGE && current_part->type != EDJE_PART_TYPE_GROUP) ||
           !tmp || strcmp(tmp, "SOURCE") != 0)
         {
            ERR("%s: Error. parse error %s:%i. "
-               "Only IMAGE part can have a min: SOURCE; defined",
+               "Only IMAGE and GROUP part can have a min: SOURCE; defined",
                progname, file_in, line - 1);
            exit(-1);
         }
 
-      desc = (Edje_Part_Description_Image *) current_desc;
-      desc->image.min.limit = EINA_TRUE;
+      current_desc->min.limit = EINA_TRUE;
    }
 }
 
@@ -4739,7 +4737,6 @@ st_collections_group_parts_part_description_max(void)
       current_desc->max.w = parse_float_range(0, -1.0, 0x7fffffff);
       current_desc->max.h = parse_float_range(1, -1.0, 0x7fffffff);
    } else {
-      Edje_Part_Description_Image *desc;
       char *tmp;
 
       tmp = parse_str(0);
@@ -4752,8 +4749,7 @@ st_collections_group_parts_part_description_max(void)
            exit(-1);
         }
 
-      desc = (Edje_Part_Description_Image *) current_desc;
-      desc->image.max.limit = EINA_TRUE;
+      current_desc->max.limit = EINA_TRUE;
    }
 }
 
index 45a6461..1f8014e 100644 (file)
@@ -2237,6 +2237,27 @@ EAPI Eina_Bool    edje_object_text_class_set          (Evas_Object *obj, const c
 EAPI void         edje_object_size_min_get            (const Evas_Object *obj, Evas_Coord *minw, Evas_Coord *minh);
 
 /**
+ * @brief Edje will automatically update the size hints on itself.
+ *
+ * @param obj A handle to an Edje object.
+ * @param update Wether or not update the size hints.
+ *
+ * By default edje doesn't set size hints on itself. With this function
+ * call, it will do so if update is true. Be carefull, it cost a lot to
+ * trigger this feature as it will recalc the object every time it make
+ * sense to be sure that's its minimal size hint is always accurate.
+ */
+EAPI void edje_object_update_hints_set(Evas_Object *obj, Eina_Bool update);
+
+/**
+ * @brief Wether or not Edje will update size hints on itself.
+ *
+ * @param obj A handle to an Edje object.
+ * @return @c true if does, @c false if it doesn't.
+ */
+EAPI Eina_Bool edje_object_update_hints_get(Evas_Object *obj);
+
+/**
  * @brief Get the maximum size specified -- as an EDC property -- for a
  * given Edje object
  *
index 5df066f..6aa6336 100644 (file)
@@ -110,7 +110,7 @@ _edje_part_pos_set(Edje *ed, Edje_Real_Part *ep, int mode, FLOAT_T pos, FLOAT_T
         npos = fp_pos;
         break;
      }
-#endif   
+#endif
    if (npos == ep->description_pos) return;
 
    ep->description_pos = npos;
@@ -572,6 +572,7 @@ _edje_part_description_apply(Edje *ed, Edje_Real_Part *ep, const char *d1, doubl
        ep->part->type == EDJE_PART_TYPE_EXTERNAL)
      _edje_external_recalc_apply(ed, ep, NULL, chosen_desc);
 
+   ed->recalc_hints = 1;
    ed->dirty = 1;
    ed->recalc_call = 1;
 #ifdef EDJE_CALC_CACHE
@@ -650,6 +651,16 @@ _edje_recalc_do(Edje *ed)
    else
      evas_object_smart_need_recalculate_set(ed->obj, need_calc);
    ed->recalc_call = 0;
+
+   if (ed->update_hints && ed->recalc_hints && !ed->calc_only)
+     {
+        Evas_Coord w, h;
+
+        ed->recalc_hints = 0;
+
+        edje_object_size_min_calc(ed->obj, &w, &h);
+        evas_object_size_hint_min_set(ed->obj, w, h);
+     }
 }
 
 void
@@ -1959,8 +1970,7 @@ _edje_part_recalc_single(Edje *ed,
           }
      }
    else if ((ep->part->type == EDJE_PART_TYPE_IMAGE) &&
-           ((((Edje_Part_Description_Image *)chosen_desc)->image.min.limit) ||
-             (((Edje_Part_Description_Image *)chosen_desc)->image.max.limit)))
+           (chosen_desc->min.limit || chosen_desc->max.limit))
      {
         Evas_Coord w, h;
 
@@ -1971,12 +1981,12 @@ _edje_part_recalc_single(Edje *ed,
         _edje_real_part_image_set(ed, ep, pos);
         evas_object_image_size_get(ep->object, &w, &h);
 
-        if (((Edje_Part_Description_Image *)chosen_desc)->image.min.limit)
+        if (chosen_desc->min.limit)
           {
              if (w > minw) minw = w;
              if (h > minh) minh = h;
           }
-        if (((Edje_Part_Description_Image *)chosen_desc)->image.max.limit)
+        if (chosen_desc->max.limit)
           {
              if ((maxw <= 0) || (w < maxw)) maxw = w;
              if ((maxh <= 0) || (h < maxh)) maxh = h;
@@ -2286,7 +2296,18 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
    if (ep->part->scale &&
        ep->part->type == EDJE_PART_TYPE_GROUP &&
        ep->swallowed_object)
-     edje_object_scale_set(ep->swallowed_object, TO_DOUBLE(ed->scale));
+     {
+        edje_object_scale_set(ep->swallowed_object, TO_DOUBLE(ed->scale));
+
+        if (ep->description_pos > FROM_DOUBLE(0.5) && ep->param2)
+          {
+             edje_object_update_hints_set(ep->swallowed_object, ep->param2->description->min.limit);
+          }
+        else
+          {
+             edje_object_update_hints_set(ep->swallowed_object, ep->param1.description->min.limit);
+          }
+     }
 
 #ifdef EDJE_CALC_CACHE
    if (ep->state == ed->state && !state)
index e8451a2..46fd521 100644 (file)
@@ -456,8 +456,10 @@ _edje_edd_init(void)
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "minmul.h", minmul.h, EDJE_T_FLOAT); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "min.w", min.w, EET_T_INT); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "min.h", min.h, EET_T_INT); \
+      EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "min.limit", min.limit, EET_T_UCHAR); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "max.w", max.w, EET_T_INT); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "max.h", max.h, EET_T_INT); \
+      EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "max.limit", max.limit, EET_T_UCHAR); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "step.x", step.x, EET_T_INT); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "step.y", step.y, EET_T_INT); \
       EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "aspect.min", aspect.min, EDJE_T_FLOAT); \
@@ -586,8 +588,6 @@ _edje_edd_init(void)
 
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.id", image.id, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.set", image.set, EET_T_UCHAR);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.min.limit", image.min.limit, EET_T_UCHAR);
-   EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.max.limit", image.max.limit, EET_T_UCHAR);
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.border.l", image.border.l, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.border.r", image.border.r, EET_T_INT);
    EET_DATA_DESCRIPTOR_ADD_BASIC(_edje_edd_edje_part_description_image, Edje_Part_Description_Image, "image.border.t", image.border.t, EET_T_INT);
index 8fbc4af..0fb0be6 100644 (file)
@@ -232,6 +232,7 @@ struct _Edje_Position
 struct _Edje_Size
 {
    int w, h;
+   Eina_Bool limit; /* should we limit ourself to the size of the source */
 };
 
 struct _Edje_Rectangle
@@ -932,9 +933,6 @@ struct _Edje_Part_Description_Spec_Image
    int            id; /* the image id to use */
    int            scale_hint; /* evas scale hint */
    Eina_Bool      set; /* if image condition it's content */
-   struct {
-      Eina_Bool   limit; /* should we limit ourself to the size of the image */
-   } min, max;
 
    Edje_Part_Description_Spec_Border border;
 };
@@ -1168,6 +1166,8 @@ struct _Edje
 #endif
    unsigned int          have_mapped_part : 1;
    unsigned int          recalc_call : 1;
+   unsigned int          update_hints : 1;
+   unsigned int          recalc_hints : 1;
 };
 
 struct _Edje_Calc_Params
index 53bb5bd..14b23e2 100644 (file)
@@ -1014,6 +1014,7 @@ _edje_object_part_text_raw_set(Evas_Object *obj, Edje_Real_Part *rp, const char
      if (text) rp->text.text = eina_stringshare_add(text);
    rp->edje->dirty = 1;
    rp->edje->recalc_call = 1;
+   rp->edje->recalc_hints = 1;
 #ifdef EDJE_CALC_CACHE
    rp->invalidate = 1;
 #endif
@@ -1076,6 +1077,7 @@ edje_object_part_text_style_user_push(Evas_Object *obj, const char *part,
    evas_textblock_style_set(ts, style);
    evas_object_textblock_style_user_push(rp->object, ts);
    evas_textblock_style_free(ts);
+   ed->recalc_hints = 1;
 }
 
 EAPI void
@@ -1091,6 +1093,7 @@ edje_object_part_text_style_user_pop(Evas_Object *obj, const char *part)
    if (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK) return;
 
    evas_object_textblock_style_user_pop(rp->object);
+   ed->recalc_hints = 1;
 }
 
 EAPI const char *
@@ -1373,6 +1376,7 @@ edje_object_part_text_insert(Evas_Object *obj, const char *part, const char *tex
    _edje_entry_text_markup_insert(rp, text);
    rp->edje->dirty = 1;
    rp->edje->recalc_call = 1;
+   rp->edje->recalc_hints = 1;
 #ifdef EDJE_CALC_CACHE
    rp->invalidate = 1;
 #endif
@@ -1395,6 +1399,7 @@ edje_object_part_text_append(Evas_Object *obj, const char *part, const char *tex
    _edje_object_part_text_raw_append(obj, rp, part, text);
    rp->edje->dirty = 1;
    rp->edje->recalc_call = 1;
+   rp->edje->recalc_hints = 1;
 #ifdef EDJE_CALC_CACHE
    rp->invalidate = 1;
 #endif
@@ -2808,6 +2813,7 @@ edje_object_size_min_restricted_calc(Evas_Object *obj, Evas_Coord *minw, Evas_Co
             maxh = 0;
          }
        pep = NULL;
+       has_non_fixed_tb = EINA_FALSE;
        for (i = 0; i < ed->table_parts_size; i++)
          {
             Edje_Real_Part *ep;
@@ -3946,6 +3952,30 @@ edje_object_preload(Evas_Object *obj, Eina_Bool cancel)
    return EINA_TRUE;
 }
 
+EAPI void
+edje_object_update_hints_set(Evas_Object *obj, Eina_Bool update)
+{
+   Edje *ed;
+
+   ed = _edje_fetch(obj);
+   if (!ed) return ;
+   if (ed->update_hints == !!update) return ;
+
+   ed->update_hints = !!update;
+   if (update) ed->recalc_hints = 1;
+}
+
+EAPI Eina_Bool
+edje_object_update_hints_get(Evas_Object *obj)
+{
+   Edje *ed;
+
+   ed = _edje_fetch(obj);
+   if (!ed) return EINA_FALSE;
+
+   return ed->update_hints;
+}
+
 Eina_Bool
 _edje_real_part_table_pack(Edje_Real_Part *rp, Evas_Object *child_obj, unsigned short col, unsigned short row, unsigned short colspan, unsigned short rowspan)
 {
@@ -4503,6 +4533,7 @@ _edje_real_part_swallow(Edje_Real_Part *rp,
                _edje_real_part_swallow_hints_update(rp);
              rp->edje->dirty = 1;
              rp->edje->recalc_call = 1;
+             rp->edje->recalc_hints = 1;
              _edje_recalc(rp->edje);
              return;
           }
@@ -4547,6 +4578,7 @@ _edje_real_part_swallow(Edje_Real_Part *rp,
 
    rp->edje->dirty = 1;
    rp->edje->recalc_call = 1;
+   rp->edje->recalc_hints = 1;
    _edje_recalc(rp->edje);
 }