improve widget_get_offset

This commit is contained in:
lixianjing 2022-08-24 18:24:36 +08:00
parent 9c13211e61
commit d26d3e59ef
5 changed files with 21 additions and 5 deletions

View File

@ -1,5 +1,8 @@
# 最新动态
2022/08/24
* 统一get\_offset的逻辑(感谢智明提供补丁)
2022/08/23
* 完善 fscript\_locals\_get
* 完善 fscripts 示例。

View File

@ -3611,12 +3611,20 @@ ret_t widget_get_prop_default_value(widget_t* widget, const char* name, value_t*
return ret;
}
static ret_t widget_get_offset(widget_t* widget, xy_t* out_x, xy_t* out_y) {
ret_t widget_get_offset(widget_t* widget, xy_t* out_x, xy_t* out_y) {
return_value_if_fail(widget != NULL && out_x != NULL && out_y != NULL, RET_BAD_PARAMS);
*out_x = 0;
*out_y = 0;
if (widget->vt != NULL && widget->vt->get_offset != NULL) {
return widget->vt->get_offset(widget, out_x, out_y);
} else if (widget->vt != NULL && widget->vt->get_prop != NULL) {
value_t v;
if (widget->vt->get_prop(widget, WIDGET_PROP_XOFFSET, &v) == RET_OK) {
*out_x = value_int(&v);
}
if (widget->vt->get_prop(widget, WIDGET_PROP_YOFFSET, &v) == RET_OK) {
*out_y = value_int(&v);
}
}
return RET_OK;
}

View File

@ -169,6 +169,10 @@ struct _widget_vtable_t {
widget_invalidate_t invalidate;
widget_find_target_t find_target;
widget_is_point_in_t is_point_in;
/**
* WIDGET_PROP_X/YOFFSET
* 使
*/
widget_get_offset_t get_offset;
widget_auto_adjust_size_t auto_adjust_size;
widget_get_prop_default_value_t get_prop_default_value;
@ -3217,6 +3221,7 @@ ret_t widget_on_keydown(widget_t* widget, key_event_t* e);
*/
ret_t widget_on_keyup(widget_t* widget, key_event_t* e);
ret_t widget_get_offset(widget_t* widget, xy_t* out_x, xy_t* out_y);
ret_t widget_on_wheel(widget_t* widget, wheel_event_t* e);
ret_t widget_on_multi_gesture(widget_t* widget, multi_gesture_event_t* e);
ret_t widget_on_pointer_down(widget_t* widget, pointer_event_t* e);

View File

@ -553,13 +553,13 @@ BEGIN_C_DECLS
/**
* @const WIDGET_PROP_XOFFSET
* X方向的偏移
* X方向的偏移 get_offset get_offset
*/
#define WIDGET_PROP_XOFFSET "xoffset"
/**
* @const WIDGET_PROP_YOFFSET
* Y方向的偏移
* Y方向的偏移 get_offset get_offset
*/
#define WIDGET_PROP_YOFFSET "yoffset"

View File

@ -29,8 +29,8 @@ ret_t widget_invalidate_default(widget_t* widget, const rect_t* rect) {
rect_t r_self = rect_init(0, 0, widget->w, widget->h);
if (!widget->dirty) {
int32_t ox = widget_get_prop_int(widget, WIDGET_PROP_XOFFSET, 0);
int32_t oy = widget_get_prop_int(widget, WIDGET_PROP_YOFFSET, 0);
int32_t ox = 0, oy = 0;
widget_get_offset(widget, &ox, &oy);
if (ox > 0) {
r->x -= ox;
}