core: add builder for input state creation
This commit is contained in:
@@ -867,31 +867,20 @@ struct InputDemo {
|
||||
password: Entity<InputState>,
|
||||
notes: Entity<InputState>,
|
||||
search: Entity<InputState>,
|
||||
_subscriptions: Vec<gpui::Subscription>,
|
||||
}
|
||||
|
||||
impl InputDemo {
|
||||
fn new(cx: &mut Context<Self>) -> Self {
|
||||
let text = InputState::new(cx);
|
||||
let password = InputState::new(cx);
|
||||
password.update(cx, |state, cx| state.set_password(true, cx));
|
||||
let notes = InputState::new(cx);
|
||||
notes.update(cx, |state, cx| state.set_multiline(true, cx));
|
||||
let password = InputState::builder().password().build(cx);
|
||||
let notes = InputState::builder().multiline().build(cx);
|
||||
let search = InputState::new(cx);
|
||||
// The panel is a cached view in the dock: the value readouts re-render
|
||||
// only when the inputs it reads are notified.
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -969,7 +958,7 @@ struct FieldDemo {
|
||||
impl FieldDemo {
|
||||
fn new(_window: &mut Window, cx: &mut Context<Self>) -> Self {
|
||||
let url = InputState::new(cx);
|
||||
let name = InputState::new_with_text("reya", cx);
|
||||
let name = InputState::builder().text("reya").build(cx);
|
||||
// The panel is a cached view in the dock: it re-renders only when the
|
||||
// entities it reads are notified. Both inputs are read at render time
|
||||
// (validation, error text), so every change must bust the cache.
|
||||
|
||||
Reference in New Issue
Block a user