efl_ui_widget: move show_region to legacy
authorMarcel Hollerbach <mail@marcel-hollerbach.de>
Wed, 27 Feb 2019 19:00:52 +0000 (14:00 -0500)
committerWonki Kim <wonki_.kim@samsung.com>
Fri, 8 Mar 2019 11:49:36 +0000 (20:49 +0900)
summary_:
show_region is simular to focus_region. However, it builds up on setting
custom functions per setter to the widget, which are then executed. This
can be solved better by overwriting the interest_region getter, and
using a function like elm_widget_focus_region_show (This function still
needs to find its place in the eo api).

ref T7553

Depends on D8025

Reviewers: woohyun, cedric, Jaehyun_Cho, zmike, segfaultxavi

Reviewed By: segfaultxavi

Subscribers: #reviewers, #committers

Tags: #efl

Maniphest Tasks: T7553

Reviewed-by: Xavi Artigas <xavierartigas@yahoo.es>
Differential Revision: https://phab.enlightenment.org/D8026

src/lib/elementary/efl_ui_widget.c
src/lib/elementary/efl_ui_widget.eo

index e1eeb84..be62f19 100644 (file)
@@ -1467,20 +1467,6 @@ _efl_ui_widget_efl_ui_i18n_mirrored_automatic_set(Eo *obj, Elm_Widget_Smart_Data
      }
 }
 
-EOLIAN static void
-_efl_ui_widget_on_show_region_hook_set(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, void *data, Efl_Ui_Scrollable_On_Show_Region func, Eina_Free_Cb func_free_cb)
-{
-   if ((sd->on_show_region_data == data) && (sd->on_show_region == func))
-     return;
-
-   if (sd->on_show_region_data && sd->on_show_region_data_free)
-     sd->on_show_region_data_free(sd->on_show_region_data);
-
-   sd->on_show_region = func;
-   sd->on_show_region_data = data;
-   sd->on_show_region_data_free = func_free_cb;
-}
-
 /*
  * @internal
  *
@@ -6065,6 +6051,84 @@ _efl_ui_widget_part_access_object_get(const Eo *obj, Elm_Widget_Smart_Data *_pd
 
 /* Legacy APIs */
 
+EAPI void
+elm_widget_on_show_region_hook_set(Eo *obj, void *data, Efl_Ui_Scrollable_On_Show_Region func, Eina_Free_Cb func_free_cb)
+{
+   ELM_WIDGET_DATA_GET(obj, sd);
+
+   if ((sd->on_show_region_data == data) && (sd->on_show_region == func))
+     return;
+
+   if (sd->on_show_region_data && sd->on_show_region_data_free)
+     sd->on_show_region_data_free(sd->on_show_region_data);
+
+   sd->on_show_region = func;
+   sd->on_show_region_data = data;
+   sd->on_show_region_data_free = func_free_cb;
+}
+
+EAPI void
+elm_widget_show_region_set(Eo *obj, Eina_Rect sr, Eina_Bool forceshow)
+{
+   Evas_Object *parent_obj, *child_obj;
+   Evas_Coord px, py, cx, cy, nx = 0, ny = 0;
+
+   ELM_WIDGET_DATA_GET_OR_RETURN(obj, sd);
+
+   evas_smart_objects_calculate(evas_object_evas_get(obj));
+
+   if (!forceshow && eina_rectangle_equal(&sr.rect, &sd->show_region.rect)) return;
+
+   sd->show_region = sr;
+   if (sd->on_show_region)
+     {
+        sd->on_show_region(sd->on_show_region_data, obj, sr);
+
+        if (_elm_scrollable_is(obj))
+          {
+             if (elm_widget_is_legacy(obj))
+               {
+                  elm_interface_scrollable_content_pos_get(obj, &nx, &ny);
+                  sr.x -= nx;
+                  sr.y -= ny;
+               }
+             else
+               {
+                  Eina_Position2D pos;
+                  pos = efl_ui_scrollable_content_pos_get(obj);
+                  sr.x -= pos.x;
+                  sr.y -= pos.y;
+               }
+          }
+     }
+
+   do
+     {
+        parent_obj = sd->parent_obj;
+        child_obj = sd->obj;
+        if ((!parent_obj) || (!_elm_widget_is(parent_obj))) break;
+        sd = efl_data_scope_get(parent_obj, MY_CLASS);
+        if (!sd) break;
+
+        evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
+        evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
+
+        sr.x += (cx - px);
+        sr.y += (cy - py);
+        sd->show_region = sr;
+
+        if (sd->on_show_region)
+          sd->on_show_region(sd->on_show_region_data, parent_obj, sr);
+     }
+   while (parent_obj);
+}
+
+EAPI Eina_Rect
+elm_widget_show_region_get(const Eo *obj)
+{
+   ELM_WIDGET_DATA_GET_OR_RETURN(obj, sd, EINA_RECT_EMPTY());
+   return (Eina_Rect) sd->show_region;
+}
 /* elm_object_content_xxx APIs are supposed to work on all objects for which
  * elm_object_widget_check() returns true. The below checks avoid printing out
  * undesired ERR messages. */
index 14fcdff..c0eebb7 100644 (file)
@@ -400,42 +400,6 @@ abstract @beta Efl.Ui.Widget extends Efl.Canvas.Group implements Efl.Access.Obje
                                        theme or default theme was used.]]
       }
 
-      /* Scroll API. */
-      @property on_show_region_hook @protected {
-         [[Hook function called when the @.show_region is changed.
-
-           See also @.show_region.
-         ]]
-         set {}
-         values {
-            func: Efl.Ui.Scrollable_On_Show_Region @nullable; [[Region hook function]]
-         }
-      }
-      @property show_region @protected {
-         [[Region inside the widget to show.
-
-           See also @.on_show_region_hook.
-         ]]
-         set {
-            [[Request parent scrollers to pan around so that this region
-              of the widget becomes visible.
-
-              If $force is $true this will trigger scroller changes and
-              the @.on_show_region_hook to be called even if the region is
-              unchanged.
-            ]]
-            values {
-               region: Eina.Rect; [[The region to show.]]
-               force: bool; [[Set to $true to force show even if unchanged.]]
-            }
-         }
-         get {
-            [[Returns the current region to show.]]
-            values {
-               region: Eina.Rect; [[The region to show.]]
-            }
-         }
-      }
       /* FIXME: Scroll API. Not sure how those APIs should be exposed with
        * the new scrollable API. */
       scroll_hold_push {
@@ -480,9 +444,9 @@ abstract @beta Efl.Ui.Widget extends Efl.Canvas.Group implements Efl.Access.Obje
          }
       }
       @property interest_region_mode {
-         [[Defines how @.show_region should be calculated.
+         [[Defines how @.interest_region should be calculated.
 
-           It is up to the implementation of @.show_region.get to take this
+           It is up to the implementation of @.interest_region.get to take this
            value into account (or ignore it).
          ]]
          get {