edje: add min: SOURCE, max: SOURCE.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 26 Jan 2012 18:24:00 +0000 (18:24 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 26 Jan 2012 18:24:00 +0000 (18:24 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/edje@67555 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

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

index 59f4566..1d11974 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 2012-01-25  Cedric Bail
 
        * Only store the image used by active group.
+
+2012-01-26  Cedric Bail
+
+       * Add min: SOURCE, max: SOURCE.
diff --git a/NEWS b/NEWS
index 018ab72..9496046 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,10 +5,11 @@ Changes since Edje 1.1.0:
 
 Additions:
 
-    * "recalc" smart callback for object size changes
+    * "recalc" smart callback for object size changes.
     * EDJE_ASPECT_PREFER_SOURCE.
     * edje.version() Lua function.
-    * minmul edc property
+    * minmul edc property.
+    * add min: SOURCE and max: SOURCE.
 
 Improvements:
     * speedup load time of Edje file.
index a3c6992..635c401 100644 (file)
@@ -4633,18 +4633,40 @@ st_collections_group_parts_part_description_fixed(void)
     @property
         min
     @parameters
-        [width] [height]
+        [width] [height] or SOURCE
     @effect
         The minimum size of the state.
+
+        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.
     @endproperty
 */
 static void
 st_collections_group_parts_part_description_min(void)
 {
-   check_arg_count(2);
+   check_min_arg_count(1);
 
-   current_desc->min.w = parse_float_range(0, 0, 0x7fffffff);
-   current_desc->min.h = parse_float_range(1, 0, 0x7fffffff);
+   if (is_param(1)) {
+      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 ||
+          !tmp || strcmp(tmp, "SOURCE") != 0)
+        {
+           ERR("%s: Error. parse error %s:%i. "
+               "Only IMAGE 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;
+   }
 }
 
 /**
@@ -4673,18 +4695,40 @@ st_collections_group_parts_part_description_minmul(void)
     @property
         max
     @parameters
-        [width] [height]
+        [width] [height] or SOURCE
     @effect
         The maximum size of the state. A size of -1.0 means that it will be ignored in one direction.
+
+        When max is set to SOURCE, edje will enforce the part to be
+        not more than the original image size. The part must be an
+        IMAGE part.
     @endproperty
 */
 static void
 st_collections_group_parts_part_description_max(void)
 {
-   check_arg_count(2);
+   check_min_arg_count(1);
 
-   current_desc->max.w = parse_float_range(0, -1.0, 0x7fffffff);
-   current_desc->max.h = parse_float_range(1, -1.0, 0x7fffffff);
+   if (is_param(1)) {
+      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);
+      if (current_part->type != EDJE_PART_TYPE_IMAGE ||
+          !tmp || strcmp(tmp, "SOURCE") != 0)
+        {
+           ERR("%s: Error. parse error %s:%i. "
+               "Only IMAGE part can have a max: SOURCE; defined",
+               progname, file_in, line - 1);
+           exit(-1);
+        }
+
+      desc = (Edje_Part_Description_Image *) current_desc;
+      desc->image.max.limit = EINA_TRUE;
+   }
 }
 
 /**
index 582cc85..67c889b 100644 (file)
@@ -1746,7 +1746,6 @@ _edje_part_recalc_single_min_max(FLOAT_T sc,
           }
      }
 
-
    /* XXX TODO: remove need of EDJE_INF_MAX_H, see edje_util.c */
    if ((ep->swallow_params.max.h <= 0) ||
        (ep->swallow_params.max.h == EDJE_INF_MAX_H))
@@ -1959,6 +1958,30 @@ _edje_part_recalc_single(Edje *ed,
              if (lminh > minh) minh = lminh;
           }
      }
+   else if ((ep->part->type == EDJE_PART_TYPE_BOX) &&
+           ((((Edje_Part_Description_Image *)chosen_desc)->image.min.limit) ||
+             (((Edje_Part_Description_Image *)chosen_desc)->image.max.limit)))
+     {
+        Evas_Coord w, h;
+
+        /* We only need pos to find the right image that would be displayed */
+        /* Yes, if someone set aspect preference to SOURCE and also max,min
+           to SOURCE, it will be under efficient, but who cares at the
+           moment. */
+        _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 (w > minw) minw = w;
+             if (h > minh) minh = h;
+          }
+        if (((Edje_Part_Description_Image *)chosen_desc)->image.max.limit)
+          {
+             if (w < maxw) maxw = w;
+             if (h < maxh) maxh = h;
+          }
+     }
 
    /* remember what our size is BEFORE we go limit it */
    params->req.x = params->x;
index 8bf18eb..ada8370 100644 (file)
@@ -839,7 +839,7 @@ struct _Edje_Part_Description_Common
       unsigned char have;
       FLOAT_T w, h;
    } minmul;
-   
+
    Edje_Size min, max;
    Edje_Position step; /* size stepping by n pixels, 0 = none */
    Edje_Aspect_Prefer aspect;
@@ -913,6 +913,9 @@ 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;
 };