From 9d3fb418969c13b93f01a6b0342a1cd8d02e9b6c Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Sat, 8 Jan 2022 13:48:35 +0100 Subject: [PATCH] feat(slider): consider ext_click_area on the knob with LV_OBJ_FLAG_ADV_HITTEST --- docs/widgets/core/slider.md | 2 ++ src/widgets/lv_slider.c | 13 ++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/widgets/core/slider.md b/docs/widgets/core/slider.md index c3b178b44..101eb91eb 100644 --- a/docs/widgets/core/slider.md +++ b/docs/widgets/core/slider.md @@ -33,6 +33,8 @@ The mode can be changed with `lv_slider_set_mode(slider, LV_SLIDER_MODE_...)` Normally, the slider can be adjusted either by dragging the knob, or by clicking on the slider bar. In the latter case the knob moves to the point clicked and slider value changes accordingly. In some cases it is desirable to set the slider to react on dragging the knob only. This feature is enabled by adding the `LV_OBJ_FLAG_ADV_HITTEST`: `lv_obj_add_flag(slider, LV_OBJ_FLAG_ADV_HITTEST)`. +The extended click area (set by `lv_obj_set_ext_click_area(slider, value)`) increases to knob's click area. + ## Events - `LV_EVENT_VALUE_CHANGED` Sent while the slider is being dragged or changed with keys. The event is sent continuously while the slider is dragged and once when released. Use `lv_slider_is_dragged` to determine whether the Slider is still being dragged or has just been released. diff --git a/src/widgets/lv_slider.c b/src/widgets/lv_slider.c index 6779fb7b0..46c02a106 100644 --- a/src/widgets/lv_slider.c +++ b/src/widgets/lv_slider.c @@ -109,13 +109,20 @@ static void lv_slider_event(const lv_obj_class_t * class_p, lv_event_t * e) /*Advanced hit testing: react only on dragging the knob(s)*/ if(code == LV_EVENT_HIT_TEST) { lv_hit_test_info_t * info = lv_event_get_param(e); + lv_coord_t ext_click_area = obj->spec_attr ? obj->spec_attr->ext_click_pad : 0; /*Ordinary slider: was the knob area hit?*/ - info->res = _lv_area_is_point_on(&slider->right_knob_area, info->point, 0); + lv_area_t a; + lv_area_copy(&a, &slider->right_knob_area); + lv_area_increase(&a, ext_click_area, ext_click_area); + info->res = _lv_area_is_point_on(&a, info->point, 0); - /*There's still a change we have a hit, if we have another knob*/ + /*There's still a chance that there is a hit if there is another knob*/ if((info->res == false) && (type == LV_SLIDER_MODE_RANGE)) { - info->res = _lv_area_is_point_on(&slider->left_knob_area, info->point, 0); + lv_area_t a; + lv_area_copy(&a, &slider->left_knob_area); + lv_area_increase(&a, ext_click_area, ext_click_area); + info->res = _lv_area_is_point_on(&a, info->point, 0); } } else if(code == LV_EVENT_PRESSED) {