Iced: Can't get TextInput to work properly.

Created on 25 Aug 2020  路  3Comments  路  Source: hecrj/iced

Hi again,
I am sure I am just doing something wrong, but this is not working for me:
(Running rev fb015a85d22a7c4632bd251127a89259bfd0c346)

    fn view(&mut self) -> Element<Self::Message> {
        let text_input = TextInput::new(
            &mut self.input_state,
            "Type something...",
            &self.value,
            Message::InputChanged,
        )
        .padding(10)
        .size(30)
        .on_submit(Message::SubmitPath);

        let content = Column::new().push(text_input);

        Container::new(content)
            .width(Length::Fill)
            .height(Length::Fill)
            .into()
    }

This is my enum Message and my struct

pub enum Message {
    // [... more]
    InputChanged(String),
    SubmitPath,
}

pub struct Ajour {
    // [... more]
    input_state: text_input::State,
    value: String,
}

Heres the error:

the trait bound gui::Message: std::convert::From<iced_native::widget::text_input::TextInput<'_, gui::Message, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>> is not satisfied
required because of the requirements on the impl of std::convert::From<iced_native::widget::text_input::TextInput<'_, gui::Message, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>> for iced_native::element::Element<'_, gui::Message, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>
required because of the requirements on the impl of std::convert::Into<iced_native::element::Element<'_, gui::Message, iced_graphics::renderer::Renderer<iced_wgpu::backend::Backend>>> for `iced_native::widget::text_input::TextInput<'_, gui::Message, iced_graphics::renderer::Renderer>

Again, i am properly doing something wrong but if anyone can take a look at help me out, it would be great. Thanks a lot.

All 3 comments

Hello. 馃檪

The push function of Column accepts an Into<Element<...>>. For me, TextInput can be turned into an Element, but it seems that the typechecker is a little bit confused here. 馃

The workaround I use in this case is to turn the TextInput into an Element by myself:

let text_input: Element<_> = TextInput::new(
        // ...
    )
    // ...
    .into();

Update: It seems that this was a known bug and is now fixed on the Master branch. 馃檪

Thanks a lot for the response.

I think this is normally caused by the message type not meeting some requirements, like implementing Clone.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

michael-hart picture michael-hart  路  4Comments

rowungiles picture rowungiles  路  4Comments

Charles-Schleich picture Charles-Schleich  路  3Comments

CallistoM picture CallistoM  路  3Comments

cetra3 picture cetra3  路  3Comments