widget: Use rectangle in show_region

Also make it a property. It's asymmetric because of the force show
argument, but the get is much cleaner.

Ref T5363
This commit is contained in:
Jean-Philippe Andre 2017-08-30 13:39:16 +09:00
parent 4a6b52465d
commit a82ab33bed
7 changed files with 65 additions and 70 deletions

View File

@ -1042,6 +1042,7 @@ _cursor_geometry_recalc(Evas_Object *obj)
Evas_Coord x, y, w, h;
Evas_Coord x2, y2, w2, h2;
Evas_Coord cx, cy, cw, ch;
Eina_Rectangle sr;
cx = cy = cw = ch = 0;
x2 = y2 = w2 = h2 = 0;
@ -1063,7 +1064,8 @@ _cursor_geometry_recalc(Evas_Object *obj)
&x2, &y2, &w2, &h2);
cx = cx + x - x2;
cy = cy + y - y2;
elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
sr = (Eina_Rectangle) { cx, cy, cw, ch };
elm_widget_show_region_set(obj, sr, EINA_FALSE);
}
EOLIAN static void

View File

@ -1067,12 +1067,14 @@ _entry_resize_cb(void *data,
void *event_info EINA_UNUSED)
{
ELM_MULTIBUTTONENTRY_DATA_GET_OR_RETURN(data, sd);
Evas_Coord en_x, en_y, en_w, en_h;
evas_object_geometry_get(sd->entry, &en_x, &en_y, &en_w, &en_h);
if (elm_widget_focus_get(sd->parent))
elm_widget_show_region_set(sd->entry, en_x, en_y, en_w, en_h, EINA_TRUE);
{
Eina_Rectangle sr = {};
evas_object_geometry_get(sd->entry, &sr.x, &sr.y, &sr.w, &sr.h);
elm_widget_show_region_set(sd->entry, sr, EINA_TRUE);
}
}
static void

View File

@ -668,7 +668,7 @@ _show_region_job(void *data)
if (r.h < _elm_config->finger_size)
r.h = _elm_config->finger_size;
elm_widget_show_region_set(focus_obj, r.x, r.y, r.w, r.h, EINA_TRUE);
elm_widget_show_region_set(focus_obj, r, EINA_TRUE);
}
sd->show_region_job = NULL;

View File

@ -1009,14 +1009,14 @@ _cursor_geometry_recalc(Evas_Object *obj)
if (!sd->deferred_recalc_job)
{
Evas_Coord cx, cy, cw, ch;
edje_object_part_text_cursor_geometry_get
(sd->entry_edje, "elm.text", &cx, &cy, &cw, &ch);
if (sd->cur_changed)
{
Eina_Rectangle sr = {};
sd->cur_changed = EINA_FALSE;
elm_widget_show_region_set(obj, cx, cy, cw, ch, EINA_FALSE);
edje_object_part_text_cursor_geometry_get
(sd->entry_edje, "elm.text", &sr.x, &sr.y, &sr.w, &sr.h);
elm_widget_show_region_set(obj, sr, EINA_FALSE);
}
}
else
@ -1083,14 +1083,14 @@ _deferred_recalc_job(void *data)
if (sd->deferred_cur)
{
Evas_Coord cx, cy, cw, ch;
edje_object_part_text_cursor_geometry_get
(sd->entry_edje, "elm.text", &cx, &cy, &cw, &ch);
if (sd->cur_changed)
{
Eina_Rectangle sr = {};
sd->cur_changed = EINA_FALSE;
elm_widget_show_region_set(data, cx, cy, cw, ch, EINA_FALSE);
edje_object_part_text_cursor_geometry_get
(sd->entry_edje, "elm.text", &sr.x, &sr.y, &sr.w, &sr.h);
elm_widget_show_region_set(data, sr, EINA_FALSE);
}
}
}

View File

@ -3393,32 +3393,25 @@ _elm_widget_disabled_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
}
EOLIAN static void
_elm_widget_show_region_set(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool forceshow)
_elm_widget_show_region_set(Eo *obj, Elm_Widget_Smart_Data *sd, Eina_Rectangle sr, Eina_Bool forceshow)
{
Evas_Object *parent_obj, *child_obj;
Evas_Coord px, py, cx, cy, nx = 0, ny = 0;
evas_smart_objects_calculate(evas_object_evas_get(obj));
if (!forceshow && (x == sd->rx) && (y == sd->ry) &&
(w == sd->rw) && (h == sd->rh)) return;
if (!forceshow && eina_rectangle_equal(&sr, &sd->show_region)) return;
sd->rx = x;
sd->ry = y;
sd->rw = w;
sd->rh = h;
sd->show_region = sr;
if (sd->on_show_region)
{
const Eina_Rectangle r = { x, y, w, h };
sd->on_show_region(sd->on_show_region_data, obj, r);
sd->on_show_region(sd->on_show_region_data, obj, sr);
if (_elm_scrollable_is(obj))
{
elm_interface_scrollable_content_pos_get(obj, &nx, &ny);
x -= nx;
y -= ny;
sr.x -= nx;
sr.y -= ny;
}
}
@ -3433,29 +3426,20 @@ _elm_widget_show_region_set(Eo *obj, Elm_Widget_Smart_Data *sd, Evas_Coord x, Ev
evas_object_geometry_get(parent_obj, &px, &py, NULL, NULL);
evas_object_geometry_get(child_obj, &cx, &cy, NULL, NULL);
x += (cx - px);
y += (cy - py);
sd->rx = x;
sd->ry = y;
sd->rw = w;
sd->rh = h;
sr.x += (cx - px);
sr.y += (cy - py);
sd->show_region = sr;
if (sd->on_show_region)
{
const Eina_Rectangle r = { x, y, w, h };
sd->on_show_region(sd->on_show_region_data, parent_obj, r);
}
sd->on_show_region(sd->on_show_region_data, parent_obj, sr);
}
while (parent_obj);
}
EOLIAN static void
_elm_widget_show_region_get(const Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h)
EOLIAN static Eina_Rectangle
_elm_widget_show_region_get(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
{
if (x) *x = sd->rx;
if (y) *y = sd->ry;
if (w) *w = sd->rw;
if (h) *h = sd->rh;
return sd->show_region;
}
/**

View File

@ -414,12 +414,40 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
/* Scroll API. */
@property on_show_region_hook {
[[Region hook on show property]]
[[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.Rectangle; [[The region of interest.]]
force: bool; [[Set to $true to force show even if unchanged.]]
}
}
get {
[[Returns the current region of interest.]]
values {
region: Eina.Rectangle; [[The region of interest.]]
}
}
}
@property item_loop_enabled {
[[Control item loop feature.]]
values {
@ -429,27 +457,6 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
scroll_hold_push {
[[Push scroll hold]]
}
/* FIXME: property with a Eina.Rectangle */
show_region_set {
[[Set show region]]
params {
@in x: int; [[X coordinate]]
@in y: int; [[Y coordinate]]
@in w: int; [[Width]]
@in h: int; [[Height]]
@in forceshow: bool; [[$true if show should be forced, $false otherwise]]
}
}
show_region_get @const {
[[Get show region]]
params {
@out x: int @optional; [[X coordinate]]
@out y: int @optional; [[Y coordinate]]
@out w: int @optional; [[Width]]
@out h: int @optional; [[Height]]
}
}
scroll_hold_pop {
[[Pop scroller hold]]
}

View File

@ -396,7 +396,7 @@ typedef struct _Elm_Widget_Smart_Data
/* "show region" coordinates. all widgets got those because this
* info may be set and queried recursively through the widget
* parenting tree */
Evas_Coord rx, ry, rw, rh;
Eina_Rectangle show_region;
/* scrolling hold/freeze hints. all widgets got those because this
* info may be set and queried recursively through the widget
@ -719,8 +719,8 @@ EAPI void elm_widget_focus_restore(Evas_Object *obj);
EAPI void elm_widget_disabled_set(Evas_Object *obj, Eina_Bool disabled);
EAPI Eina_Bool elm_widget_disabled_get(const Evas_Object *obj);
EAPI void elm_widget_show_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool forceshow);
EAPI void elm_widget_show_region_get(const Evas_Object *obj, Evas_Coord *x, Evas_Coord *y, Evas_Coord *w, Evas_Coord *h);
EAPI void elm_widget_show_region_set(Evas_Object *obj, Eina_Rectangle sr, Eina_Bool forceshow);
EAPI Eina_Rectangle elm_widget_show_region_get(const Evas_Object *obj);
EAPI Eina_Rectangle elm_widget_focus_region_get(const Evas_Object *obj);
EAPI void elm_widget_focus_region_show(Evas_Object *obj);
EAPI void elm_widget_scroll_hold_push(Evas_Object *obj);