Rust Cursive EditView setText function

199 views Asked by At

My EditView is:

//.addChild( 
EditView::new().fixed_width(30).with_name("customer_names") 
//)

Now when try set content:

siv.call_on_name("customer_names", |view: &mut EditView| {
    view.set_content("helloooo");
});

Does nothing. :<

However, the textviews work well!

let view = siv.find_name::<TextView>("customer_id").unwrap();
view.set_content("this is ok helloo!!");

Thanks in advance!

2

There are 2 answers

0
Barrrettt On BEST ANSWER

I found the problem. It didn't work because of the order of calling the functions. This is the creation of the editview:

EditView::new().fixed_width(30).with_name("customer_names") //no work

The search by name function was not finding the view. If I do so, if it finds the view:

EditView::new().with_name("customer_names").fixed_width(30) //this work ok!!

I have to put the with_name() first before other properties, otherwise it puts a wrapper on it and the editview doesn't work.

0
jakun On

In my case cursive did not find the TextView because it was a child of another NamedView. So I first needed to find the parent view and then the child view inside of it:

parent_view.call_on_name("child_view", |text: &mut cursive::views::TextView| {
    text.set_content(new_content);
});

This requires

use cursive::traits::Finder;

see also https://docs.rs/cursive/latest/cursive/traits/trait.Finder.html