add widget_animate_value_to

This commit is contained in:
xianjimli 2018-12-26 09:30:33 +08:00
parent 9c85038e16
commit f5442abea5
4 changed files with 30 additions and 5 deletions

View File

@ -339,9 +339,8 @@ static ret_t on_mem_test(void* ctx, event_t* e) {
static ret_t on_inc(void* ctx, event_t* e) {
widget_t* win = WIDGET(ctx);
widget_t* progress_bar = widget_lookup(win, "bar1", TRUE);
uint8_t value = (PROGRESS_BAR(progress_bar)->value + 10) % 100;
progress_bar_set_value(progress_bar, value);
int32_t value = (PROGRESS_BAR(progress_bar)->value + 20);
widget_animate_value_to(progress_bar, tk_min(100, value), 500);
(void)e;
return RET_OK;
}
@ -349,8 +348,8 @@ static ret_t on_inc(void* ctx, event_t* e) {
static ret_t on_dec(void* ctx, event_t* e) {
widget_t* win = WIDGET(ctx);
widget_t* progress_bar = widget_lookup(win, "bar1", TRUE);
uint8_t value = (PROGRESS_BAR(progress_bar)->value + 90) % 100;
progress_bar_set_value(progress_bar, value);
int32_t value = PROGRESS_BAR(progress_bar)->value - 20;
widget_animate_value_to(progress_bar, tk_max(0, value), 500);
(void)e;
return RET_OK;

View File

@ -2,6 +2,7 @@
* 2018/12/26
* 为了语义的一致性把widget的虚函数destroy改名为on\_destroy。on\_destroy只是通知子类控件即将销毁。
* 重命名NAME\_LEN为TK\_NAME\_LEN。
* 增加函数widget\_animate\_value\_to
* 2018/12/25
* 整理控件API文档row/column/grid/grid\_item/view/group\_box/app\_bar/system\_bar

View File

@ -113,6 +113,18 @@ ret_t widget_add_value(widget_t* widget, int32_t delta) {
return widget_set_value(widget, widget_get_value(widget) + delta);
}
ret_t widget_animate_value_to(widget_t* widget, int32_t value, uint32_t duration) {
if (duration == 0) {
return widget_set_value(widget, value);
} else {
char params[64];
tk_snprintf(params, sizeof(params) - 1, "value(to=%d, duration=%d)", value, duration);
widget_destroy_animator(widget, "value");
return widget_create_animator(widget, params);
}
}
bool_t widget_is_window_opened(widget_t* widget) {
int32_t stage =
widget_get_prop_int(widget_get_window(widget), WIDGET_PROP_STAGE, WINDOW_STAGE_NONE);

View File

@ -543,6 +543,19 @@ ret_t widget_move_resize(widget_t* widget, xy_t x, xy_t y, wh_t w, wh_t h);
*/
ret_t widget_set_value(widget_t* widget, int32_t value);
/**
* @method widget_animate_value_to
* ()
* widget\_set\_prop的包装
* @annotation ["scriptable"]
* @param {widget_t*} widget
* @param {int32_t} value
* @param {uint32_t} duration ()
*
* @return {ret_t} RET_OK表示成功
*/
ret_t widget_animate_value_to(widget_t* widget, int32_t value, uint32_t duration);
/**
* @method widget_add_value
*