core: add read only builder option to input state
This commit is contained in:
@@ -535,6 +535,7 @@ pub struct InputStateBuilder {
|
|||||||
text: String,
|
text: String,
|
||||||
multiline: bool,
|
multiline: bool,
|
||||||
password: bool,
|
password: bool,
|
||||||
|
read_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputStateBuilder {
|
impl InputStateBuilder {
|
||||||
@@ -559,12 +560,19 @@ impl InputStateBuilder {
|
|||||||
self
|
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.
|
/// Creates the state entity.
|
||||||
pub fn build(self, cx: &mut App) -> Entity<InputState> {
|
pub fn build(self, cx: &mut App) -> Entity<InputState> {
|
||||||
let InputStateBuilder {
|
let InputStateBuilder {
|
||||||
text,
|
text,
|
||||||
multiline,
|
multiline,
|
||||||
password,
|
password,
|
||||||
|
read_only,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
cx.new(|cx| {
|
cx.new(|cx| {
|
||||||
@@ -574,6 +582,7 @@ impl InputStateBuilder {
|
|||||||
state.anchor = state.cursor;
|
state.anchor = state.cursor;
|
||||||
state.multiline = multiline;
|
state.multiline = multiline;
|
||||||
state.password = password;
|
state.password = password;
|
||||||
|
state.read_only = read_only;
|
||||||
state
|
state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -867,6 +867,7 @@ struct InputDemo {
|
|||||||
password: Entity<InputState>,
|
password: Entity<InputState>,
|
||||||
notes: Entity<InputState>,
|
notes: Entity<InputState>,
|
||||||
search: Entity<InputState>,
|
search: Entity<InputState>,
|
||||||
|
_subscriptions: Vec<gpui::Subscription>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InputDemo {
|
impl InputDemo {
|
||||||
@@ -876,11 +877,19 @@ impl InputDemo {
|
|||||||
let notes = InputState::builder().multiline().build(cx);
|
let notes = InputState::builder().multiline().build(cx);
|
||||||
let search = InputState::new(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 {
|
Self {
|
||||||
text,
|
text,
|
||||||
password,
|
password,
|
||||||
notes,
|
notes,
|
||||||
search,
|
search,
|
||||||
|
_subscriptions: subscriptions,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user