Skip to content

How to enable EditView and give it focus and user input without mouse click #820

Answered by gyscos
rcook asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, and thanks for the question!

The main issue here is the concept of focus: the EditView itself cannot control if it's in focus. Instead, its parents (in this case, the LinearLayout) decide which view is active.

You will need to give a name to that LinearLayout, and use something like focus_view() with a name selector, or set_focus_index if you know it'll be the child at index 1.

Note that you can call call_on_name on any view (with the Finder trait), so in the callback, you can call it on the linear layout to get the editview (since c will be borrowed):

        use cursive::traits::Finder;

        c.call_on_name("LINEAR", |linear: &mut LinearLayout| {
            linear.call_on_name("…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rcook
Comment options

Answer selected by rcook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants