list view support pagedown/pageup

This commit is contained in:
lixianjing 2019-11-05 09:31:06 +08:00
parent 8b3b4a2fcf
commit 82e4d74e16
5 changed files with 76 additions and 18 deletions

View File

@ -1,5 +1,8 @@
# 最新动态
* 2019/11/05
* list\_view/list\_view\_h 增加pageup/pagedown按键处理。
* 2019/11/04
* 完善字体和文字绘制。

View File

@ -69,6 +69,7 @@ static ret_t list_view_set_prop(widget_t* widget, const char* name, const value_
}
static ret_t list_view_on_event(widget_t* widget, event_t* e) {
ret_t ret = RET_OK;
list_view_t* list_view = LIST_VIEW(widget);
return_value_if_fail(list_view != NULL, RET_BAD_PARAMS);
@ -81,12 +82,24 @@ static ret_t list_view_on_event(widget_t* widget, event_t* e) {
log_debug("wheel: %d\n", delta);
}
return RET_STOP;
ret = RET_STOP;
break;
}
case EVT_KEY_DOWN: {
key_event_t* evt = (key_event_t*)e;
if (evt->key == TK_KEY_PAGEDOWN) {
scroll_view_scroll_delta_to(list_view->scroll_view, 0, widget->h, TK_ANIMATING_TIME);
ret = RET_STOP;
} else if (evt->key == TK_KEY_PAGEUP) {
scroll_view_scroll_delta_to(list_view->scroll_view, 0, -widget->h, TK_ANIMATING_TIME);
ret = RET_STOP;
}
break;
}
default:
break;
}
return RET_OK;
return ret;
}
TK_DECL_VTABLE(list_view) = {.type = WIDGET_TYPE_LIST_VIEW,

View File

@ -62,10 +62,27 @@ static ret_t list_view_h_set_prop(widget_t* widget, const char* name, const valu
}
static ret_t list_view_h_on_event(widget_t* widget, event_t* e) {
ret_t ret = RET_OK;
list_view_h_t* list_view = LIST_VIEW_H(widget);
return_value_if_fail(list_view != NULL, RET_BAD_PARAMS);
return RET_OK;
switch (e->type) {
case EVT_KEY_DOWN: {
key_event_t* evt = (key_event_t*)e;
if (evt->key == TK_KEY_PAGEDOWN) {
scroll_view_scroll_delta_to(list_view->scroll_view, widget->w, 0, TK_ANIMATING_TIME);
ret = RET_STOP;
} else if (evt->key == TK_KEY_PAGEUP) {
scroll_view_scroll_delta_to(list_view->scroll_view, -widget->w, 0, TK_ANIMATING_TIME);
ret = RET_STOP;
}
break;
}
default:
break;
}
return ret;
}
TK_DECL_VTABLE(list_view_h) = {.type = WIDGET_TYPE_LIST_VIEW_H,

View File

@ -159,6 +159,18 @@ ret_t scroll_view_scroll_to(widget_t* widget, int32_t xoffset_end, int32_t yoffs
scroll_view_t* scroll_view = SCROLL_VIEW(widget);
return_value_if_fail(scroll_view != NULL, RET_FAIL);
if (scroll_view->fix_end_offset) {
scroll_view->xoffset_end = xoffset_end;
scroll_view->yoffset_end = yoffset_end;
scroll_view->fix_end_offset(widget);
xoffset_end = scroll_view->xoffset_end;
yoffset_end = scroll_view->yoffset_end;
}
if (xoffset_end == scroll_view->xoffset && yoffset_end == scroll_view->yoffset) {
return RET_OK;
}
xoffset = scroll_view->xoffset;
yoffset = scroll_view->yoffset;
@ -166,14 +178,9 @@ ret_t scroll_view_scroll_to(widget_t* widget, int32_t xoffset_end, int32_t yoffs
scroll_view->on_scroll_to(widget, xoffset_end, yoffset_end, duration);
}
if ((!scroll_view->yslidable && xoffset == xoffset_end) ||
(!scroll_view->xslidable && yoffset == yoffset_end)) {
return RET_OK;
}
if (scroll_view->wa != NULL) {
widget_animator_scroll_t* wa = (widget_animator_scroll_t*)scroll_view->wa;
if (scroll_view->xslidable) {
if (xoffset_end != scroll_view->xoffset) {
bool_t changed = wa->x_to != xoffset_end;
bool_t in_range = wa->x_to > 0 && wa->x_to < (scroll_view->virtual_w - widget->w);
if (changed && in_range) {
@ -184,7 +191,7 @@ ret_t scroll_view_scroll_to(widget_t* widget, int32_t xoffset_end, int32_t yoffs
}
}
if (scroll_view->yslidable) {
if (yoffset_end != scroll_view->yoffset) {
bool_t changed = wa->y_to != yoffset_end;
bool_t in_range = wa->y_to > 0 && wa->y_to < (scroll_view->virtual_h - widget->h);
if (changed && in_range) {
@ -209,6 +216,18 @@ ret_t scroll_view_scroll_to(widget_t* widget, int32_t xoffset_end, int32_t yoffs
return RET_OK;
}
ret_t scroll_view_scroll_delta_to(widget_t* widget, int32_t xoffset_delta, int32_t yoffset_delta,
int32_t duration) {
scroll_view_t* scroll_view = SCROLL_VIEW(widget);
return_value_if_fail(scroll_view != NULL, RET_FAIL);
scroll_view->xoffset_end = scroll_view->xoffset + xoffset_delta;
scroll_view->yoffset_end = scroll_view->yoffset + yoffset_delta;
return scroll_view_scroll_to(widget, scroll_view->xoffset_end, scroll_view->yoffset_end,
duration);
}
#define SPEED_SCALE 2
#define MIN_DELTA 10
@ -217,10 +236,6 @@ static ret_t scroll_view_on_pointer_down_abort(scroll_view_t* scroll_view, point
(void)e;
if (scroll_view->xslidable || scroll_view->yslidable) {
if (scroll_view->fix_end_offset) {
scroll_view->fix_end_offset(widget);
}
scroll_view_scroll_to(widget, scroll_view->xoffset_end, scroll_view->yoffset_end,
TK_ANIMATING_TIME);
}
@ -264,10 +279,6 @@ static ret_t scroll_view_on_pointer_up(scroll_view_t* scroll_view, pointer_event
}
}
if (scroll_view->fix_end_offset) {
scroll_view->fix_end_offset(widget);
}
scroll_view_scroll_to(widget, scroll_view->xoffset_end, scroll_view->yoffset_end,
TK_ANIMATING_TIME);
}

View File

@ -225,6 +225,20 @@ ret_t scroll_view_set_offset(widget_t* widget, int32_t xoffset, int32_t yoffset)
ret_t scroll_view_scroll_to(widget_t* widget, int32_t xoffset_end, int32_t yoffset_end,
int32_t duration);
/**
* @method scroll_view_scroll_delta_to
*
* @annotation ["scriptable"]
* @param {widget_t*} widget
* @param {int32_t} xoffset_delta x偏移量
* @param {int32_t} yoffset_delta y偏移量
* @param {int32_t} duration
*
* @return {ret_t} RET_OK表示成功
*/
ret_t scroll_view_scroll_delta_to(widget_t* widget, int32_t xoffset_delta, int32_t yoffset_delta,
int32_t duration);
#define SCROLL_VIEW(widget) ((scroll_view_t*)(scroll_view_cast(WIDGET(widget))))
/*public for subclass and runtime type check*/