mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 11:08:34 +08:00
improve toast
This commit is contained in:
parent
7229977695
commit
5e5bcf0a3b
@ -1,5 +1,8 @@
|
|||||||
# 最新动态
|
# 最新动态
|
||||||
|
|
||||||
|
* 2020/06/15
|
||||||
|
* 完善toast (感谢培煌提供补丁)
|
||||||
|
|
||||||
* 2020/06/14
|
* 2020/06/14
|
||||||
* 完善 scroll view,增加滚动相关事件。
|
* 完善 scroll view,增加滚动相关事件。
|
||||||
* 增加文档《如何实现弹出菜单》
|
* 增加文档《如何实现弹出菜单》
|
||||||
|
@ -108,20 +108,26 @@ static widget_t* dialog_create_label(const char* text) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret_t dialog_toast(const char* text, uint32_t duration) {
|
ret_t dialog_toast(const char* text, uint32_t duration) {
|
||||||
|
char params[128];
|
||||||
|
int32_t margin = 10;
|
||||||
widget_t* label = NULL;
|
widget_t* label = NULL;
|
||||||
widget_t* dialog = 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);
|
label = dialog_create_label(text);
|
||||||
return_value_if_fail(label != NULL, RET_OOM);
|
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);
|
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_ANIM_HINT, "fade(duration=500)");
|
||||||
widget_set_prop_str(dialog, WIDGET_PROP_THEME, "dialog_toast");
|
widget_set_prop_str(dialog, WIDGET_PROP_THEME, "dialog_toast");
|
||||||
widget_add_child(dialog, label);
|
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_on(dialog, EVT_POINTER_UP, on_ok_to_quit, dialog);
|
||||||
widget_add_timer(dialog, on_timer_to_quit, duration);
|
widget_add_timer(dialog, on_timer_to_quit, duration);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user