Need a Button widget with separate on_pressed and on_released events

I need a button that produces a message when the LMB is pressed (on_pressed) and another message when the LMB is released (on_released). The standard button seems to produce on_pressed message only when the LMB is released. So, I’m looking for a solution. I can’t find such a button widget, so the only option I see is a custom button. I’ve looked at the Button code, and it doesn’t seem too difficult to add the desired functionality, but since I’m very new to Iced, I could be wrong and it might actually be more complicated than it seems. Please tell me if I missed something and such a button already exists.

You can wrap any widget (such as a text label, for example) with a mouse_area which provides both on_press and on_release:

Thank you. I suppose this approach won’t work with a touchscreen. Is there something like a ‘touch_area’ or anything similar?

It should work with touchscreens too, despite the mouse_* name

You can Ctrl+F Event::Touch in that module I linked you to.

I see. You’re right. Thanks again.

1 Like