From 6f86cebc9efe85dad1a259e882a416070befdb39 Mon Sep 17 00:00:00 2001 From: lixianjing Date: Thu, 27 Jul 2023 18:23:57 +0800 Subject: [PATCH] improve hscrollable --- docs/changes.md | 3 ++- src/base/hscrollable.c | 12 ++++++++++-- src/base/hscrollable.h | 2 ++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/docs/changes.md b/docs/changes.md index fa3cea9f6..d5202187c 100644 --- a/docs/changes.md +++ b/docs/changes.md @@ -2,7 +2,8 @@ 2023/07/27 * 修改克隆label控件时没有拷贝ellipses属性的问题(感谢朝泽提供补丁) - * 修复克隆 rich_text 对象失败的问题(感谢智明提供补丁) + * 修复克隆 rich\_text 对象失败的问题(感谢智明提供补丁) + * 修复在 scrollable 的 tab\_button\_group 上面快速点击有概率会导致瞬移的问题(感谢智明提供补丁) 2023/07/26 * 修改Windows下路径带中文时fs\_os\_get\_exe的返回结果不是utf8的问题(感谢朝泽提供补丁) diff --git a/src/base/hscrollable.c b/src/base/hscrollable.c index bceb8318c..8dbb6eff2 100644 --- a/src/base/hscrollable.c +++ b/src/base/hscrollable.c @@ -169,8 +169,8 @@ ret_t hscrollable_on_event(hscrollable_t* hscrollable, event_t* e) { break; case EVT_POINTER_UP: { pointer_event_t* evt = (pointer_event_t*)e; - int32_t dx = evt->x - hscrollable->down.x; - if (dx) { + int32_t dx = tk_abs(evt->x - hscrollable->down.x); + if (dx > hscrollable->drag_threshold) { hscrollable_on_pointer_up(hscrollable, (pointer_event_t*)e); } hscrollable->dragged = FALSE; @@ -305,6 +305,7 @@ hscrollable_t* hscrollable_create(widget_t* widget) { hscrollable->widget = widget; hscrollable->enable_hscroll_animator = TRUE; + hscrollable->drag_threshold = TK_DRAG_THRESHOLD; return hscrollable; } @@ -323,6 +324,13 @@ ret_t hscrollable_set_xoffset(hscrollable_t* hscrollable, int32_t xoffset) { return RET_OK; } +ret_t hscrollable_set_drag_threshold(hscrollable_t* hscrollable, uint32_t drag_threshold) { + return_value_if_fail(hscrollable != NULL, RET_BAD_PARAMS); + hscrollable->drag_threshold = drag_threshold; + + return RET_OK; +} + ret_t hscrollable_set_virtual_w(hscrollable_t* hscrollable, int32_t virtual_w) { return_value_if_fail(hscrollable != NULL, RET_BAD_PARAMS); hscrollable->virtual_w = virtual_w; diff --git a/src/base/hscrollable.h b/src/base/hscrollable.h index 22a47e98e..adac2632d 100644 --- a/src/base/hscrollable.h +++ b/src/base/hscrollable.h @@ -40,6 +40,7 @@ typedef struct _hscrollable_t { int32_t xoffset_end; int32_t xoffset_save; int32_t virtual_w; + uint32_t drag_threshold; widget_t* widget; velocity_t velocity; @@ -51,6 +52,7 @@ typedef struct _hscrollable_t { hscrollable_t* hscrollable_create(widget_t* widget); 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_drag_threshold(hscrollable_t* hscrollable, uint32_t drag_threshold); ret_t hscrollable_set_always_scrollable(hscrollable_t* hscrollable, bool_t always_scrollable); ret_t hscrollable_set_enable_hscroll_animator(hscrollable_t* hscrollable, bool_t enable_hscroll_animator);