iced-rs / iced

A cross-platform GUI library for Rust, inspired by Elm
https://iced.rs
MIT License
22.96k stars 1.06k forks source link

Add alternative (right click) for buttons #2395

Closed Gremious closed 3 weeks ago

Gremious commented 3 weeks ago

My app needs buttons that are right-clickable as a secondary, alternative action.

I am adding a very simple on_press_alt to go alongside on_press:

  1. A button must still have on_press or else be disabled, as usual. Whether on_press_alt is missing or present is irrelevant.
  2. As such, no on_press_alt_maybe - only removing the on_press counts as disabling the button. a) Which is why it checks whether both are present before allowing state.is_pressed_alt = true;

I have tested this on the counter example. It sends different messages ok and styles the button on ether click if present. Disabling on_press re-styles as disabled and stops both from working as expected.

hecrj commented 3 weeks ago

Ideally, we want to keep widgets as simple as possible and with a single purpose. I think you could achieve something similar with the MouseArea widget.

Additionally, buttons with a right click handler are not very common and, therefore, not ideal for UX.

Gremious commented 3 weeks ago

Mouse area is what I have right now, and the reason for this PR.

I cannot nicely achieve similar things with a mouse area, as I cannot easily re-create a button: I cannot style a mouse area or the container around it on hover (https://github.com/iced-rs/iced/issues/972 + mouse area doesn't have on_hover), and creating the on-click (active) styling also suddenly becomes cumbersome if I'm gonna be sending messaged and rebuilding elements just to restyle for a brief moment (compared to just having a button which already does that underneath).

(Plus, when i'm doing messges like this, the timing of that doesn't seem as smooth/nice as what buttons do? Might be a me issue.)

I didn't, then, want to copy-paste the entire button widget in my own code and only add those few lines.

So, I felt like contributing this simple case. I implore you to reconsider, but if not, I guess I have to go the annoying route of having my own button widget, or having the clutter of a bunch of mesaages bouncing back and forth with different near-identical containers switching places for a simple button. I do need right clickable buttons.


buttons with a right click handler are not very common and, therefore, not ideal for UX.

They are good UX in my case..? Sorry, I don't think this is applicable for me.