glory_ui/input.rs
1//! Helpers for widgets that implement controlled input reconciliation.
2
3use glory_render::NodeId;
4
5use crate::{Error, Result, Scope};
6
7impl Scope {
8 /// Write a text input using the next revision of the live semantic node.
9 /// Equal values still acknowledge host edits without resetting caret/preedit.
10 /// Call after a host tick (for example in an owned Effect), so later events
11 /// from that tick retain their original revision until routing completes.
12 pub fn set_input_value(&self, node: NodeId, value: impl Into<String>) -> Result {
13 self.session()?.input_value(node, value.into())
14 }
15
16 /// Reconcile a native select after a complete host tick using its live revision.
17 pub fn set_select_selection(
18 &self,
19 node: NodeId,
20 keys: Vec<glory_render::SemanticId>,
21 ) -> Result {
22 self.session()?.select_selection(node, keys)
23 }
24
25 /// Start a new image request revision, including an explicit same-URL retry.
26 pub fn set_image_source(&self, node: NodeId, source: impl Into<String>) -> Result {
27 self.session()?.image_source(node, source.into())
28 }
29
30 /// Report a custom widget's asynchronous Binding/Effect/handler error at the
31 /// next App flush. Retired scopes ignore late errors without retaining App.
32 pub fn report_error(&self, error: impl Into<Error>) {
33 if let Ok(session) = self.session() {
34 session.report(error.into());
35 }
36 }
37}