From 9678a7676f4c70f91f04b6ab0ad68148659c2558 Mon Sep 17 00:00:00 2001 From: Ren Amamiya Date: Thu, 12 Nov 2026 08:55:05 +0700 Subject: [PATCH] core: add read only builder option to input state --- crates/core/src/input.rs | 9 +++++++++ examples/gallery/src/main.rs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/crates/core/src/input.rs b/crates/core/src/input.rs index ff3f60e..dc30797 100644 --- a/crates/core/src/input.rs +++ b/crates/core/src/input.rs @@ -535,6 +535,7 @@ pub struct InputStateBuilder { text: String, multiline: bool, password: bool, + read_only: bool, } impl InputStateBuilder { @@ -559,12 +560,19 @@ impl InputStateBuilder { self } + /// Refuses user edits, focus, movement, selection and copy stay. + pub fn read_only(mut self) -> Self { + self.read_only = true; + self + } + /// Creates the state entity. pub fn build(self, cx: &mut App) -> Entity { let InputStateBuilder { text, multiline, password, + read_only, } = self; cx.new(|cx| { @@ -574,6 +582,7 @@ impl InputStateBuilder { state.anchor = state.cursor; state.multiline = multiline; state.password = password; + state.read_only = read_only; state }) } diff --git a/examples/gallery/src/main.rs b/examples/gallery/src/main.rs index b03859c..6d6028b 100644 --- a/examples/gallery/src/main.rs +++ b/examples/gallery/src/main.rs @@ -867,6 +867,7 @@ struct InputDemo { password: Entity, notes: Entity, search: Entity, + _subscriptions: Vec, } impl InputDemo { @@ -876,11 +877,19 @@ impl InputDemo { let notes = InputState::builder().multiline().build(cx); let search = InputState::new(cx); + let subscriptions = vec![ + cx.observe(&text, |_, _, cx| cx.notify()), + cx.observe(&password, |_, _, cx| cx.notify()), + cx.observe(¬es, |_, _, cx| cx.notify()), + cx.observe(&search, |_, _, cx| cx.notify()), + ]; + Self { text, password, notes, search, + _subscriptions: subscriptions, } } }