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.55k stars 601 forks source link

Make it possible to handle double clicks #2774

Closed tronical closed 11 months ago

tronical commented 1 year ago

Discussed in https://github.com/slint-ui/slint/discussions/2772

Originally posted by **pcevent** May 24, 2023 How do I capture mouse double-click events?

At the moment the internal mouse press and release events have a click count, which the built-in Text item uses to handle double clicks. We should either make this API public or design a new API to make it possible to handle double/triple/etc. clicking in Slint code.

ogoffart commented 12 months ago

Some things we could so:

I think we should do both eventually. I have the feeling that in most cases user don't want the normal clicked handler to be run if (and only if) there is no double click.

I believe we should do the following:

hunger commented 11 months ago

When doing a five-time click you get events with a click count of 1, 2, 3, 4 and 5 and have no idea whether the 5-event will eventually be followed by 6, 7, ... or not. That is not very useful, especially as we the timeout for "double clicks" is not exposed to the public as far as I can tell. So a user have no way to wait for the right amount of time to decide that my 5-event was indeed the last event to happen.

A multi-clicked callback with a click count argument is probably more generically useful. Someone will want to use a triple-click at some point :-)

tronical commented 11 months ago

I believe we should do the following: [ ... ]

I agree

A multi-clicked callback with a click count argument is probably more generically useful. Someone will want to use a triple-click at some point :-)

I don't think it's necessary to go all the generic way. Honestly, with a mouse event double click is a rather rare pattern (even on Windows I'd say single click is dominant). With finger input double "tap" is not an established pattern IMO. With pencils a double click (on the pencil's button for example) is a good pattern, but I have yet to see a triple or n-click (n > 3).

I'm in favor of a pragmatic double-click and we can worry about a multi-click in the (unlikely) event that it becomes popular.

hunger commented 11 months ago

I am tempted to move the implementation into core/input.rs and send a MouseClicked event from there in addition to the MousePressed/Released, mostly to keep all the lower level mouse handling in one place. But looking at the Text item: That seems to be happy with just the click count it gets, so this might actually be over-doing it and the TouchArea might indeed be the best place to implement this.

tronical commented 11 months ago

This was implemented in #4060 :-)