How to drag the slider in any position of the slider to change the value of the slider? And remove the knob click event? It's like a phone volume control


What MCU/Processor/Board and compiler are you using?

stm32 and Vscood

What LVGL version are you using?


What do you want to achieve?

When we open the navigation bar at the top of the phone, we see a white volume adjustment ui, which is exactly what I want :
1, no knob click event;
2, in any position of the slider can slide, as in the picture, and the progress of the slider and drag distance is relative.


What have you tried so far?

I’ve created the style, but for its event handling, it’s been a week and I still haven’t been able to implement it. I tried using knob only mode:
lv_obj_add_flag(slider, LV_OBJ_FLAG_ADV_HITTESTE)
Trying to get the touch position of the pressed event, calculating the distance moved to update the value of the slider, but obviously I didn’t achieve my goal.

I’m glad there are open source projects like lvgl and forums where I can learn and discuss issues, but it’s a bit difficult, so I’m publishing this article for your help! >.<

Reference implementation:

static void my_slider_event(lv_event_t *e)
    lv_obj_t *slider = lv_event_get_current_target(e);

    lv_indev_t *indev = lv_indev_get_act();
    if (indev == NULL)

    int16_t sensitive = 3;  // // TODO: You can adjust the sensitivity
    lv_point_t vect;
    lv_indev_get_vect(indev, &vect);
    LV_LOG_USER("vect.x: %d, vect.y: %d\n", vect.x, vect.y);
    if (vect.y < -sensitive)
        lv_slider_set_value(slider, (lv_slider_get_value(slider) + 5), LV_ANIM_ON);
    else if (vect.y > sensitive)
        lv_slider_set_value(slider, (lv_slider_get_value(slider) - 5), LV_ANIM_ON);

void my_lv_example_slider(void)
    /*Create a slider in the center of the display*/
    lv_obj_t *slider = lv_slider_create(lv_scr_act());
    lv_obj_set_size(slider, 40, 300);
    lv_obj_add_flag(slider, LV_OBJ_FLAG_ADV_HITTEST);

    lv_obj_add_event_cb(slider, my_slider_event, LV_EVENT_HIT_TEST, NULL);