improve scroll view

This commit is contained in:
lixianjing 2019-11-28 15:17:16 +08:00
parent 461b5299fc
commit 00722c8c44
8 changed files with 38 additions and 97 deletions

View File

@ -1,14 +1,15 @@
# 最新动态
* 2019/11/28
* 修复preview ui预览dialog时拖动dialog出现残影的问题。
* 引入引用计数协助管理widget的生命周期。
* 完善combobox弹出对话框位置的问题。
* 完善vgcanvas感谢智明提供补丁
* 修复 preview ui 预览 dialog 时,拖动 dialog 出现残影的问题。
* 引入引用计数协助管理 widget 的生命周期。
* 完善 combobox 弹出对话框位置的问题。
* 完善 vgcanvas感谢智明提供补丁
* 完善 scroll view感谢朝泽提供补丁
* 2019/11/27
* 完善edit/mledit (感谢智明提供补丁)。
* 完善agge (感谢智明提供补丁)。
* 完善 edit/mledit (感谢智明提供补丁)。
* 完善 agge (感谢智明提供补丁)。
* 2019/11/26
* 完善 log (感谢大恒提供补丁)。

View File

@ -33,16 +33,6 @@ static widget_t* hscrollable_get_widget(hscrollable_t* hscrollable) {
return hscrollable != NULL ? hscrollable->widget : NULL;
}
static ret_t hscrollable_invalidate_self(hscrollable_t* hscrollable) {
rect_t r;
widget_t* widget = hscrollable_get_widget(hscrollable);
return_value_if_fail(hscrollable != NULL && widget != NULL, RET_BAD_PARAMS);
widget->dirty = FALSE;
r = rect_init(widget->x, widget->y, widget->w, widget->h);
return widget_invalidate(widget->parent, &r);
}
static ret_t hscrollable_on_pointer_down(hscrollable_t* hscrollable, pointer_event_t* e) {
velocity_t* v = &(hscrollable->velocity);
@ -83,7 +73,7 @@ static ret_t hscrollable_on_scroll_done(void* ctx, event_t* e) {
return_value_if_fail(hscrollable != NULL, RET_BAD_PARAMS);
hscrollable->wa = NULL;
hscrollable_invalidate_self(hscrollable);
widget_invalidate_force(hscrollable_get_widget(hscrollable), NULL);
return RET_REMOVE;
}
@ -190,7 +180,7 @@ ret_t hscrollable_on_event(hscrollable_t* hscrollable, event_t* e) {
if (hscrollable->dragged) {
hscrollable_on_pointer_move(hscrollable, evt);
hscrollable_invalidate_self(hscrollable);
widget_invalidate_force(hscrollable_get_widget(hscrollable), NULL);
} else {
int32_t delta = evt->x - hscrollable->down.x;
@ -214,29 +204,6 @@ ret_t hscrollable_on_event(hscrollable_t* hscrollable, event_t* e) {
return ret;
}
ret_t hscrollable_invalidate(hscrollable_t* hscrollable, rect_t* r) {
rect_t r_self;
widget_t* widget = hscrollable_get_widget(hscrollable);
return_value_if_fail(hscrollable != NULL && widget != NULL, RET_BAD_PARAMS);
r_self = rect_init(0, 0, widget->w, widget->h);
r->x -= hscrollable->xoffset;
*r = rect_intersect(r, &r_self);
r->x += widget->x;
r->y += widget->y;
if (r->w <= 0 || r->h <= 0) {
return RET_OK;
}
if (widget->parent) {
widget_invalidate(widget->parent, r);
}
return RET_OK;
}
ret_t hscrollable_on_paint_children(hscrollable_t* hscrollable, canvas_t* c) {
rect_t r_save;
widget_t* widget = hscrollable_get_widget(hscrollable);
@ -296,7 +263,7 @@ ret_t hscrollable_set_prop(hscrollable_t* hscrollable, const char* name, const v
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_XOFFSET)) {
hscrollable->xoffset = value_int(v);
hscrollable_invalidate_self(hscrollable);
widget_invalidate_force(hscrollable_get_widget(hscrollable), NULL);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_YOFFSET)) {
return RET_OK;

View File

@ -52,7 +52,6 @@ ret_t hscrollable_set_xoffset(hscrollable_t* hscrollable, int32_t xoffset);
ret_t hscrollable_set_virtual_w(hscrollable_t* hscrollable, int32_t virtual_w);
ret_t hscrollable_set_always_scrollable(hscrollable_t* hscrollable, bool_t always_scrollable);
ret_t hscrollable_invalidate(hscrollable_t* hscrollable, rect_t* r);
ret_t hscrollable_on_event(hscrollable_t* hscrollable, event_t* e);
ret_t hscrollable_get_prop(hscrollable_t* hscrollable, const char* name, value_t* v);
ret_t hscrollable_set_prop(hscrollable_t* hscrollable, const char* name, const value_t* v);

View File

@ -732,7 +732,7 @@ static ret_t widget_remove_child_prepare(widget_t* widget, widget_t* child) {
ret_t widget_remove_child(widget_t* widget, widget_t* child) {
return_value_if_fail(widget != NULL && child != NULL, RET_BAD_PARAMS);
widget_remove_child_prepare(widget, child);
widget_remove_child_prepare(widget, child);
child->parent = NULL;
return darray_remove(widget->children, child);
@ -3130,7 +3130,7 @@ static ret_t widget_on_visit_focusable(void* ctx, const void* data) {
widget_t* widget = WIDGET(data);
darray_t* all_focusable = (darray_t*)ctx;
if (!(widget->visible) || !(widget->enable)) {
if (!(widget->sensitive) || !(widget->visible) || !(widget->enable)) {
return RET_SKIP;
}

View File

@ -23,12 +23,30 @@
#include "tkc/mem.h"
ret_t widget_invalidate_default(widget_t* widget, rect_t* r) {
if (widget->vt->scrollable) {
int32_t ox = widget_get_prop_int(widget, WIDGET_PROP_XOFFSET, 0);
int32_t oy = widget_get_prop_int(widget, WIDGET_PROP_YOFFSET, 0);
rect_t r_self = rect_init(0, 0, widget->w, widget->h);
if (ox != 0) {
r->x -= ox;
r->w += ox + 1;
}
if (oy > 0) {
r->y -= oy;
r->h += oy + 1;
}
*r = rect_intersect(r, &r_self);
}
if (r->w <= 0 || r->h <= 0) {
return RET_OK;
}
r->x += widget->x;
r->y += widget->y;
if (widget->astyle != NULL) {
int32_t ox = tk_abs(style_get_int(widget->astyle, STYLE_ID_X_OFFSET, 0));
int32_t oy = tk_abs(style_get_int(widget->astyle, STYLE_ID_Y_OFFSET, 0));

View File

@ -172,13 +172,6 @@ static ret_t candidates_on_event(widget_t* widget, event_t* e) {
return hscrollable_on_event(candidates->hscrollable, e);
}
static ret_t candidates_invalidate(widget_t* widget, rect_t* r) {
candidates_t* candidates = CANDIDATES(widget);
return_value_if_fail(candidates != NULL, RET_BAD_PARAMS);
return hscrollable_invalidate(candidates->hscrollable, r);
}
static ret_t candidates_on_paint_children(widget_t* widget, canvas_t* c) {
candidates_t* candidates = CANDIDATES(widget);
return_value_if_fail(candidates != NULL, RET_BAD_PARAMS);
@ -206,7 +199,6 @@ TK_DECL_VTABLE(candidates) = {.size = sizeof(candidates_t),
.parent = TK_PARENT_VTABLE(widget),
.create = candidates_create,
.on_event = candidates_on_event,
.invalidate = candidates_invalidate,
.on_paint_self = candidates_on_paint_self,
.on_paint_children = candidates_on_paint_children,
.get_prop = candidates_get_prop,

View File

@ -29,35 +29,6 @@
#include "base/image_manager.h"
#include "widget_animators/widget_animator_scroll.h"
ret_t scroll_view_invalidate(widget_t* widget, rect_t* r) {
scroll_view_t* scroll_view = SCROLL_VIEW(widget);
rect_t r_self = rect_init(widget->x, widget->y, widget->w, widget->h);
r->x += widget->x;
r->y += widget->y;
r->x -= scroll_view->xoffset;
r->y -= scroll_view->yoffset;
*r = rect_intersect(r, &r_self);
if (r->w <= 0 || r->h <= 0) {
return RET_OK;
}
if (widget->parent) {
widget_invalidate(widget->parent, r);
}
return RET_OK;
}
ret_t scroll_view_invalidate_self(widget_t* widget) {
rect_t r = rect_init(widget->x, widget->y, widget->w, widget->h);
widget->dirty = FALSE;
return widget_invalidate(widget->parent, &r);
}
static ret_t scroll_view_update_virtual_size(widget_t* widget) {
int32_t virtual_w = 0;
int32_t virtual_h = 0;
@ -91,9 +62,11 @@ static ret_t scroll_view_on_layout_children(widget_t* widget) {
if (scroll_view->on_layout_children) {
scroll_view->on_layout_children(widget);
} else {
scroll_view_set_offset(widget, 0, 0);
widget_layout_children_default(widget);
scroll_view_update_virtual_size(widget);
scroll_view_set_offset(widget,
tk_min(scroll_view->xoffset, (scroll_view->virtual_w - widget->w)),
tk_min(scroll_view->yoffset, (scroll_view->virtual_h - widget->h)));
}
return RET_OK;
@ -119,7 +92,7 @@ static ret_t scroll_view_on_scroll_done(void* ctx, event_t* e) {
return_value_if_fail(widget != NULL && scroll_view != NULL, RET_BAD_PARAMS);
scroll_view->wa = NULL;
scroll_view_invalidate_self(widget);
widget_invalidate_force(widget, NULL);
return RET_REMOVE;
}
@ -373,7 +346,7 @@ static ret_t scroll_view_on_event(widget_t* widget, event_t* e) {
if (scroll_view->dragged) {
scroll_view_on_pointer_move(scroll_view, evt);
scroll_view_invalidate_self(widget);
widget_invalidate_force(widget, NULL);
} else {
if (scroll_view_is_dragged(widget, evt)) {
pointer_event_t abort = *evt;
@ -487,12 +460,12 @@ static ret_t scroll_view_set_prop(widget_t* widget, const char* name, const valu
} else if (tk_str_eq(name, WIDGET_PROP_XOFFSET)) {
scroll_view->xoffset = value_int(v);
scroll_view_notify_scrolled(scroll_view);
scroll_view_invalidate_self(widget);
widget_invalidate_force(widget, NULL);
return RET_OK;
} else if (tk_str_eq(name, WIDGET_PROP_YOFFSET)) {
scroll_view->yoffset = value_int(v);
scroll_view_notify_scrolled(scroll_view);
scroll_view_invalidate_self(widget);
widget_invalidate_force(widget, NULL);
return RET_OK;
}
@ -513,7 +486,6 @@ TK_DECL_VTABLE(scroll_view) = {.size = sizeof(scroll_view_t),
.parent = TK_PARENT_VTABLE(widget),
.create = scroll_view_create,
.on_event = scroll_view_on_event,
.invalidate = scroll_view_invalidate,
.on_layout_children = scroll_view_on_layout_children,
.on_paint_children = scroll_view_on_paint_children,
.on_add_child = scroll_view_on_add_child,
@ -556,7 +528,7 @@ ret_t scroll_view_set_offset(widget_t* widget, int32_t xoffset, int32_t yoffset)
scroll_view->xoffset = xoffset;
scroll_view->yoffset = yoffset;
scroll_view_invalidate_self(widget);
widget_invalidate_force(widget, NULL);
return RET_OK;
}

View File

@ -124,13 +124,6 @@ static ret_t tab_button_group_set_prop(widget_t* widget, const char* name, const
return hscrollable_set_prop(tab_button_group->hscrollable, name, v);
}
static ret_t tab_button_group_invalidate(widget_t* widget, rect_t* r) {
tab_button_group_t* tab_button_group = TAB_BUTTON_GROUP(widget);
return_value_if_fail(tab_button_group != NULL, RET_BAD_PARAMS);
return hscrollable_invalidate(tab_button_group->hscrollable, r);
}
static ret_t tab_button_group_on_paint_children(widget_t* widget, canvas_t* c) {
tab_button_group_t* tab_button_group = TAB_BUTTON_GROUP(widget);
return_value_if_fail(tab_button_group != NULL, RET_BAD_PARAMS);
@ -183,7 +176,6 @@ TK_DECL_VTABLE(tab_button_group) = {.size = sizeof(tab_button_group_t),
.create = tab_button_group_create,
.set_prop = tab_button_group_set_prop,
.get_prop = tab_button_group_get_prop,
.invalidate = tab_button_group_invalidate,
.on_event = tab_button_group_on_event,
.on_destroy = tab_button_group_on_destroy,
.on_paint_children = tab_button_group_on_paint_children,