1use iced_native::widget::text_input::State;
2use iced_native::{Column, Container, Element, Length, Text, TextInput};
3use iced_pancurses::{PancursesRenderer, Sandbox};
4
5#[derive(Debug, Clone)]
6pub enum MyMessage {
7 OnTextInput(String),
8}
9
10struct MyState {
11 text_input_state: State,
12 curr_value: String,
13}
14
15impl Sandbox for MyState {
16 type Message = MyMessage;
17
18 fn new() -> Self {
19 MyState {
20 text_input_state: State::new(),
21 curr_value: "".into(),
22 }
23 }
24
25 fn view(&mut self) -> Element<'_, MyMessage, PancursesRenderer> {
26 Container::new(
27 Column::new()
28 .spacing(1)
29 .push(Text::new("Hello TextInput!").width(Length::Shrink))
30 .push(
31 TextInput::new(
32 &mut self.text_input_state,
33 "Type something",
34 &self.curr_value,
35 MyMessage::OnTextInput,
36 )
37 .width(Length::Units(20)),
38 )
39 .width(Length::Shrink),
40 )
41 .width(Length::Fill)
42 .height(Length::Fill)
43 .center_x()
44 .center_y()
45 .into()
46 }
47
48 fn update(&mut self, messages: Vec<MyMessage>) {
49 messages.into_iter().for_each(|m| match m {
50 MyMessage::OnTextInput(new) => self.curr_value = new,
51 })
52 }
53}
54
55fn main() {
56 MyState::run()
57}