Evas: Move aspect ratio to Efl.Gfx.Size.Hint
authorJean-Philippe Andre <jp.andre@samsung.com>
Wed, 8 Jun 2016 05:56:51 +0000 (14:56 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Wed, 8 Jun 2016 06:14:11 +0000 (15:14 +0900)
Problem:
- edje aspect ratio is defined by 1 enum and 2 double (min, max)
- window aspect ratio is defined by only 1 double
- evas object aspect ratio is defined by 1 enum and 2 ints (w, h)

Which one is the best interface? Are min/max a better option?

Also, not sure how to call the enum...

src/lib/efl/interfaces/efl_gfx_size_hint.eo
src/lib/efl/interfaces/efl_gfx_types.eot
src/lib/evas/Evas_Common.h
src/lib/evas/Evas_Legacy.h
src/lib/evas/canvas/evas_object.eo
src/lib/evas/canvas/evas_object_main.c
src/lib/evas/canvas/evas_types.eot

index 6e86fbc..fb53e83 100644 (file)
@@ -1,4 +1,7 @@
-interface Efl.Gfx.Size.Hint {
+import efl_gfx_types;
+
+interface Efl.Gfx.Size.Hint
+{
    methods {
       @property base {
          set {
@@ -38,5 +41,44 @@ interface Efl.Gfx.Size.Hint {
             h: int; [[The stepping height (0 disables).]]
          }
       }
+      @property aspect {
+         [[Defines the aspect ratio to respect when scaling this object.
+
+           The aspect ratio is defined as the width / height ratio of the
+           object. Depending on the object and its container, this hint may
+           or may not be fully respected.
+
+           If any of the given aspect ratio terms are 0, the object's container
+           will ignore the aspect and scale this object to occupy the whole
+           available area, for any given policy.
+         ]]
+         /*
+         @image html any-policy.png
+         @image rtf any-policy.png
+         @image latex any-policy.eps
+
+         @image html aspect-control-none-neither.png
+         @image rtf aspect-control-none-neither.png
+         @image latex aspect-control-none-neither.eps
+
+         @image html aspect-control-both.png
+         @image rtf aspect-control-both.png
+         @image latex aspect-control-both.eps
+
+         @image html aspect-control-horizontal.png
+         @image rtf aspect-control-horizontal.png
+         @image latex aspect-control-horizontal.eps
+         */
+         values {
+            mode: Efl.Gfx.Size.Hint.Aspect; [[Mode of interpretation.]]
+            w: int;
+            h: int;
+
+            /* FIXME: do we want min/max like Edje instead??
+            min: double; [[Default: 0.0 (no preference).]]
+            max: double @optional; [[Default: 0.0, may be ignored.]]
+            */
+         }
+      }
    }
 }
index 86b860b..9821784 100644 (file)
@@ -174,3 +174,22 @@ struct Efl.Gfx.Event.Render_Post
    updated_area: list <Eina.Rectangle>; [[A list of rectangles that were
                                           updated in the canvas.]]
 }
+
+enum Efl.Gfx.Size.Hint.Aspect
+{
+   [[Aspect types/policies for scaling size hints.
+
+     See also $Efl.Gfx.Size.Hint.aspect.
+   ]]
+
+   none = 0, [[No preference on either direction of the container
+               for aspect ratio control.]]
+   neither = 1, [[Same effect as disabling aspect ratio preference]]
+   horizontal = 2, [[Use all horizontal container space to place an object,
+                     using the given aspect.]]
+   vertical = 3, [[Use all vertical container space to place an object, using
+                   the given aspect.]]
+   both = 4 [[Use all horizontal and vertical container spaces to place an
+              object (never growing it out of those bounds), using the given
+              aspect.]]
+}
index f793264..5e6a17b 100644 (file)
@@ -355,6 +355,14 @@ typedef Efl_Event_Flags                    Evas_Event_Flags;
 #define EVAS_EVENT_FLAG_ON_HOLD            EFL_EVENT_FLAGS_ON_HOLD
 #define EVAS_EVENT_FLAG_ON_SCROLL          EFL_EVENT_FLAGS_ON_SCROLL
 
+typedef Efl_Gfx_Size_Hint_Aspect           Evas_Aspect_Control; /**< Aspect types/policies for scaling size hints, used for evas_object_size_hint_aspect_set */
+
+#define EVAS_ASPECT_CONTROL_NONE           EFL_GFX_SIZE_HINT_ASPECT_NONE
+#define EVAS_ASPECT_CONTROL_NEITHER        EFL_GFX_SIZE_HINT_ASPECT_NEITHER
+#define EVAS_ASPECT_CONTROL_HORIZONTAL     EFL_GFX_SIZE_HINT_ASPECT_HORIZONTAL
+#define EVAS_ASPECT_CONTROL_VERTICAL       EFL_GFX_SIZE_HINT_ASPECT_VERTICAL
+#define EVAS_ASPECT_CONTROL_BOTH           EFL_GFX_SIZE_HINT_ASPECT_BOTH
+
 struct _Evas_Engine_Info /** Generic engine information. Generic info is useless */
 {
    int magic; /**< Magic number */
index f4d1998..dc65965 100644 (file)
@@ -858,6 +858,50 @@ EAPI void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
 EAPI Eina_Bool evas_object_visible_get(const Evas_Object *obj);
 
 /**
+ * @brief Sets the hints for an object's aspect ratio.
+ *
+ * This is not a size enforcement in any way, it's just a hint that should be
+ * used whenever appropriate.
+ *
+ * If any of the given aspect ratio terms are 0, the object's container will
+ * ignore the aspect and scale @c obj to occupy the whole available area, for
+ * any given policy.
+ *
+ * @note Smart objects(such as elementary) can have their own size hint policy.
+ * So calling this API may or may not affect the size of smart objects.
+ *
+ * @param[in] aspect The policy/type of aspect ratio to apply to @c obj.
+ * @param[in] w Integer to use as aspect width ratio term.
+ * @param[in] h Integer to use as aspect height ratio term.
+ *
+ * @ingroup Evas_Object
+ */
+EAPI void evas_object_size_hint_aspect_set(Evas_Object *obj, Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h);
+
+/**
+ * @brief Retrieves the hints for an object's aspect ratio.
+ *
+ * The different aspect ratio policies are documented in the
+ * #Evas_Aspect_Control type. A container respecting these size hints would
+ * resize its children accordingly to those policies.
+ *
+ * For any policy, if any of the given aspect ratio terms are 0, the object's
+ * container should ignore the aspect and scale @c obj to occupy the whole
+ * available area. If they are both positive integers, that proportion will be
+ * respected, under each scaling policy.
+ *
+ * @note Use @c null pointers on the hint components you're not interested in:
+ * they'll be ignored by the function.
+ *
+ * @param[out] aspect The policy/type of aspect ratio to apply to @c obj.
+ * @param[out] w Integer to use as aspect width ratio term.
+ * @param[out] h Integer to use as aspect height ratio term.
+ *
+ * @ingroup Evas_Object
+ */
+EAPI void evas_object_size_hint_aspect_get(const Evas_Object *obj, Evas_Aspect_Control *aspect, Evas_Coord *w, Evas_Coord *h);
+
+/**
  *
  * Sets the layer of its canvas that the given object will be part of.
  *
index 2bc9d56..cda5c35 100644 (file)
@@ -1,7 +1,7 @@
 import evas_types;
 
 abstract Evas.Object (Eo.Base, Evas.Common_Interface, Efl.Gfx, Efl.Gfx.Stack,
-                      Efl.Animator, Efl.Input.Interface)
+                      Efl.Animator, Efl.Input.Interface, Efl.Gfx.Size.Hint)
 {
    legacy_prefix: evas_object;
    eo_prefix: evas_obj;
@@ -304,74 +304,6 @@ abstract Evas.Object (Eo.Base, Evas.Common_Interface, Efl.Gfx, Efl.Gfx.Stack,
             map: const(Evas.Map)*; [[The map.]]
          }
       }
-      @property size_hint_aspect {
-         set {
-            [[Sets the hints for an object's aspect ratio.
-
-              This is not a size enforcement in any way, it's just a hint
-              that should be used whenever appropriate.
-
-              If any of the given aspect ratio terms are 0, the object's
-              container will ignore the aspect and scale $obj to occupy
-              the whole available area, for any given policy.
-
-              Note: Smart objects(such as elementary) can have their own
-              size hint policy. So calling this API may or may not affect
-              the size of smart objects.
-            ]]
-         }
-         get {
-            [[Retrieves the hints for an object's aspect ratio.
-
-              The different aspect ratio policies are documented in the
-              #Evas_Aspect_Control type. A container respecting these size
-              hints would resize its children accordingly to those policies.
-
-              For any policy, if any of the given aspect ratio terms are 0,
-              the object's container should ignore the aspect and scale $obj
-              to occupy the whole available area. If they are both positive
-              integers, that proportion will be respected, under each
-              scaling policy.
-
-              Note: Use $null pointers on the hint components you're not
-              interested in: they'll be ignored by the function.
-            ]]
-            /* FIXME-doc
-            These images illustrate some of the #Evas_Aspect_Control policies:
-
-            @image html any-policy.png
-            @image rtf any-policy.png
-            @image latex any-policy.eps
-
-            @image html aspect-control-none-neither.png
-            @image rtf aspect-control-none-neither.png
-            @image latex aspect-control-none-neither.eps
-
-            @image html aspect-control-both.png
-            @image rtf aspect-control-both.png
-            @image latex aspect-control-both.eps
-
-            @image html aspect-control-horizontal.png
-            @image rtf aspect-control-horizontal.png
-            @image latex aspect-control-horizontal.eps
-
-            This is not a size enforcement in any way, it's just a hint that
-            should be used whenever appropriate.
-            ---
-            Example:
-            @dontinclude evas-aspect-hints.c
-            @skip if (strcmp(ev->key, "c") == 0)
-            @until }
-
-            See the full @ref Example_Evas_Aspect_Hints "example".
-            */
-         }
-         values {
-            aspect: Evas.Aspect_Control; [[The policy/type of aspect ratio to apply to $obj.]]
-            w: Evas.Coord; [[Integer to use as aspect width ratio term.]]
-            h: Evas.Coord; [[Integer to use as aspect height ratio term.]]
-         }
-      }
       @property clip {
          set {
             [[Clip one object to another.
@@ -1246,6 +1178,8 @@ abstract Evas.Object (Eo.Base, Evas.Common_Interface, Efl.Gfx, Efl.Gfx.Stack,
       Efl.Gfx.Stack.stack_above;
       Efl.Gfx.Stack.raise;
       Efl.Gfx.Stack.lower;
+      Efl.Gfx.Size.Hint.aspect.set;
+      Efl.Gfx.Size.Hint.aspect.get;
    }
    events {
        /* FIXME: remove events from Efl.Input.Interface */
index 7e2950a..bef3774 100644 (file)
@@ -1185,7 +1185,7 @@ _evas_object_size_hint_request_set(Eo *eo_obj, Evas_Object_Protected_Data *obj,
 }
 
 EOLIAN static void
-_evas_object_size_hint_aspect_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj, Evas_Aspect_Control *aspect, Evas_Coord *w, Evas_Coord *h)
+_evas_object_efl_gfx_size_hint_aspect_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_Data *obj, Efl_Gfx_Size_Hint_Aspect *aspect, Evas_Coord *w, Evas_Coord *h)
 {
    if ((!obj->size_hints) || obj->delete_me)
      {
@@ -1200,7 +1200,7 @@ _evas_object_size_hint_aspect_get(Eo *eo_obj EINA_UNUSED, Evas_Object_Protected_
 }
 
 EOLIAN static void
-_evas_object_size_hint_aspect_set(Eo *eo_obj, Evas_Object_Protected_Data *obj, Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h)
+_evas_object_efl_gfx_size_hint_aspect_set(Eo *eo_obj, Evas_Object_Protected_Data *obj, Efl_Gfx_Size_Hint_Aspect aspect, Evas_Coord w, Evas_Coord h)
 {
    if (obj->delete_me)
      return;
@@ -2131,5 +2131,19 @@ _evas_object_legacy_ctor(Eo *eo_obj, Evas_Object_Protected_Data *obj)
    obj->legacy = EINA_TRUE;
 }
 
+/* legacy */
+
+EAPI void
+evas_object_size_hint_aspect_set(Evas_Object *obj, Evas_Aspect_Control aspect, Evas_Coord w, Evas_Coord h)
+{
+   efl_gfx_size_hint_aspect_set(obj, aspect, w, h);
+}
+
+EAPI void
+evas_object_size_hint_aspect_get(const Evas_Object *obj, Evas_Aspect_Control *aspect, Evas_Coord *w, Evas_Coord *h)
+{
+   efl_gfx_size_hint_aspect_get(obj, aspect, w, h);
+}
+
 #include "canvas/evas_object.eo.c"
 
index fcfcc83..b89d876 100644 (file)
@@ -6,19 +6,6 @@ struct Evas.Native_Surface; [[A generic datatype for engine specific native surf
 
 type Evas.Modifier_Mask: ullong;  [[An Evas modifier mask type]]
 type Evas.Coord: int; [[A type for coordinates]]
-enum Evas.Aspect_Control {
-   [[Aspect types/policies for scaling size hints, used for
-     evas_object_size_hint_aspect_set()]]
-   none = 0, [[Preference on scaling unset]]
-   neither = 1, [[Same effect as unset preference on scaling]]
-   horizontal = 2, [[Use all horizontal container space to place an object,
-                     using the given aspect]]
-   vertical = 3, [[Use all vertical container space to place an object, using
-                   the given aspect]]
-   both = 4 [[Use all horizontal and vertical container spaces to place an
-              object (never growing it out of those bounds), using the given
-              aspect]]
-}
 
 enum Evas.Render_Op {
    [[How the object should be rendered to output.]]