core: add read only builder option to input state

This commit is contained in:
2026-11-12 08:55:05 +07:00
parent ccd8997801
commit 9678a7676f
2 changed files with 18 additions and 0 deletions
+9
View File
@@ -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<InputState> {
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
})
}
+9
View File
@@ -867,6 +867,7 @@ struct InputDemo {
password: Entity<InputState>,
notes: Entity<InputState>,
search: Entity<InputState>,
_subscriptions: Vec<gpui::Subscription>,
}
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(&notes, |_, _, cx| cx.notify()),
cx.observe(&search, |_, _, cx| cx.notify()),
];
Self {
text,
password,
notes,
search,
_subscriptions: subscriptions,
}
}
}