Search code examples
kivykivy-language

Kivy ScrollView Smooth Scrolling with Mac Touchpad


On a macBook with trackpad, default Kivy <ScrollView> objects do not scroll smoothly when using two-finger-scrolling (i.e. not using a scrollbar). When fingers are lifted from the trackpad, the scroll stops immediately. I want to be able to more closely mimic Apple's smooth scrolling behavior, where the list coasts to a stop rather than stopping instantly.


Solution

  • The smooth-scrolling effect can be achieved by setting two properties of the ScrollView object: smooth_scroll_end and scroll_wheel_distance.

    To set it globally, attach the properties to a <ScrollView> rule:

    <ScrollView>
        smooth_scroll_end: 25
        scroll_wheel_distance: 30
        ...
    

    or to set it for an individual `ScrollView' object,

    <My_ScrollView_Object>
        smooth_scroll_end: 25
        scroll_wheel_distance: 30
        ...
    

    The above values smooth_scroll_end: 25 and scroll_wheel_distance: 30 are not the default values for these properties; instead, they are (at least on my 2020 macBook Pro) closer to native Mac smooth scrolling behavior. These values may not be optimal for other hardware/platforms.

    Information on the smooth scrolling properties of ScrollView objects can be found in the Kivy documentation:

    smooth_scroll_end - Whether smooth scroll end should be used when scrolling with the mouse-wheel and the factor of transforming the scroll distance to velocity. This option also enables velocity addition meaning if you scroll more, you will scroll faster and further. The recommended value is 10. The velocity is calculated as scroll_wheel_distance * smooth_scroll_end.

    smooth_scroll_end is a NumericProperty and defaults to None.

    scroll_wheel_distance - Distance to move when scrolling with a mouse wheel. It is advisable that you base this value on the dpi of your target device’s screen.

    scroll_wheel_distance is a NumericProperty , defaults to 20 pixels.