mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-10 03:10:41 +00:00
Rename find_id -> call_on_id, find_id_mut -> find_id
This commit is contained in:
parent
200435fefe
commit
146ebd8931
@ -19,7 +19,7 @@ fn main() {
|
||||
.fixed_width(20))
|
||||
.button("Ok", |s| {
|
||||
let name =
|
||||
s.find_id("name", |view: &mut EditView| view.get_content())
|
||||
s.call_on_id("name", |view: &mut EditView| view.get_content())
|
||||
.unwrap();
|
||||
show_popup(s, &name);
|
||||
}));
|
||||
|
@ -28,7 +28,7 @@ fn main() {
|
||||
Checkbox::new()
|
||||
.on_change(|s, checked| for name in &["email1",
|
||||
"email2"] {
|
||||
s.find_id(name, |view: &mut EditView| {
|
||||
s.call_on_id(name, |view: &mut EditView| {
|
||||
view.set_enabled(checked)
|
||||
});
|
||||
}))
|
||||
|
@ -13,7 +13,7 @@ fn show_popup(siv: &mut Cursive) {
|
||||
Dialog::around(TextView::new("Tak!"))
|
||||
.button("Change", |s| {
|
||||
// Look for a view tagged "text". We _know_ it's there, so unwrap it.
|
||||
s.find_id("text", |view: &mut TextView| {
|
||||
s.call_on_id("text", |view: &mut TextView| {
|
||||
let content: String = view.get_content().chars().rev().collect();
|
||||
view.set_content(content);
|
||||
});
|
||||
|
@ -26,12 +26,12 @@ fn main() {
|
||||
// and directly retrieve the content from the `Cursive` root.
|
||||
fn on_edit(siv: &mut Cursive, _content: &str, _cursor: usize) {
|
||||
// Get handles for each view.
|
||||
let edit_1 = siv.find_id_mut::<EditView>("1").unwrap();
|
||||
let edit_2 = siv.find_id_mut::<EditView>("2").unwrap();
|
||||
let edit_1 = siv.find_id::<EditView>("1").unwrap();
|
||||
let edit_2 = siv.find_id::<EditView>("2").unwrap();
|
||||
|
||||
// Directly compare references to edit_1 and edit_2.
|
||||
let matches = edit_1.get_content() == edit_2.get_content();
|
||||
siv.find_id("match", |v: &mut TextView| v.set_content(if matches {
|
||||
siv.call_on_id("match", |v: &mut TextView| v.set_content(if matches {
|
||||
"match"
|
||||
} else {
|
||||
"no match"
|
||||
|
@ -14,7 +14,7 @@ fn main() {
|
||||
.value(7)
|
||||
.on_change(|s, v| {
|
||||
let title = format!("[ {} ]", v);
|
||||
s.find_id("dialog", |view: &mut Dialog| view.set_title(title));
|
||||
s.call_on_id("dialog", |view: &mut Dialog| view.set_title(title));
|
||||
})
|
||||
.on_enter(|s, v| {
|
||||
s.pop_layer();
|
||||
|
@ -417,13 +417,13 @@ impl Cursive {
|
||||
/// .with_id("text"));
|
||||
///
|
||||
/// siv.add_global_callback('p', |s| {
|
||||
/// s.find_id("text", |view: &mut views::TextView| {
|
||||
/// s.call_on_id("text", |view: &mut views::TextView| {
|
||||
/// view.set_content("Text #2");
|
||||
/// });
|
||||
/// });
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn find_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R>
|
||||
pub fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R>
|
||||
where V: View + Any,
|
||||
F: FnOnce(&mut V) -> R
|
||||
{
|
||||
@ -436,10 +436,10 @@ impl Cursive {
|
||||
/// a mutable reference to the wrapped view.
|
||||
///
|
||||
/// [`RefCellView`]: views/struct.RefCellView.html
|
||||
pub fn find_id_mut<V>(&mut self, id: &str) -> Option<views::ViewRef<V>>
|
||||
pub fn find_id<V>(&mut self, id: &str) -> Option<views::ViewRef<V>>
|
||||
where V: View + Any
|
||||
{
|
||||
self.find_id(id, views::RefCellView::<V>::get_mut)
|
||||
self.call_on_id(id, views::RefCellView::<V>::get_mut)
|
||||
}
|
||||
|
||||
/// Moves the focus to the view identified by `id`.
|
||||
|
@ -41,7 +41,7 @@ use view::View;
|
||||
/// .with_id("name")
|
||||
/// .fixed_width(20))
|
||||
/// .button("Ok", |s| {
|
||||
/// let name = s.find_id("name", |view: &mut EditView| view.get_content())
|
||||
/// let name = s.call_on_id("name", |view: &mut EditView| view.get_content())
|
||||
/// .unwrap();
|
||||
/// show_popup(s, &name);
|
||||
/// }));
|
||||
|
Loading…
Reference in New Issue
Block a user