pub fn on_ui<G>(g: G) -> OnUi<G>Expand description
Wrap a synchronous closure to run on the UI main thread. Use it for pure-UI
actions. The closure may take the params (|p|), the host context &mut Cx
to reach real widgets (e.g. gpui’s &mut App), both (|p, cx|), or neither
(||); the |cx| and || forms are for parameterless actions.
§Examples
use purview::{ActionError, GuiBridge, on_ui};
let (_bridge, app) = GuiBridge::headless().build();
let win = app.open("Panel");
// A pure-UI action, run entirely on the main thread.
win.actions()
.add("refresh", "Refresh")
.on(on_ui(|_p| Ok::<_, ActionError>("refreshed")));
// `close` is an ordinary action you define yourself:
let closer = win.clone();
win.actions().add("close", "Close").on(on_ui(move |_p| {
closer.close(); // projection bookkeeping
Ok::<_, ActionError>("closed")
}));