linebender / xilem

An experimental Rust native UI framework
Apache License 2.0
3.65k stars 115 forks source link

Add `Widget::Action` associated type #664

Open PoignardAzur opened 3 weeks ago

PoignardAzur commented 3 weeks ago

During various passes, widgets that want to signal a semantically meaningful event from the UI (eg a button that was clicked) can emit actions.

Actions are a centralized queue of messages intended for the root application, mostly for the app driver (eg Xilem) to handle. They are inspired by Facebook's Flux architecture.

Actions are currently under-designed. Right now, they only store the emitter's id, plus a payload among a small set of types with Box<dyn Any> as a wildcard. Ideally, we'd want a way to connect the type of an action from the widget that sent it, so that each widget would have an associated action type. This associated type would only exist for sized Widgets so that the trait remains dyn-safe.

DJMcNab commented 2 weeks ago

To clarify, this would mean that the action type is always downcasted? That seems reasonable to me.

I think Xilem would be able to make use of this for a slight ease-of-use improvement.

PoignardAzur commented 2 weeks ago

To clarify, this would mean that the action type is always downcasted?

Basically yes.