mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-11-30 19:18:53 +08:00
improve layout
This commit is contained in:
parent
b63c1db91b
commit
6776301952
@ -62,48 +62,6 @@ static ret_t widget_on_paint_done(widget_t* widget, canvas_t* c);
|
||||
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 layout_children_need(widget_t* widget) {
|
||||
WIDGET_FOR_EACH_CHILD_BEGIN(widget, iter, i)
|
||||
if (widget->need_relayout_children) {
|
||||
widget_layout_children(widget);
|
||||
} else {
|
||||
layout_children_need(iter);
|
||||
}
|
||||
WIDGET_FOR_EACH_CHILD_END()
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
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);
|
||||
} else {
|
||||
layout_children_need(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);
|
||||
|
||||
@ -3810,11 +3768,6 @@ ret_t widget_set_need_relayout_children(widget_t* widget) {
|
||||
|
||||
if (!widget->destroying && widget->children != NULL && widget->children->size > 0) {
|
||||
widget->need_relayout_children = TRUE;
|
||||
if (widget_is_window_opened(widget)) {
|
||||
widget_t* win = widget_get_window(widget);
|
||||
/*relayout win to avoid adding too many idles*/
|
||||
widget_add_delay_work(win);
|
||||
}
|
||||
}
|
||||
|
||||
return RET_OK;
|
||||
|
@ -251,6 +251,18 @@ ret_t window_manager_close_window_force(widget_t* widget, widget_t* window) {
|
||||
return wm->vt->close_window_force(widget, window);
|
||||
}
|
||||
|
||||
ret_t window_manager_check_and_layout(widget_t* widget) {
|
||||
WIDGET_FOR_EACH_CHILD_BEGIN(widget, iter, i)
|
||||
if (iter->need_relayout_children) {
|
||||
widget_layout_children(iter);
|
||||
} else {
|
||||
window_manager_check_and_layout(iter);
|
||||
}
|
||||
WIDGET_FOR_EACH_CHILD_END()
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
ret_t window_manager_paint(widget_t* widget) {
|
||||
window_manager_t* wm = WINDOW_MANAGER(widget);
|
||||
return_value_if_fail(wm != NULL && wm->vt != NULL, RET_BAD_PARAMS);
|
||||
|
@ -255,6 +255,19 @@ ret_t window_manager_close_window_force(widget_t* widget, widget_t* window);
|
||||
*/
|
||||
ret_t window_manager_paint(widget_t* widget);
|
||||
|
||||
/**
|
||||
* @method window_manager_check_and_layout
|
||||
* 检查各个窗口的layout并且把有需要的执行对应的layout。
|
||||
*
|
||||
*> 仅由主循环调用。
|
||||
*
|
||||
* @annotation ["private"]
|
||||
* @param {widget_t*} widget 窗口管理器对象。
|
||||
*
|
||||
* @return {ret_t} 返回RET_OK表示成功,否则表示失败。
|
||||
*/
|
||||
ret_t window_manager_check_and_layout(widget_t* widget);
|
||||
|
||||
/**
|
||||
* @method window_manager_dispatch_input_event
|
||||
* 分发输入事件。
|
||||
|
@ -173,6 +173,7 @@ static ret_t main_loop_simple_step(main_loop_t* l) {
|
||||
main_loop_dispatch_events(loop);
|
||||
event_source_manager_dispatch(loop->event_source_manager);
|
||||
|
||||
window_manager_check_and_layout(loop->base.wm);
|
||||
window_manager_paint(loop->base.wm);
|
||||
|
||||
return RET_OK;
|
||||
|
@ -128,6 +128,7 @@ ret_t window_manager_default_snap_curr_window(widget_t* widget, widget_t* curr_w
|
||||
return_value_if_fail(wm != NULL && curr_win != NULL, RET_BAD_PARAMS);
|
||||
|
||||
c = native_window_get_canvas(wm->native_window);
|
||||
window_manager_check_and_layout(widget);
|
||||
|
||||
#ifdef WITH_NANOVG_GPU
|
||||
vg = lcd_get_vgcanvas(c->lcd);
|
||||
@ -168,6 +169,7 @@ ret_t window_manager_default_snap_prev_window(widget_t* widget, widget_t* prev_w
|
||||
|
||||
c = native_window_get_canvas(wm->native_window);
|
||||
dialog_highlighter = wm->dialog_highlighter;
|
||||
window_manager_check_and_layout(widget);
|
||||
|
||||
WIDGET_FOR_EACH_CHILD_BEGIN_R(widget, iter, i)
|
||||
if (iter == prev_win) {
|
||||
|
Loading…
Reference in New Issue
Block a user