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