How do I set the focus to a text_input?

I have an app where I have created a bunch of buttons. When each button is pressed it is replaced by a text_input. I am doing this because I have not been able to figure out which text_input a change message pertains to. By only having 1 text_input I know where to put the changed text. My problem is that the text_input does not get focus unless I click in it. I would like to create it with the initial focus. text_input has a focus function but I don’t see how to run the resulting task.

You use the iced::widget::text_input::focus function to create a task (I assume you’re using iced’s master branch, but if you are on 0.12 it would be called command instead of task), passing the widget’s id, and then return that task from your app’s update function.

You can also know which text input triggered a change by adding more context to the message you are dispatching when it does. For example, your message could include the widget’s id or some other form of identification.

You can see examples of how I achieve both things in my own project: