improve toast

This commit is contained in:
xianjimli 2020-06-15 11:11:57 +08:00
parent 7229977695
commit 5e5bcf0a3b
2 changed files with 11 additions and 2 deletions

View File

@ -1,5 +1,8 @@
# 最新动态
* 2020/06/15
* 完善toast (感谢培煌提供补丁)
* 2020/06/14
* 完善 scroll view增加滚动相关事件。
* 增加文档《如何实现弹出菜单》

View File

@ -108,20 +108,26 @@ static widget_t* dialog_create_label(const char* text) {
}
ret_t dialog_toast(const char* text, uint32_t duration) {
char params[128];
int32_t margin = 10;
widget_t* label = NULL;
widget_t* dialog = NULL;
return_value_if_fail(text != NULL, RET_BAD_PARAMS);
return_value_if_fail(text != NULL && duration >= 1000, RET_BAD_PARAMS);
label = dialog_create_label(text);
return_value_if_fail(label != NULL, RET_OOM);
dialog = dialog_create(NULL, 0, 0, label->w, label->h);
dialog = dialog_create(NULL, 0, 0, label->w + 2 * margin, label->h + 2 * margin);
goto_error_if_fail(dialog != NULL);
widget_set_prop_str(dialog, WIDGET_PROP_ANIM_HINT, "fade(duration=500)");
widget_set_prop_str(dialog, WIDGET_PROP_THEME, "dialog_toast");
widget_add_child(dialog, label);
tk_snprintf(params, sizeof(params) - 1, "default(x=%d, y=%d, w=%d, h=%d)",
margin, margin, label->w, label->h);
widget_set_self_layout(label, params);
widget_on(dialog, EVT_POINTER_UP, on_ok_to_quit, dialog);
widget_add_timer(dialog, on_timer_to_quit, duration);