From fc2f7541e9c89785fec3df94a2b423580aeb0d3e Mon Sep 17 00:00:00 2001 From: lixianjing Date: Fri, 22 Oct 2021 15:51:12 +0800 Subject: [PATCH] improve value animation --- demos/demo_ui_old_app.c | 42 ++ design/default/ui/animate_widget.xml | 5 + design/default/ui/main.xml | 2 +- design/default/ui/value_anim.xml | 31 ++ docs/changes.md | 3 + res/assets/__assets_all_dark.inc | 4 + res/assets/__assets_all_default.inc | 4 + res/assets/__assets_old_dark.inc | 4 + res/assets/__assets_old_default.inc | 4 + res/assets/default/inc/ui/animate_widget.data | 21 + res/assets/default/inc/ui/main.data | 392 +++++++++--------- res/assets/default/inc/ui/value_anim.data | 130 ++++++ res/assets/default/raw/ui/animate_widget.bin | Bin 0 -> 348 bytes res/assets/default/raw/ui/main.bin | Bin 5762 -> 5768 bytes res/assets/default/raw/ui/value_anim.bin | Bin 0 -> 2518 bytes res/assets_all_dark.inc | 4 + res/assets_all_default.inc | 4 + res/assets_old_dark.inc | 4 + res/assets_old_default.inc | 4 + src/base/widget.c | 63 ++- src/base/widget.h | 40 +- src/widgets/slider.c | 34 +- 22 files changed, 560 insertions(+), 235 deletions(-) create mode 100644 design/default/ui/animate_widget.xml create mode 100644 design/default/ui/value_anim.xml create mode 100644 res/assets/default/inc/ui/animate_widget.data create mode 100644 res/assets/default/inc/ui/value_anim.data create mode 100644 res/assets/default/raw/ui/animate_widget.bin create mode 100644 res/assets/default/raw/ui/value_anim.bin diff --git a/demos/demo_ui_old_app.c b/demos/demo_ui_old_app.c index 5c91664bb..0bf4f57d5 100644 --- a/demos/demo_ui_old_app.c +++ b/demos/demo_ui_old_app.c @@ -726,6 +726,45 @@ static ret_t on_change_locale(void* ctx, event_t* e) { return RET_OK; } +static ret_t on_bind_value_changed(void* ctx, event_t* e) { + widget_t* widget = WIDGET(ctx); + widget_t* target = WIDGET(e->target); + if (widget != NULL && target != NULL) { + widget_set_prop_float(widget, "animate.value", widget_get_value(target)); + } + return RET_OK; +} + +static widget_t* find_bind_value_target(widget_t* widget, const char* name) { + widget_t* target = NULL; + widget_t* parent = widget->parent; + const char* subname = NULL; + tokenizer_t t; + + tokenizer_init(&t, name, tk_strlen(name), "/"); + + while ((subname = tokenizer_next(&t)) != NULL) { + if (tokenizer_has_more(&t)) { + if (tk_str_eq(subname, "..")) { + parent = parent->parent; + } else { + while (parent != NULL) { + widget_t* tmp = widget_lookup(parent, subname, FALSE); + if (tmp != NULL) { + parent = tmp; + break; + } else { + parent = parent->parent; + } + } + } + } else { + target = widget_lookup(parent, subname, FALSE); + } + } + return target; +} + static ret_t install_one(void* ctx, const void* iter) { widget_t* widget = WIDGET(iter); widget_t* win = widget_get_window(widget); @@ -823,6 +862,9 @@ static ret_t install_one(void* ctx, const void* iter) { } } else if (tk_str_eq(name, "pages")) { widget_on(widget, EVT_WIDGET_ADD_CHILD, on_pages_add_child, widget); + } else if (strstr(name, "bind_value:") != NULL) { + widget_t* target = find_bind_value_target(widget, name + 11); + widget_on(target, EVT_VALUE_CHANGED, on_bind_value_changed, (void*)widget); } } else if (tk_str_eq(widget->vt->type, "combo_box")) { widget_on(widget, EVT_VALUE_CHANGED, on_combo_box_changed, widget); diff --git a/design/default/ui/animate_widget.xml b/design/default/ui/animate_widget.xml new file mode 100644 index 000000000..acb20eaac --- /dev/null +++ b/design/default/ui/animate_widget.xml @@ -0,0 +1,5 @@ + +