mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 03:58:33 +08:00
improve set need relayout children
This commit is contained in:
parent
f9375ba632
commit
b7b63d9928
@ -9,6 +9,7 @@
|
||||
* 完善 scroll view(感谢朝泽提供补丁)。
|
||||
* 完善 销毁子控件的处理(感谢培煌提供补丁)。
|
||||
* 完善 native\_window\_sdl\_resize (感谢 [qianfan-Zhao](https://github.com/qianfan-Zhao) 提供补丁)。
|
||||
* 完善 set need relayout children。
|
||||
|
||||
* 2019/11/27
|
||||
* 完善 edit/mledit (感谢智明提供补丁)。
|
||||
|
@ -27,6 +27,10 @@ uint32_t idle_add(idle_func_t on_idle, void* ctx) {
|
||||
return idle_manager_add(idle_manager(), on_idle, ctx);
|
||||
}
|
||||
|
||||
bool_t idle_exist(idle_func_t on_idle, void* ctx) {
|
||||
return idle_manager_exist(idle_manager(), on_idle, ctx);
|
||||
}
|
||||
|
||||
ret_t idle_remove(uint32_t idle_id) {
|
||||
return idle_manager_remove(idle_manager(), idle_id);
|
||||
}
|
||||
|
@ -124,6 +124,9 @@ ret_t idle_dispatch(void);
|
||||
*/
|
||||
uint32_t idle_count(void);
|
||||
|
||||
/*internal use*/
|
||||
bool_t idle_exist(idle_func_t on_idle, void* ctx);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_IDLE_H*/
|
||||
|
@ -60,6 +60,35 @@ static ret_t widget_remove_child_prepare(widget_t* widget, widget_t* child);
|
||||
typedef widget_t* (*widget_find_wanted_focus_widget_t)(widget_t* widget, darray_t* all_focusable);
|
||||
static ret_t widget_move_focus(widget_t* widget, widget_find_wanted_focus_widget_t find);
|
||||
|
||||
static ret_t delay_work_in_idle(const idle_info_t* info) {
|
||||
widget_t* widget = WIDGET(info->ctx);
|
||||
ENSURE(widget != NULL && widget->vt != NULL);
|
||||
|
||||
/*if ref_count == 1 means the widget is pending to destroy*/
|
||||
if (widget->ref_count > 1) {
|
||||
if (widget->need_update_style) {
|
||||
widget_update_style(widget);
|
||||
}
|
||||
|
||||
if (widget->need_relayout_children) {
|
||||
widget_layout_children(widget);
|
||||
}
|
||||
}
|
||||
widget_unref(widget);
|
||||
|
||||
return RET_REMOVE;
|
||||
}
|
||||
|
||||
static ret_t widget_add_delay_work(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL && widget->vt != NULL, RET_BAD_PARAMS);
|
||||
if (!idle_exist(delay_work_in_idle, widget)) {
|
||||
widget_ref(widget);
|
||||
idle_add(delay_work_in_idle, widget);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t widget_set_need_update_style(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL, RET_BAD_PARAMS);
|
||||
|
||||
@ -90,6 +119,8 @@ ret_t widget_update_style(widget_t* widget) {
|
||||
}
|
||||
|
||||
static ret_t widget_real_destroy(widget_t* widget) {
|
||||
ENSURE(widget->ref_count == 1);
|
||||
|
||||
if (widget->vt->on_destroy) {
|
||||
widget->vt->on_destroy(widget);
|
||||
}
|
||||
@ -293,7 +324,7 @@ assets_manager_t* widget_get_assets_manager(widget_t* widget) {
|
||||
assets_manager_t* am = assets_manager();
|
||||
return_value_if_fail(widget != NULL && widget->vt != NULL, am);
|
||||
|
||||
if(widget->assets_manager != NULL) {
|
||||
if (widget->assets_manager != NULL) {
|
||||
return widget->assets_manager;
|
||||
}
|
||||
|
||||
@ -3475,7 +3506,11 @@ bool_t widget_is_window_manager(widget_t* widget) {
|
||||
|
||||
ret_t widget_set_need_relayout_children(widget_t* widget) {
|
||||
return_value_if_fail(widget != NULL, RET_BAD_PARAMS);
|
||||
widget->need_relayout_children = TRUE;
|
||||
|
||||
if (!widget->destroying && widget->children != NULL && widget->children->size > 0) {
|
||||
widget->need_relayout_children = TRUE;
|
||||
widget_add_delay_work(widget);
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
@ -152,3 +152,19 @@ uint32_t idle_manager_count(idle_manager_t* idle_manager) {
|
||||
|
||||
return slist_size(&(idle_manager->idles));
|
||||
}
|
||||
|
||||
bool_t idle_manager_exist(idle_manager_t* idle_manager, idle_func_t on_idle, void* ctx) {
|
||||
slist_node_t* iter = idle_manager->idles.first;
|
||||
|
||||
while (iter != NULL) {
|
||||
idle_info_t* idle = (idle_info_t*)(iter->data);
|
||||
|
||||
if (idle->on_idle == idle->on_idle && idle->ctx == ctx) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
iter = iter->next;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -160,6 +160,8 @@ const idle_info_t* idle_manager_find(idle_manager_t* idle_manager, uint32_t idle
|
||||
*/
|
||||
uint32_t idle_manager_add(idle_manager_t* idle_manager, idle_func_t on_idle, void* ctx);
|
||||
|
||||
bool_t idle_manager_exist(idle_manager_t* idle_manager, idle_func_t on_idle, void* ctx);
|
||||
|
||||
END_C_DECLS
|
||||
|
||||
#endif /*TK_IDLE_MANAGER_H*/
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "base/idle.h"
|
||||
#include "tkc/utils.h"
|
||||
#include "base/idle.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <string>
|
||||
@ -32,7 +33,8 @@ TEST(Idle, basic) {
|
||||
idle_manager_remove_all(idle_manager());
|
||||
|
||||
for (i = 0; i < nr; i++) {
|
||||
ASSERT_EQ(idle_add(on_idle, NULL) > 0, true);
|
||||
ASSERT_EQ(idle_add(on_idle, tk_pointer_from_int(i)) > 0, true);
|
||||
ASSERT_EQ(idle_exist(on_idle, tk_pointer_from_int(i)) > 0, true);
|
||||
ASSERT_EQ(idle_count(), i + 1);
|
||||
}
|
||||
|
||||
@ -42,7 +44,8 @@ TEST(Idle, basic) {
|
||||
ASSERT_EQ(s_log, "o:o:o:o:o:o:o:o:o:o:");
|
||||
|
||||
for (i = 0; i < nr; i++) {
|
||||
uint32_t id = idle_add(on_idle, NULL);
|
||||
uint32_t id = idle_add(on_idle, tk_pointer_from_int(i));
|
||||
ASSERT_EQ(idle_exist(on_idle, tk_pointer_from_int(i)) > 0, true);
|
||||
ASSERT_EQ(id > 0, true);
|
||||
ASSERT_EQ(idle_remove(id), RET_OK);
|
||||
ASSERT_EQ(idle_count(), 0);
|
||||
|
Loading…
Reference in New Issue
Block a user