Elementary: Wrote proper support for "wanted position" in els_scroller. It will now save the position we really wanted to get to (for example because of scrolling) and will go back to that place after resizes. Fixes a couple of bugs.

In this change I also introduced elm_smart_scroller_child_region_set thats used to change the position of the scroller, without actually saving it as a wanted position.

SVN revision: 56284
This commit is contained in:
Tom Hacohen 2011-01-24 10:50:35 +00:00
parent 5871b29ea1
commit 8d4db80639
2 changed files with 52 additions and 9 deletions

View File

@ -12,6 +12,7 @@ typedef struct _Smart_Data Smart_Data;
struct _Smart_Data
{
Evas_Coord x, y, w, h;
Evas_Coord wx, wy, ww, wh; /* Last "wanted" geometry */
Evas_Object *smart_obj;
Evas_Object *child_obj;
@ -165,6 +166,7 @@ elm_smart_scroller_child_set(Evas_Object *obj, Evas_Object *child)
}
sd->child_obj = child;
sd->wx = sd->wy = sd->ww = sd->wh = 0;
if (!child) return;
if (!sd->pan_obj)
@ -400,7 +402,7 @@ _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
x = pos_x;
elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
return;
}
t = ecore_loop_time_get();
@ -411,7 +413,7 @@ _smart_scrollto_x(Smart_Data *sd, double t_in, Evas_Coord pos_x)
sd->scrollto.x.t_end = t + t_in;
elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
if (!sd->scrollto.x.animator)
{
if (!sd->scrollto.y.animator)
@ -467,7 +469,7 @@ _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
y = pos_y;
elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
return;
}
t = ecore_loop_time_get();
@ -478,7 +480,7 @@ _smart_scrollto_y(Smart_Data *sd, double t_in, Evas_Coord pos_y)
sd->scrollto.y.t_end = t + t_in;
elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
elm_smart_scroller_child_viewport_size_get(sd->smart_obj, &w, &h);
elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
if (!sd->scrollto.y.animator)
{
if (!sd->scrollto.x.animator)
@ -573,7 +575,7 @@ _smart_page_adjust(Smart_Data *sd)
x = _smart_page_x_get(sd, 0);
y = _smart_page_y_get(sd, 0);
elm_smart_scroller_child_region_show(sd->smart_obj, x, y, w, h);
elm_smart_scroller_child_region_set(sd->smart_obj, x, y, w, h);
}
static Eina_Bool
@ -916,8 +918,10 @@ elm_smart_scroller_child_pos_get(Evas_Object *obj, Evas_Coord *x, Evas_Coord *y)
sd->pan_func.get(sd->pan_obj, x, y);
}
void
elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
/* "internal_call" actually toggles whether we should save the coords and do
* extra "speedup" checks, or not. */
static void
_elm_smart_scroller_child_region_show_internal(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h, Eina_Bool internal_call)
{
Evas_Coord mx = 0, my = 0, cw = 0, ch = 0, px = 0, py = 0, nx, ny, minx = 0, miny = 0;
@ -941,7 +945,15 @@ elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord
ny = y + h - (ch - my);
if (ny > y) ny = y;
}
if ((nx == px) && (ny == py)) return;
if (!internal_call)
{
sd->wx = x;
sd->wy = y;
sd->ww = w;
sd->wh = h;
if ((nx == px) && (ny == py)) return;
}
if ((sd->down.bounce_x_animator) || (sd->down.bounce_y_animator) ||
(sd->scrollto.x.animator) || (sd->scrollto.y.animator))
{
@ -989,6 +1001,23 @@ elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord
elm_smart_scroller_child_pos_set(obj, nx, ny);
}
/* Set should be used for calculated positions, for example, when we move
* because of an animation or because this is the correct position after
* constraints. */
void
elm_smart_scroller_child_region_set(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
{
_elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_TRUE);
}
/* Set should be used for setting the wanted position, for example a user scroll
* or moving the cursor in an entry. */
void
elm_smart_scroller_child_region_show(Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
{
_elm_smart_scroller_child_region_show_internal(obj, x, y, w, h, EINA_FALSE);
}
void
elm_smart_scroller_child_viewport_size_get(Evas_Object *obj, Evas_Coord *w, Evas_Coord *h)
{
@ -1438,7 +1467,11 @@ _smart_event_wheel(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__,
x += ev->z * sd->step.x;
if ((!sd->hold) && (!sd->freeze))
elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
{
sd->wx = x;
sd->wy = y;
elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
}
}
static void
@ -1551,6 +1584,8 @@ _smart_hold_animator(void *data)
}
}
elm_smart_scroller_child_pos_set(sd->smart_obj, ox, oy);
sd->wx = ox;
sd->wy = oy;
return ECORE_CALLBACK_RENEW;
}
@ -1769,6 +1804,8 @@ _smart_event_mouse_up(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *ev
sd->down.now = 0;
elm_smart_scroller_child_pos_get(sd->smart_obj, &x, &y);
elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
sd->wx = x;
sd->wy = y;
if (!_smart_do_page(sd))
bounce_eval(sd);
}
@ -1817,6 +1854,8 @@ _smart_onhold_animator(void *data)
}
elm_smart_scroller_child_pos_set(sd->smart_obj, x, y);
sd->wx = x;
sd->wy = y;
// printf("scroll %i %i\n", sd->down.hold_x, sd->down.hold_y);
}
sd->down.onhold_tlast = t;
@ -1906,6 +1945,8 @@ _smart_event_mouse_move(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *
#ifdef SCROLLDBG
printf("::: %i %i\n", ev->cur.canvas.x, ev->cur.canvas.y);
#endif
sd->wx = ev->cur.canvas.x;
sd->wy = ev->cur.canvas.y;
memmove(&(sd->down.history[1]), &(sd->down.history[0]),
sizeof(sd->down.history[0]) * 19);
#ifdef EVTIME
@ -2494,6 +2535,7 @@ _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
sd->w = w;
sd->h = h;
_smart_reconfigure(sd);
elm_smart_scroller_child_region_set(obj, sd->wx, sd->wy, sd->ww, sd->h);
}
static void

View File

@ -13,6 +13,7 @@ void elm_smart_scroller_custom_edje_file_set (Evas_Object *obj, char *file, c
void elm_smart_scroller_child_pos_set (Evas_Object *obj, Evas_Coord x, Evas_Coord y);
void elm_smart_scroller_child_pos_get (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);
void elm_smart_scroller_child_region_show (Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
void elm_smart_scroller_child_region_set (Evas_Object *obj, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h);
void elm_smart_scroller_child_viewport_size_get (Evas_Object *obj, Evas_Coord *w, Evas_Coord *h);
void elm_smart_scroller_step_size_set (Evas_Object *obj, Evas_Coord x, Evas_Coord y);
void elm_smart_scroller_step_size_get (Evas_Object *obj, Evas_Coord *x, Evas_Coord *y);