slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.24k stars 581 forks source link

Allow disabling combobox value changing with scrolling #5929

Open JakubKoralewski opened 1 month ago

JakubKoralewski commented 1 month ago

When a ComboBox is set inside ScrollView it is easy to make the mistake of editing the ComboBox by hovering over the ComboBox and scrolling on the ComboBox instead of an empty part of the window. When ComboBox.width: 100%; this situation is inevitable.

I tried getting around this with a wrapper TouchArea catching scroll events, but looks like the TouchArea would need to be inside the ComboBox for this to work.

import { AboutSlint, Button, VerticalBox, ScrollView, ComboBox } from "std-widgets.slint";
export component Demo {
    height: 300px;
    ScrollView 
    {
        VerticalLayout {
            padding: 50px;
            for i in 5 : TouchArea {
                height: 100px;
                ComboBox  {
                    height: 100%;
                    width: 100%;

                    model: ["setting-a", "setting-b", "setting-c"];
                }
                scroll-event(ev) => {
                    EventResult.accept // since this controls whether parent element gets the event, this does nothing for the child combobox
                }
            }
            Text {
                text: "----";
            }
            for i in 5 : ComboBox  {
                height: 100px;
                model: ["setting-a", "setting-b", "setting-c"];
            }
        }
    }
}
ogoffart commented 1 month ago

Thanks for the bug report. We should do the same as what the platform natively does. I tried Qt and the wheel does change the combobox even within scroll area. On windows, it seems that the wheel only change the content of the combobox if it has focus.