mirror of
https://gitee.com/zlgopen/awtk.git
synced 2024-12-02 03:58:33 +08:00
improve widget_get_offset
This commit is contained in:
parent
9c13211e61
commit
d26d3e59ef
@ -1,5 +1,8 @@
|
||||
# 最新动态
|
||||
|
||||
2022/08/24
|
||||
* 统一get\_offset的逻辑(感谢智明提供补丁)
|
||||
|
||||
2022/08/23
|
||||
* 完善 fscript\_locals\_get
|
||||
* 完善 fscripts 示例。
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user