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.61k stars 605 forks source link

Feature request: callback run on PopupWindow close #3781

Open flukejones opened 1 year ago

flukejones commented 1 year ago

Related to #3712

In some cases if the PopupWindow is closed by clicking outside of the bounds of its content, a callback that runs on this case could be handy for performing certain tasks such as closing or updating other widgets (thinking of "cancel" behaviour).

The callback would be specific to clicking outside of the popup bounds, so that closing via other means does not produce unexpected results.

tronical commented 1 year ago

Suppose we had a closed-event callback. My feeling is that if close-on-click is true, it should always be invoked - regardless of whether the user clicks inside or outside the bounds of the popup. If close-on-click is false, then I think closed-event should be invoked when close() is called.

@FloVanGH @ogoffart thoughts? :)

ogoffart commented 1 year ago

i'd called it closed (why -event?) But the behavior you describe is fine. always call the closed callback when the popup is closed

tronical commented 1 year ago

I was thinking -event because it's in response to a mouse event. But since it doesn't have to be... you're right, just closed is fine.

I can implement that if everyone else agrees. This seems straightforward (famous last words!).

ogoffart commented 1 year ago

Maybe this would allow to fix the original issue from https://github.com/slint-ui/slint/issues/456

Psy-Kai commented 2 weeks ago

Hello. I ran in the same issue. With slints 1.8 Property Changed callbacks there is no need for an additional callback. We could leverage the visible property. Buuuut: the PopupWindow show/close function does not update the visible-property.

I would expect that showing/closing the PopupWindow would change the visible property thus I can use the property changed callback.