mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 17:35:00 +00:00
Rename id
to name
: phase 2
This commit is contained in:
parent
ddac91373c
commit
6824cc4299
28
CHANGELOG.md
28
CHANGELOG.md
@ -7,21 +7,38 @@
|
||||
- `cursive::event::AnyCb` changed from `Box<...>` to `&mut ...`, so users of
|
||||
`View::call_on_any` no longer need to box their closures.
|
||||
- Remove `BoxView::squishable`.
|
||||
- Update crossterm to 0.12.
|
||||
- Update crossterm to 0.14.
|
||||
- Renamed multiple types (old names are still re-exported, but deprecated):
|
||||
- `BoxView` -> `ResizedView`
|
||||
- `ViewBox` -> `BoxedView`
|
||||
- `SizedView` -> `LastSizeView`
|
||||
- `Identifiable` -> `Nameable`
|
||||
- `Boxable` -> `Resizable`
|
||||
- `IdView` -> `NamedView`
|
||||
- `Selector::Id` -> `Selector::Name`
|
||||
- `with_id` -> `with_name`
|
||||
- `call_on_id` -> `call_on_name`
|
||||
- `find_id` -> `find_name`
|
||||
- `focus_id` -> `focus_name`
|
||||
|
||||
### API updates
|
||||
|
||||
- `SelectView::{item, with_all}` now accept `S: Into<StyledString>` for colored labels.
|
||||
- Add `ScrollView::scroll_to_important_area`.
|
||||
- Add `LinearLayout::set_focus_index`.
|
||||
- Add `XY::{sum, product}`
|
||||
- `view::scroll` is now a public module
|
||||
- Add `Cursive::process_events` and `Cursive::post_events`
|
||||
- This gives users finer control than `Cursive::step`
|
||||
- Add `XY::{sum, product}`.
|
||||
- `view::scroll` is now a public module.
|
||||
- Add `Cursive::process_events` and `Cursive::post_events`.
|
||||
- This gives users finer control than `Cursive::step`.
|
||||
- `Layer` now has a `color` option.
|
||||
- `LinearLayout` can now directly add boxed views without re-boxing.
|
||||
- Add inner getters to `EnableableView`.
|
||||
- Add `PaddedView::get_inner(_mut)`.
|
||||
|
||||
### Improvements
|
||||
|
||||
- Changed the default color for `TitleSecondary` from yellow to light blue.
|
||||
- Changed the default color for `Tertiary` from grey to white.
|
||||
- Reduced dependencies (`toml` is now optional, removed `hashbrown`).
|
||||
- `Cursive::default()` now fallbacks do dummy backend if no other is available.
|
||||
|
||||
@ -30,6 +47,7 @@
|
||||
- Fixed `ScrollView::show_scrollbars()`
|
||||
- Fixed layout for `BoxView` with some size constraints.
|
||||
- On Windows, do not print unix-specific character during initialization.
|
||||
- Fix out-of-bounds access for some mouse events in `MenuPopup`
|
||||
|
||||
## 0.13.0
|
||||
|
||||
|
@ -19,7 +19,7 @@ fn main() {
|
||||
|
||||
let select = SelectView::<String>::new()
|
||||
.on_submit(on_submit)
|
||||
.with_id("select")
|
||||
.with_name("select")
|
||||
.fixed_size((10, 5));
|
||||
let buttons = LinearLayout::vertical()
|
||||
.child(Button::new("Add new", add_name))
|
||||
@ -38,7 +38,7 @@ fn main() {
|
||||
|
||||
fn add_name(s: &mut Cursive) {
|
||||
fn ok(s: &mut Cursive, name: &str) {
|
||||
s.call_on_id("select", |view: &mut SelectView<String>| {
|
||||
s.call_on_name("select", |view: &mut SelectView<String>| {
|
||||
view.add_item_str(name)
|
||||
});
|
||||
s.pop_layer();
|
||||
@ -46,12 +46,12 @@ fn add_name(s: &mut Cursive) {
|
||||
|
||||
s.add_layer(Dialog::around(EditView::new()
|
||||
.on_submit(ok)
|
||||
.with_id("name")
|
||||
.with_name("name")
|
||||
.fixed_width(10))
|
||||
.title("Enter a new name")
|
||||
.button("Ok", |s| {
|
||||
let name =
|
||||
s.call_on_id("name", |view: &mut EditView| {
|
||||
s.call_on_name("name", |view: &mut EditView| {
|
||||
view.get_content()
|
||||
}).unwrap();
|
||||
ok(s, &name);
|
||||
@ -62,7 +62,7 @@ fn add_name(s: &mut Cursive) {
|
||||
}
|
||||
|
||||
fn delete_name(s: &mut Cursive) {
|
||||
let mut select = s.find_id::<SelectView<String>>("select").unwrap();
|
||||
let mut select = s.find_name::<SelectView<String>>("select").unwrap();
|
||||
match select.selected_id() {
|
||||
None => s.add_layer(Dialog::info("No name to remove")),
|
||||
Some(focus) => {
|
||||
@ -193,7 +193,7 @@ this list with names!
|
||||
[`LinearLayout`]: https://docs.rs/cursive/0/cursive/views/struct.LinearLayout.html
|
||||
[`DummyView`]: https://docs.rs/cursive/0/cursive/views/struct.DummyView.html
|
||||
|
||||
## IDs
|
||||
## Identifying views
|
||||
|
||||
When the user presses the `<Add new>` button, we want to show a popup where he
|
||||
can enter a new name:
|
||||
@ -224,12 +224,12 @@ The closure has access to the `&mut Cursive`, which in turn has access to all
|
||||
the views, so _in theory_, we could ask it to borrow the view, if only we knew
|
||||
how to point to the correct view.
|
||||
|
||||
[`IdView`] is meant exactly for this: it wraps a view and gives it an ID.
|
||||
Later, you can ask the Cursive root for this ID and get access to the view.
|
||||
[`IdView`] is meant exactly for this: it wraps a view and gives it a name.
|
||||
Later, you can ask the Cursive root for this name and get access to the view.
|
||||
Just what we need!
|
||||
|
||||
Like `ResizedView`, `IdView` can be used directly with [`IdView::new`], or through
|
||||
the [`Identifiable`] trait. [`Cursive::call_on_id`] allows you to run a closure
|
||||
the [`Identifiable`] trait. [`Cursive::call_on_name`] allows you to run a closure
|
||||
on the view.
|
||||
|
||||
Here's what it looks like in action:
|
||||
@ -237,11 +237,11 @@ Here's what it looks like in action:
|
||||
```rust,ignore
|
||||
fn add_name(s: &mut Cursive) {
|
||||
s.add_layer(Dialog::around(EditView::new()
|
||||
.with_id("name")
|
||||
.with_name("name")
|
||||
.fixed_width(10))
|
||||
.title("Enter a new name")
|
||||
.button("Ok", |s| {
|
||||
let name = s.call_on_id("name", |view: &mut EditView| {
|
||||
let name = s.call_on_name("name", |view: &mut EditView| {
|
||||
view.get_content()
|
||||
}).unwrap();
|
||||
})
|
||||
@ -252,15 +252,15 @@ fn add_name(s: &mut Cursive) {
|
||||
```
|
||||
|
||||
We create the `EditView` with the id `"name"`, and we use `"name"` again when
|
||||
calling `call_on_id`.
|
||||
calling `call_on_name`.
|
||||
|
||||
Now we just need to do something with this name: add it to the list!
|
||||
Remember the `SelectView` we created? Let's give it an ID too:
|
||||
Remember the `SelectView` we created? Let's give it a name too:
|
||||
|
||||
```rust,ignore
|
||||
let select = SelectView::<String>::new()
|
||||
.on_submit(on_submit)
|
||||
.with_id("select")
|
||||
.with_name("select")
|
||||
.fixed_size((10, 5));
|
||||
```
|
||||
(Here again, the order is important: we want to wrap the `SelectView`, not
|
||||
@ -271,7 +271,7 @@ That way, we can update it with a new item:
|
||||
```rust,ignore
|
||||
fn add_name(s: &mut Cursive) {
|
||||
fn ok(s: &mut Cursive, name: &str) {
|
||||
s.call_on_id("select", |view: &mut SelectView<String>| {
|
||||
s.call_on_name("select", |view: &mut SelectView<String>| {
|
||||
view.add_item_str(name);
|
||||
});
|
||||
s.pop_layer();
|
||||
@ -279,11 +279,11 @@ fn add_name(s: &mut Cursive) {
|
||||
|
||||
s.add_layer(Dialog::around(EditView::new()
|
||||
.on_submit(ok)
|
||||
.with_id("name")
|
||||
.with_name("name")
|
||||
.fixed_width(10))
|
||||
.title("Enter a new name")
|
||||
.button("Ok", |s| {
|
||||
let name = s.call_on_id("name", |v: &mut EditView| {
|
||||
let name = s.call_on_name("name", |v: &mut EditView| {
|
||||
v.get_content()
|
||||
}).unwrap();
|
||||
ok(s, &name);
|
||||
@ -299,7 +299,7 @@ complicated:
|
||||
|
||||
```rust,ignore
|
||||
fn delete_name(s: &mut Cursive) {
|
||||
let mut select = s.find_id::<SelectView<String>>("select").unwrap();
|
||||
let mut select = s.find_name::<SelectView<String>>("select").unwrap();
|
||||
match select.selected_id() {
|
||||
None => s.add_layer(Dialog::info("No name to remove")),
|
||||
Some(focus) => {
|
||||
@ -312,7 +312,7 @@ fn delete_name(s: &mut Cursive) {
|
||||
We use [`SelectView::selected_id`] and [`SelectView::remove_item`] to remove
|
||||
the item currently selected, nothing too surprising.
|
||||
|
||||
But this time, instead of using `call_on_id`, we use [`Cursive::find_id`]:
|
||||
But this time, instead of using `call_on_name`, we use [`Cursive::find_name`]:
|
||||
this method returns a handle, through which we can mutate the view.
|
||||
It uses `Rc` and `RefCell` under the hood to provide mutable access to the
|
||||
view without borrowing the `Cursive` root, leaving us free to pop layers.
|
||||
@ -321,8 +321,8 @@ view without borrowing the `Cursive` root, leaving us free to pop layers.
|
||||
[`IdView`]: https://docs.rs/cursive/0/cursive/views/struct.IdView.html
|
||||
[`IdView::new`]: https://docs.rs/cursive/0/cursive/prelude/struct.IdView.html#method.around
|
||||
[`Identifiable`]: https://docs.rs/cursive/0/cursive/view/trait.Identifiable.html
|
||||
[`Cursive::find_id`]: https://docs.rs/cursive/0/cursive/struct.Cursive.html#method.find_id
|
||||
[`Cursive::call_on_id`]: https://docs.rs/cursive/0/cursive/struct.Cursive.html#method.call_on_id
|
||||
[`Cursive::find_name`]: https://docs.rs/cursive/0/cursive/struct.Cursive.html#method.find_name
|
||||
[`Cursive::call_on_name`]: https://docs.rs/cursive/0/cursive/struct.Cursive.html#method.call_on_name
|
||||
[`SelectView::selected_id`]: https://docs.rs/cursive/0/cursive/views/struct.SelectView.html#method.selected_id
|
||||
[`SelectView::remove_item`]: https://docs.rs/cursive/0/cursive/views/struct.SelectView.html#method.remove_item
|
||||
|
||||
@ -334,5 +334,5 @@ don't hesitate to read the documentation.
|
||||
You've now seen:
|
||||
* How to wrap views to control their size
|
||||
* How to assemble views together in a linear layout
|
||||
* How to give an ID to views and use them later
|
||||
* How to give names to views and use them later
|
||||
* How to use `SelectView`, `EditView`, `Button`s...
|
||||
|
@ -18,9 +18,9 @@ fn main() {
|
||||
// Call `show_popup` when the user presses `Enter`
|
||||
.on_submit(show_popup)
|
||||
// Give the `EditView` a name so we can refer to it later.
|
||||
.with_id("name")
|
||||
.with_name("name")
|
||||
// Wrap this in a `ResizedView` with a fixed width.
|
||||
// Do this _after_ `with_id` or the name will point to the
|
||||
// Do this _after_ `with_name` or the name will point to the
|
||||
// `ResizedView` instead of `EditView`!
|
||||
.fixed_width(20),
|
||||
)
|
||||
@ -28,7 +28,7 @@ fn main() {
|
||||
// This will run the given closure, *ONLY* if a view with the
|
||||
// correct type and the given ID is found.
|
||||
let name = s
|
||||
.call_on_id("name", |view: &mut EditView| {
|
||||
.call_on_name("name", |view: &mut EditView| {
|
||||
// We can return content from the closure!
|
||||
view.get_content()
|
||||
})
|
||||
|
@ -24,11 +24,11 @@ fn main() {
|
||||
Checkbox::new().on_change(|s, checked| {
|
||||
// Enable/Disable the next field depending on this checkbox
|
||||
for name in &["email1", "email2"] {
|
||||
s.call_on_id(name, |view: &mut EditView| {
|
||||
s.call_on_name(name, |view: &mut EditView| {
|
||||
view.set_enabled(checked)
|
||||
});
|
||||
if checked {
|
||||
s.focus_id("email1").unwrap();
|
||||
s.focus_name("email1").unwrap();
|
||||
}
|
||||
}
|
||||
}),
|
||||
@ -41,14 +41,14 @@ fn main() {
|
||||
.child(
|
||||
EditView::new()
|
||||
.disabled()
|
||||
.with_id("email1")
|
||||
.with_name("email1")
|
||||
.fixed_width(15),
|
||||
)
|
||||
.child(TextView::new("@"))
|
||||
.child(
|
||||
EditView::new()
|
||||
.disabled()
|
||||
.with_id("email2")
|
||||
.with_name("email2")
|
||||
.fixed_width(10),
|
||||
),
|
||||
)
|
||||
|
@ -17,7 +17,7 @@ fn main() {
|
||||
// We add the P callback on the textview only (and not globally),
|
||||
// so that we can't call it when the popup is already visible.
|
||||
siv.add_layer(
|
||||
OnEventView::new(TextView::new(content).with_id("text"))
|
||||
OnEventView::new(TextView::new(content).with_name("text"))
|
||||
.on_event('p', |s| show_popup(s)),
|
||||
);
|
||||
|
||||
@ -33,7 +33,7 @@ fn show_popup(siv: &mut Cursive) {
|
||||
.button("Change", |s| {
|
||||
// Look for a view tagged "text".
|
||||
// We _know_ it's there, so unwrap it.
|
||||
s.call_on_id("text", |view: &mut TextView| {
|
||||
s.call_on_name("text", |view: &mut TextView| {
|
||||
let content = reverse(view.get_content().source());
|
||||
view.set_content(content);
|
||||
});
|
||||
|
@ -12,9 +12,9 @@ fn main() {
|
||||
siv.add_layer(
|
||||
Dialog::around(
|
||||
LinearLayout::vertical()
|
||||
.child(EditView::new().on_edit(on_edit).with_id("1"))
|
||||
.child(EditView::new().on_edit(on_edit).with_id("2"))
|
||||
.child(TextView::new("match").with_id("match"))
|
||||
.child(EditView::new().on_edit(on_edit).with_name("1"))
|
||||
.child(EditView::new().on_edit(on_edit).with_name("2"))
|
||||
.child(TextView::new("match").with_name("match"))
|
||||
.fixed_width(10),
|
||||
)
|
||||
.button("Quit", Cursive::quit),
|
||||
@ -30,13 +30,13 @@ 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::<EditView>("1").unwrap();
|
||||
let edit_2 = siv.find_id::<EditView>("2").unwrap();
|
||||
let edit_1 = siv.find_name::<EditView>("1").unwrap();
|
||||
let edit_2 = siv.find_name::<EditView>("2").unwrap();
|
||||
|
||||
// Directly compare references to edit_1 and edit_2.
|
||||
let matches = edit_1.get_content() == edit_2.get_content();
|
||||
|
||||
siv.call_on_id("match", |v: &mut TextView| {
|
||||
siv.call_on_name("match", |v: &mut TextView| {
|
||||
v.set_content(if matches { "match" } else { "no match" })
|
||||
});
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ fn main() {
|
||||
.value(7)
|
||||
.on_change(|s, v| {
|
||||
let title = format!("[ {} ]", v);
|
||||
s.call_on_id("dialog", |view: &mut Dialog| {
|
||||
s.call_on_name("dialog", |view: &mut Dialog| {
|
||||
view.set_title(title)
|
||||
});
|
||||
})
|
||||
@ -31,7 +31,7 @@ fn main() {
|
||||
}),
|
||||
)
|
||||
.title("[ 7 ]")
|
||||
.with_id("dialog"),
|
||||
.with_name("dialog"),
|
||||
);
|
||||
|
||||
siv.run();
|
||||
|
@ -154,13 +154,13 @@ fn build_selector(model: Model) -> impl cursive::view::View {
|
||||
.child(
|
||||
views::EditView::new()
|
||||
.content(format!("{}", offset))
|
||||
.with_id("edit")
|
||||
.with_name("edit")
|
||||
.min_width(5),
|
||||
)
|
||||
.child(views::DummyView.fixed_width(1))
|
||||
.child(views::Button::new("Update", move |s| {
|
||||
if let Some(n) = s
|
||||
.call_on_id("edit", |edit: &mut views::EditView| {
|
||||
.call_on_name("edit", |edit: &mut views::EditView| {
|
||||
edit.get_content()
|
||||
})
|
||||
.and_then(|content| content.parse().ok())
|
||||
|
@ -12,7 +12,7 @@ fn main() {
|
||||
Dialog::new()
|
||||
.title("Describe your issue")
|
||||
.padding((1, 1, 1, 0))
|
||||
.content(TextArea::new().with_id("text"))
|
||||
.content(TextArea::new().with_name("text"))
|
||||
.button("Ok", Cursive::quit),
|
||||
);
|
||||
|
||||
@ -29,12 +29,12 @@ fn main() {
|
||||
.content(
|
||||
EditView::new()
|
||||
.on_submit(find)
|
||||
.with_id("edit")
|
||||
.with_name("edit")
|
||||
.min_width(10),
|
||||
)
|
||||
.button("Ok", |s| {
|
||||
let text = s
|
||||
.call_on_id("edit", |view: &mut EditView| {
|
||||
.call_on_name("edit", |view: &mut EditView| {
|
||||
view.get_content()
|
||||
})
|
||||
.unwrap();
|
||||
@ -55,7 +55,7 @@ fn find(siv: &mut Cursive, text: &str) {
|
||||
// First, remove the find popup
|
||||
siv.pop_layer();
|
||||
|
||||
let res = siv.call_on_id("text", |v: &mut TextArea| {
|
||||
let res = siv.call_on_name("text", |v: &mut TextArea| {
|
||||
// Find the given text from the text area content
|
||||
// Possible improvement: search after the current cursor.
|
||||
if let Some(i) = v.get_content().find(text) {
|
||||
|
@ -306,7 +306,8 @@ impl Cursive {
|
||||
/// siv.add_global_callback('~', Cursive::toggle_debug_console);
|
||||
/// ```
|
||||
pub fn toggle_debug_console(&mut self) {
|
||||
if let Some(pos) = self.screen_mut().find_layer_from_id(DEBUG_VIEW_ID)
|
||||
if let Some(pos) =
|
||||
self.screen_mut().find_layer_from_name(DEBUG_VIEW_ID)
|
||||
{
|
||||
self.screen_mut().remove_layer(pos);
|
||||
} else {
|
||||
@ -524,7 +525,7 @@ impl Cursive {
|
||||
/// # use cursive::traits::*;
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// siv.add_layer(views::TextView::new("Text #1").with_id("text"));
|
||||
/// siv.add_layer(views::TextView::new("Text #1").with_name("text"));
|
||||
///
|
||||
/// siv.add_global_callback('p', |s| {
|
||||
/// s.call_on(
|
||||
@ -559,20 +560,34 @@ impl Cursive {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// siv.add_layer(views::TextView::new("Text #1")
|
||||
/// .with_id("text"));
|
||||
/// .with_name("text"));
|
||||
///
|
||||
/// siv.add_global_callback('p', |s| {
|
||||
/// s.call_on_id("text", |view: &mut views::TextView| {
|
||||
/// s.call_on_name("text", |view: &mut views::TextView| {
|
||||
/// view.set_content("Text #2");
|
||||
/// });
|
||||
/// });
|
||||
/// ```
|
||||
pub fn call_on_name<V, F, R>(
|
||||
&mut self,
|
||||
name: &str,
|
||||
callback: F,
|
||||
) -> Option<R>
|
||||
where
|
||||
V: View + Any,
|
||||
F: FnOnce(&mut V) -> R,
|
||||
{
|
||||
self.call_on(&view::Selector::Name(name), callback)
|
||||
}
|
||||
|
||||
/// Same as [`call_on_name`](Cursive::call_on_name).
|
||||
#[deprecated(note = "`call_on_id` is being renamed to `call_on_name`")]
|
||||
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,
|
||||
{
|
||||
self.call_on(&view::Selector::Name(id), callback)
|
||||
self.call_on_name(id, callback)
|
||||
}
|
||||
|
||||
/// Convenient method to find a view wrapped in [`NamedView`].
|
||||
@ -589,10 +604,10 @@ impl Cursive {
|
||||
/// # let mut siv = Cursive::dummy();
|
||||
/// use cursive::traits::Identifiable;
|
||||
///
|
||||
/// siv.add_layer(TextView::new("foo").with_id("id"));
|
||||
/// siv.add_layer(TextView::new("foo").with_name("id"));
|
||||
///
|
||||
/// // Could be called in a callback
|
||||
/// let mut view: ViewRef<TextView> = siv.find_id("id").unwrap();
|
||||
/// let mut view: ViewRef<TextView> = siv.find_name("id").unwrap();
|
||||
/// view.set_content("bar");
|
||||
/// ```
|
||||
///
|
||||
@ -606,30 +621,45 @@ impl Cursive {
|
||||
/// use cursive::traits::Identifiable;
|
||||
///
|
||||
/// let select = SelectView::new().item("zero", 0u32).item("one", 1u32);
|
||||
/// siv.add_layer(select.with_id("select"));
|
||||
/// siv.add_layer(select.with_name("select"));
|
||||
///
|
||||
/// // Specifying a wrong type will not return anything.
|
||||
/// assert!(siv.find_id::<SelectView<String>>("select").is_none());
|
||||
/// assert!(siv.find_name::<SelectView<String>>("select").is_none());
|
||||
///
|
||||
/// // Omitting the type will use the default type, in this case `String`.
|
||||
/// assert!(siv.find_id::<SelectView>("select").is_none());
|
||||
/// assert!(siv.find_name::<SelectView>("select").is_none());
|
||||
///
|
||||
/// // But with the correct type, it works fine.
|
||||
/// assert!(siv.find_id::<SelectView<u32>>("select").is_some());
|
||||
/// assert!(siv.find_name::<SelectView<u32>>("select").is_some());
|
||||
/// ```
|
||||
///
|
||||
/// [`NamedView`]: views/struct.NamedView.html
|
||||
/// [`ViewRef`]: views/type.ViewRef.html
|
||||
/// [`NamedView`]: views::NamedView
|
||||
/// [`ViewRef`]: views::ViewRef
|
||||
pub fn find_name<V>(&mut self, id: &str) -> Option<views::ViewRef<V>>
|
||||
where
|
||||
V: View + Any,
|
||||
{
|
||||
self.call_on_name(id, views::NamedView::<V>::get_mut)
|
||||
}
|
||||
|
||||
/// Same as [`find_name`](Cursive::find_name).
|
||||
#[deprecated(note = "`find_id` is being renamed to `find_name`")]
|
||||
pub fn find_id<V>(&mut self, id: &str) -> Option<views::ViewRef<V>>
|
||||
where
|
||||
V: View + Any,
|
||||
{
|
||||
self.call_on_id(id, views::NamedView::<V>::get_mut)
|
||||
self.find_name(id)
|
||||
}
|
||||
|
||||
/// Moves the focus to the view identified by `id`.
|
||||
/// Moves the focus to the view identified by `name`.
|
||||
///
|
||||
/// Convenient method to call `focus` with a `view::Selector::Id`.
|
||||
/// Convenient method to call `focus` with a [`view::Selector::Name`].
|
||||
pub fn focus_name(&mut self, name: &str) -> Result<(), ()> {
|
||||
self.focus(&view::Selector::Name(name))
|
||||
}
|
||||
|
||||
/// Same as [`focus_name`](Cursive::focus_name).
|
||||
#[deprecated(note = "`focus_id` is being renamed to `focus_name`")]
|
||||
pub fn focus_id(&mut self, id: &str) -> Result<(), ()> {
|
||||
self.focus(&view::Selector::Name(id))
|
||||
}
|
||||
|
@ -2,9 +2,6 @@
|
||||
//!
|
||||
//! This module defines two main concepts: [`Orientation`] and [`Direction`].
|
||||
//!
|
||||
//! [`Orientation`]: direction::Orientation
|
||||
//! [`Direction`]: direction::Direction
|
||||
//!
|
||||
//! ### Orientation
|
||||
//!
|
||||
//! `Orientation` is a simple enum that can take two values:
|
||||
|
13
src/event.rs
13
src/event.rs
@ -1,17 +1,16 @@
|
||||
//! User-input events and their effects.
|
||||
//!
|
||||
//! * Every user input the application receives is converted to an
|
||||
//! [`Event`](./enum.Event.html).
|
||||
//! * Every user input the application receives is converted to an [`Event`].
|
||||
//! * Each event is then given to the root, and descends the view tree down to
|
||||
//! the view currently in focus, through the
|
||||
//! [`on_event`](../view/trait.View.html#method.on_event) method.
|
||||
//! the view currently in focus, through the [`on_event`] method.
|
||||
//! * If the view consumes the event, it may return a callback to be
|
||||
//! executed.
|
||||
//! * Otherwise, it ignores the event, and the view parent can in turn
|
||||
//! choose to consume it or not.
|
||||
//! * If no view consumes the event, the
|
||||
//! [global callback](../struct.Cursive.html#method.add_global_callback)
|
||||
//! table is checked.
|
||||
//! * If no view consumes the event, the [global callback] table is checked.
|
||||
//!
|
||||
//! [`on_event`]: crate::View::on_event
|
||||
//! [global callback]: crate::Cursive::add_global_callback
|
||||
|
||||
use crate::vec::Vec2;
|
||||
use crate::Cursive;
|
||||
|
12
src/lib.rs
12
src/lib.rs
@ -8,19 +8,18 @@
|
||||
//!
|
||||
//! ## Getting started
|
||||
//!
|
||||
//! * Every application should start with a [`Cursive`](struct.Cursive.html)
|
||||
//! object. It is the main entry-point to the library.
|
||||
//! * Every application should start with a [`Cursive`] object. It is the main
|
||||
//! entry-point to the library.
|
||||
//! * A declarative phase then describes the structure of the UI by adding
|
||||
//! views and configuring their behaviours.
|
||||
//! * Finally, the event loop is started by calling
|
||||
//! [`Cursive::run(&mut self)`](struct.Cursive.html#method.run).
|
||||
//! * Finally, the event loop is started by calling [`Cursive::run`].
|
||||
//!
|
||||
//! ## Views
|
||||
//!
|
||||
//! Views are the main components of a cursive interface.
|
||||
//! The [`views`](./views/index.html) module contains many views to use in your
|
||||
//! The [`views`] module contains many views to use in your
|
||||
//! application; if you don't find what you need, you may also implement the
|
||||
//! [`View`](view/trait.View.html) trait and build your own.
|
||||
//! [`View`] trait and build your own.
|
||||
//!
|
||||
//! ## Callbacks
|
||||
//!
|
||||
@ -104,5 +103,6 @@ pub use self::cursive::{CbSink, Cursive, ScreenId};
|
||||
pub use self::printer::Printer;
|
||||
pub use self::rect::Rect;
|
||||
pub use self::vec::Vec2;
|
||||
pub use self::view::View;
|
||||
pub use self::with::With;
|
||||
pub use self::xy::XY;
|
||||
|
@ -2,7 +2,7 @@
|
||||
//!
|
||||
//! Menus are a way to arrange many actions in groups of more manageable size.
|
||||
//!
|
||||
//! A menu can be seen as a `MenuTree`. It has a list of children:
|
||||
//! A menu can be seen as a [`MenuTree`]. It has a list of children:
|
||||
//!
|
||||
//! * Leaf nodes are made of a label and a callback
|
||||
//! * Sub-trees are made of a label, and another `MenuTree`.
|
||||
@ -10,7 +10,7 @@
|
||||
//!
|
||||
//! The [menubar] is the main way to show menus.
|
||||
//!
|
||||
//! [menubar]: ../struct.Cursive.html#method.menubar
|
||||
//! [menubar]: crate::Cursive::menubar
|
||||
|
||||
use crate::event::Callback;
|
||||
use crate::Cursive;
|
||||
|
@ -5,8 +5,6 @@
|
||||
//! Characters can be printed in the terminal with a specific color.
|
||||
//! The [`Color`] enum represents the ways this can be set.
|
||||
//!
|
||||
//! [`Color`]: enum.Color.html
|
||||
//!
|
||||
//! # Palette
|
||||
//!
|
||||
//! To achieve a customizable, yet unified look, Cursive uses a configurable
|
||||
@ -14,8 +12,6 @@
|
||||
//!
|
||||
//! The [`PaletteColor`] enum defines possible entries in this palette.
|
||||
//!
|
||||
//! [`PaletteColor`]: enum.PaletteColor.html
|
||||
//!
|
||||
//! These entries are:
|
||||
//!
|
||||
//! * **`Background`**: used to color the application background
|
||||
@ -42,9 +38,6 @@
|
||||
//!
|
||||
//! A [`Palette`] then maps each of these to an actual [`Color`].
|
||||
//!
|
||||
//! [`Palette`]: type.Palette.html
|
||||
//! [`Color`]: enum.Color.html
|
||||
//!
|
||||
//! # Color Types
|
||||
//!
|
||||
//! When drawing views, color can be picked in two way:
|
||||
@ -55,8 +48,6 @@
|
||||
//!
|
||||
//! The [`ColorType`] enum abstract over these two choices.
|
||||
//!
|
||||
//! [`ColorType`]: enum.ColorType.html
|
||||
//!
|
||||
//! # Color Styles
|
||||
//!
|
||||
//! To actually print anything, two colors must be picked: one for the
|
||||
@ -102,8 +93,6 @@
|
||||
//! Using one of these pairs when styling your application helps give it a
|
||||
//! coherent look.
|
||||
//!
|
||||
//! [`ColorStyle`]: struct.ColorStyle.html
|
||||
//!
|
||||
//! # Effects
|
||||
//!
|
||||
//! On top of a color style, some effects can be applied on cells: `Reverse`,
|
||||
@ -115,8 +104,6 @@
|
||||
//! Finally, a style combine a [`ColorType`] and a set of [`Effect`]s, to
|
||||
//! represent any way text should be printed on screen.
|
||||
//!
|
||||
//! [`Effect`]: enum.Effect.html
|
||||
//!
|
||||
//! # Themes
|
||||
//!
|
||||
//! A theme defines the color palette an application will use, as well as
|
||||
|
@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
|
||||
/// Atomic counter used by [`ProgressBar`].
|
||||
///
|
||||
/// [`ProgressBar`]: ../views/struct.ProgressBar.html
|
||||
/// [`ProgressBar`]: crate::views::ProgressBar
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Counter(pub Arc<AtomicUsize>);
|
||||
|
||||
|
@ -15,8 +15,6 @@ use crate::utils::span::{IndexedSpan, Span, SpannedString};
|
||||
///
|
||||
/// **Note**: due to limitations in rustdoc, you will need to read the
|
||||
/// documentation from the [`SpannedString`] page.
|
||||
///
|
||||
/// [`SpannedString`]: ../span/struct.SpannedString.html
|
||||
pub type StyledString = SpannedString<Style>;
|
||||
|
||||
/// Indexes a span into a source string.
|
||||
|
@ -14,7 +14,7 @@ use crate::XY;
|
||||
/// currently shown on the [`XY`] page.
|
||||
///
|
||||
/// [#32077]: https://github.com/rust-lang/rust/issues/32077
|
||||
/// [`XY`]: ../struct.XY.html
|
||||
/// [`XY`]: crate::XY
|
||||
pub type Vec2 = XY<usize>;
|
||||
|
||||
impl<T: PartialOrd> PartialOrd for XY<T> {
|
||||
|
@ -7,8 +7,6 @@ use std::any::Any;
|
||||
/// This trait is mostly a wrapper around [`View::call_on_any`].
|
||||
///
|
||||
/// It provides a nicer interface to find a view when you know its type.
|
||||
///
|
||||
/// [`View::call_on_any`]: ./trait.View.html#method.call_on_any
|
||||
pub trait Finder {
|
||||
/// Runs a callback on the view identified by `sel`.
|
||||
///
|
||||
@ -25,23 +23,40 @@ pub trait Finder {
|
||||
V: View + Any,
|
||||
F: FnOnce(&mut V) -> R;
|
||||
|
||||
/// Convenient method to use `call_on` with a `view::Selector::Id`.
|
||||
/// Convenient method to use `call_on` with a `view::Selector::Name`.
|
||||
fn call_on_name<V, F, R>(&mut self, name: &str, callback: F) -> Option<R>
|
||||
where
|
||||
V: View + Any,
|
||||
F: FnOnce(&mut V) -> R,
|
||||
{
|
||||
self.call_on(&Selector::Name(name), callback)
|
||||
}
|
||||
|
||||
/// Same as [`call_on_name`](Finder::call_on_name).
|
||||
#[deprecated(note = "`call_on_id` is being renamed to `call_on_name`")]
|
||||
fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R>
|
||||
where
|
||||
V: View + Any,
|
||||
F: FnOnce(&mut V) -> R,
|
||||
{
|
||||
self.call_on(&Selector::Name(id), callback)
|
||||
self.call_on_name(id, callback)
|
||||
}
|
||||
|
||||
/// Convenient method to find a view wrapped in an [`NamedView`].
|
||||
///
|
||||
/// [`NamedView`]: views/struct.NamedView.html
|
||||
fn find_name<V>(&mut self, name: &str) -> Option<ViewRef<V>>
|
||||
where
|
||||
V: View + Any,
|
||||
{
|
||||
self.call_on_name(name, NamedView::<V>::get_mut)
|
||||
}
|
||||
|
||||
/// Same as [`find_name`](Finder::find_name()).
|
||||
#[deprecated(note = "`find_id` is being renamed to `find_name`")]
|
||||
fn find_id<V>(&mut self, id: &str) -> Option<ViewRef<V>>
|
||||
where
|
||||
V: View + Any,
|
||||
{
|
||||
self.call_on_id(id, NamedView::<V>::get_mut)
|
||||
self.find_name(id)
|
||||
}
|
||||
}
|
||||
|
||||
@ -81,7 +96,9 @@ impl<T: View> Finder for T {
|
||||
/// Selects a single view (if any) in the tree.
|
||||
pub enum Selector<'a> {
|
||||
/// Selects a view from its ID.
|
||||
#[deprecated(note = "Id is being renamed to Name")]
|
||||
#[deprecated(
|
||||
note = "`Selector::Id` is being renamed to `Selector::Name`"
|
||||
)]
|
||||
Id(&'a str),
|
||||
|
||||
/// Selects a view from its name.
|
||||
|
@ -119,8 +119,8 @@ pub use self::view_path::ViewPath;
|
||||
pub use self::view_trait::View;
|
||||
pub use self::view_wrapper::ViewWrapper;
|
||||
|
||||
#[deprecated(note = "Boxable is being renamed to Resizable")]
|
||||
#[deprecated(note = "`Boxable` is being renamed to `Resizable`")]
|
||||
pub use self::resizable::Resizable as Boxable;
|
||||
|
||||
#[deprecated(note = "Identifiable is being renamed to Nameable")]
|
||||
#[deprecated(note = "`Identifiable` is being renamed to `Nameable`")]
|
||||
pub use self::nameable::Nameable as Identifiable;
|
||||
|
@ -2,8 +2,6 @@ use crate::view::View;
|
||||
use crate::views::NamedView;
|
||||
|
||||
/// Makes a view wrappable in an [`NamedView`].
|
||||
///
|
||||
/// [`NamedView`]: ../views/struct.NamedView.html
|
||||
pub trait Nameable: View + Sized {
|
||||
/// Wraps this view into an `NamedView` with the given id.
|
||||
///
|
||||
@ -22,12 +20,12 @@ pub trait Nameable: View + Sized {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
/// siv.add_layer(
|
||||
/// TextView::new("foo")
|
||||
/// .with_id("text")
|
||||
/// .with_name("text")
|
||||
/// .fixed_width(10)
|
||||
/// );
|
||||
///
|
||||
/// // You could call this from an event callback
|
||||
/// siv.call_on_id("text", |view: &mut TextView| {
|
||||
/// siv.call_on_name("text", |view: &mut TextView| {
|
||||
/// view.set_content("New content!");
|
||||
/// });
|
||||
/// ```
|
||||
@ -38,15 +36,15 @@ pub trait Nameable: View + Sized {
|
||||
/// before other wrappers like [`fixed_width`]. Otherwise, you would be
|
||||
/// retrieving a [`ResizedView`]!
|
||||
///
|
||||
/// [`fixed_width`]: trait.Resizable.html#method.fixed_width
|
||||
/// [`ResizedView`]: ../views/struct.ResizedView.html
|
||||
/// [`fixed_width`]: crate::view::Resizable::fixed_width
|
||||
/// [`ResizedView`]: crate::views::ResizedView
|
||||
///
|
||||
fn with_name<S: Into<String>>(self, name: S) -> NamedView<Self> {
|
||||
NamedView::new(name, self)
|
||||
}
|
||||
|
||||
/// Same as [`with_name`](Self::with_name())
|
||||
#[deprecated(note = "with_id is being renamed to with_name")]
|
||||
/// Same as [`with_name`](Nameable::with_name)
|
||||
#[deprecated(note = "`with_id` is being renamed to `with_name`")]
|
||||
fn with_id<S: Into<String>>(self, id: S) -> NamedView<Self> {
|
||||
self.with_name(id)
|
||||
}
|
||||
|
@ -3,11 +3,9 @@ use crate::view::{SizeConstraint, View};
|
||||
use crate::views::ResizedView;
|
||||
|
||||
/// Makes a view wrappable in a [`ResizedView`].
|
||||
///
|
||||
/// [`ResizedView`]: ../views/struct.ResizedView.html
|
||||
pub trait Resizable: View + Sized {
|
||||
/// Same as [`resized`](Self::resized())
|
||||
#[deprecated(note = "Use resized() instead.")]
|
||||
/// Same as [`resized`](Resizable::resized)
|
||||
#[deprecated(note = "Use `Resizable::resized()` instead.")]
|
||||
fn boxed(
|
||||
self,
|
||||
width: SizeConstraint,
|
||||
|
@ -4,7 +4,7 @@ use std::cmp::min;
|
||||
///
|
||||
/// This describes a possible behaviour for a [`ResizedView`].
|
||||
///
|
||||
/// [`ResizedView`]: ../views/struct.ResizedView.html
|
||||
/// [`ResizedView`]: crate::views::ResizedView
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum SizeConstraint {
|
||||
/// No constraint imposed, the child view's response is used.
|
||||
|
@ -76,7 +76,7 @@ pub trait View: Any + AnyView {
|
||||
/// See [`Finder::call_on`] for a nicer interface, implemented for all
|
||||
/// views.
|
||||
///
|
||||
/// [`Finder::call_on`]: trait.Finder.html#method.call_on
|
||||
/// [`Finder::call_on`]: crate::view::Finder::call_on
|
||||
///
|
||||
/// If the selector doesn't find a match, the closure will not be run.
|
||||
///
|
||||
|
@ -17,8 +17,6 @@ use crate::Printer;
|
||||
/// You can also override any of the `wrap_*` methods for more specific
|
||||
/// behaviors (the default implementations simply forwards the calls to the
|
||||
/// child view).
|
||||
///
|
||||
/// [`wrap_impl!`]: ../macro.wrap_impl.html
|
||||
pub trait ViewWrapper: 'static {
|
||||
/// Type that this view wraps.
|
||||
type V: View + ?Sized;
|
||||
@ -151,7 +149,7 @@ impl<T: ViewWrapper> View for T {
|
||||
/// It defines the `with_view` and `with_view_mut` implementations,
|
||||
/// as well as the `type V` declaration.
|
||||
///
|
||||
/// [`ViewWrapper`]: view/trait.ViewWrapper.html
|
||||
/// [`ViewWrapper`]: crate::view::ViewWrapper
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@ -194,8 +192,8 @@ macro_rules! wrap_impl {
|
||||
///
|
||||
/// It defines the `get_inner` and `get_inner_mut` implementations.
|
||||
///
|
||||
/// [`ViewWrapper`]: view/trait.ViewWrapper.html
|
||||
/// [`View`]: view/trait.View.html
|
||||
/// [`ViewWrapper`]: crate::view::ViewWrapper
|
||||
/// [`View`]: crate::View
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -16,7 +16,7 @@ use std::rc::Rc;
|
||||
/// use cursive::views::Checkbox;
|
||||
/// use cursive::traits::Identifiable;
|
||||
///
|
||||
/// let checkbox = Checkbox::new().checked().with_id("check");
|
||||
/// let checkbox = Checkbox::new().checked().with_name("check");
|
||||
/// ```
|
||||
pub struct Checkbox {
|
||||
checked: bool,
|
||||
|
@ -14,8 +14,6 @@ use std::cmp::max;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
/// Identifies currently focused element in [`Dialog`].
|
||||
///
|
||||
/// [`Dialog`]: struct.Dialog.html
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum DialogFocus {
|
||||
/// Content element focused
|
||||
|
@ -46,11 +46,11 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
||||
/// .content(
|
||||
/// EditView::new()
|
||||
/// .on_submit(show_popup)
|
||||
/// .with_id("name")
|
||||
/// .with_name("name")
|
||||
/// .fixed_width(20),
|
||||
/// )
|
||||
/// .button("Ok", |s| {
|
||||
/// let name = s.call_on_id(
|
||||
/// let name = s.call_on_name(
|
||||
/// "name",
|
||||
/// |view: &mut EditView| view.get_content(),
|
||||
/// ).unwrap();
|
||||
|
@ -16,9 +16,9 @@ use crate::Printer;
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// siv.add_layer(LinearLayout::vertical()
|
||||
/// .child(EnableableView::new(Checkbox::new()).with_id("my_view"))
|
||||
/// .child(EnableableView::new(Checkbox::new()).with_name("my_view"))
|
||||
/// .child(Button::new("Toggle", |s| {
|
||||
/// s.call_on_id("my_view", |v: &mut EnableableView<Checkbox>| {
|
||||
/// s.call_on_name("my_view", |v: &mut EnableableView<Checkbox>| {
|
||||
/// // This will disable (or re-enable) the checkbox, preventing the user from
|
||||
/// // interacting with it.
|
||||
/// v.set_enabled(!v.is_enabled());
|
||||
|
@ -6,7 +6,7 @@ use crate::Printer;
|
||||
///
|
||||
/// This is mostly used as layer in the [`StackView`].
|
||||
///
|
||||
/// [`StackView`]: struct.StackView.html
|
||||
/// [`StackView`]: crate::views::StackView
|
||||
#[derive(Debug)]
|
||||
pub struct Layer<T: View> {
|
||||
view: T,
|
||||
|
@ -11,8 +11,6 @@ use std::rc::Rc;
|
||||
use unicode_width::UnicodeWidthStr;
|
||||
|
||||
/// Represents a child from a [`ListView`].
|
||||
///
|
||||
/// [`ListView`]: struct.ListView.html
|
||||
pub enum ListChild {
|
||||
/// A single row, with a label and a view.
|
||||
Row(String, Box<dyn View>),
|
||||
|
@ -31,7 +31,7 @@ enum State {
|
||||
/// The [`Cursive`] root already includes a menubar
|
||||
/// that you just need to configure.
|
||||
///
|
||||
/// [`Cursive`]: ../struct.Cursive.html#method.menubar
|
||||
/// [`Cursive`]: crate::Cursive::menubar
|
||||
pub struct Menubar {
|
||||
/// Menu items in this menubar.
|
||||
root: MenuTree,
|
||||
|
@ -119,17 +119,17 @@ pub use self::text_view::{TextContent, TextContentRef, TextView};
|
||||
pub use self::tracked_view::TrackedView;
|
||||
|
||||
/// Same as [`LastSizeView`](self::LastSizeView).
|
||||
#[deprecated(note = "SizedView is being renamed to LastSizeView")]
|
||||
#[deprecated(note = "`SizedView` is being renamed to `LastSizeView`")]
|
||||
pub type SizedView<T> = LastSizeView<T>;
|
||||
|
||||
/// Same as [`ResizedView`](self::ResizedView).
|
||||
#[deprecated(note = "BoxView is being renamed to ResizedView")]
|
||||
#[deprecated(note = "`BoxView` is being renamed to `ResizedView`")]
|
||||
pub type BoxView<T> = ResizedView<T>;
|
||||
|
||||
/// Same as [`BoxedView`](self::BoxedView).
|
||||
#[deprecated(note = "ViewBox is being renamed to BoxedView")]
|
||||
#[deprecated(note = "`ViewBox` is being renamed to `BoxedView`")]
|
||||
pub type ViewBox = BoxedView;
|
||||
|
||||
/// Same as [`NamedView`](self::NamedView).
|
||||
#[deprecated(note = "IdView is being renamed to NamedView")]
|
||||
#[deprecated(note = "`IdView` is being renamed to `NamedView`")]
|
||||
pub type IdView<T> = NamedView<T>;
|
||||
|
@ -19,7 +19,7 @@ pub struct NamedView<V: View> {
|
||||
///
|
||||
/// This behaves like a [`RefMut`], but without being tied to a lifetime.
|
||||
///
|
||||
/// [`RefMut`]: https://doc.rust-lang.org/std/cell/struct.RefMut.html
|
||||
/// [`RefMut`]: std::cell::RefMut
|
||||
pub type ViewRef<V> = OwningHandle<RcRef<RefCell<V>>, RefMut<'static, V>>;
|
||||
|
||||
impl<V: View> NamedView<V> {
|
||||
|
@ -24,10 +24,10 @@ use std::rc::Rc;
|
||||
/// "Simple" callbacks ([`on_event`] and [`on_pre_event`]) skip this first
|
||||
/// phase and are only called with a `&mut Cursive`.
|
||||
///
|
||||
/// [`on_event`]: struct.OnEventView.html#method.on_event
|
||||
/// [`on_pre_event`]: struct.OnEventView.html#method.on_pre_event
|
||||
/// [`on_event_inner`]: struct.OnEventView.html#method.on_event_inner
|
||||
/// [`on_pre_event_inner`]: struct.OnEventView.html#method.on_pre_event_inner
|
||||
/// [`on_event`]: OnEventView::on_event
|
||||
/// [`on_pre_event`]: OnEventView::on_pre_event
|
||||
/// [`on_event_inner`]: OnEventView::on_event_inner
|
||||
/// [`on_pre_event_inner`]: OnEventView::on_pre_event_inner
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
|
@ -26,8 +26,6 @@ impl<T> SharedState<T> {
|
||||
/// A `RadioGroup` is used to create and manage [`RadioButton`]s.
|
||||
///
|
||||
/// A `RadioGroup` can be cloned; it will keep pointing to the same group.
|
||||
///
|
||||
/// [`RadioButton`]: struct.RadioButton.html
|
||||
#[derive(Clone)]
|
||||
pub struct RadioGroup<T> {
|
||||
// Given to every child button
|
||||
@ -114,10 +112,8 @@ impl RadioGroup<String> {
|
||||
/// time.
|
||||
///
|
||||
/// `RadioButton`s are not created directly, but through
|
||||
/// [`RadioGroup::button()`].
|
||||
/// [`RadioGroup::button`].
|
||||
///
|
||||
/// [`RadioGroup`]: struct.RadioGroup.html
|
||||
/// [`RadioGroup::button()`]: struct.RadioGroup.html#method.button
|
||||
pub struct RadioButton<T> {
|
||||
state: Rc<RefCell<SharedState<T>>>,
|
||||
id: usize,
|
||||
|
@ -178,7 +178,7 @@ impl<T: 'static> SelectView<T> {
|
||||
/// use cursive::traits::Identifiable;
|
||||
/// use cursive::views::{TextView, SelectView};
|
||||
///
|
||||
/// let text_view = TextView::new("").with_id("text");
|
||||
/// let text_view = TextView::new("").with_name("text");
|
||||
///
|
||||
/// let select_view = SelectView::new()
|
||||
/// .item("One", 1)
|
||||
@ -191,7 +191,7 @@ impl<T: 'static> SelectView<T> {
|
||||
/// };
|
||||
///
|
||||
/// // Update the textview with the currently selected item.
|
||||
/// s.call_on_id("text", |v: &mut TextView| {
|
||||
/// s.call_on_name("text", |v: &mut TextView| {
|
||||
/// v.set_content(content);
|
||||
/// }).unwrap();
|
||||
/// });
|
||||
|
@ -312,12 +312,12 @@ impl StackView {
|
||||
/// # use cursive::view::Identifiable;
|
||||
/// let mut stack = StackView::new();
|
||||
/// stack.add_layer(TextView::new("Back"));
|
||||
/// stack.add_layer(Dialog::around(TextView::new("Middle").with_id("text")));
|
||||
/// stack.add_layer(Dialog::around(TextView::new("Middle").with_name("text")));
|
||||
/// stack.add_layer(TextView::new("Front"));
|
||||
///
|
||||
/// assert_eq!(stack.find_layer_from_id("text"), Some(LayerPosition::FromBack(1)));
|
||||
/// assert_eq!(stack.find_layer_from_name("text"), Some(LayerPosition::FromBack(1)));
|
||||
/// ```
|
||||
pub fn find_layer_from_id(&mut self, id: &str) -> Option<LayerPosition> {
|
||||
pub fn find_layer_from_name(&mut self, id: &str) -> Option<LayerPosition> {
|
||||
let selector = Selector::Name(id);
|
||||
|
||||
for (i, child) in self.layers.iter_mut().enumerate() {
|
||||
@ -331,6 +331,14 @@ impl StackView {
|
||||
None
|
||||
}
|
||||
|
||||
/// Same as [`find_layer_from_name`](StackView::find_layer_from_name).
|
||||
#[deprecated(
|
||||
note = "`find_layer_from_id` is being renamed to `find_layer_from_name`"
|
||||
)]
|
||||
pub fn find_layer_from_id(&mut self, id: &str) -> Option<LayerPosition> {
|
||||
self.find_layer_from_name(id)
|
||||
}
|
||||
|
||||
/// Adds a new full-screen layer on top of the stack.
|
||||
///
|
||||
/// Chainable variant.
|
||||
|
@ -25,7 +25,7 @@ use unicode_width::UnicodeWidthStr;
|
||||
///
|
||||
/// let text_area = TextArea::new()
|
||||
/// .content("Write description here...")
|
||||
/// .with_id("text_area")
|
||||
/// .with_name("text_area")
|
||||
/// .fixed_width(30)
|
||||
/// .min_height(5);
|
||||
/// ```
|
||||
|
@ -19,8 +19,6 @@ type InnerContentType = Arc<StyledString>;
|
||||
///
|
||||
/// Cloning this object will still point to the same content.
|
||||
///
|
||||
/// [`TextView`]: struct.TextView.html
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
@ -61,8 +59,6 @@ impl TextContent {
|
||||
///
|
||||
/// This can be deref'ed into a [`StyledString`].
|
||||
///
|
||||
/// [`StyledString`]: ../utils/markup/type.StyledString.html
|
||||
///
|
||||
/// This keeps the content locked. Do not store this!
|
||||
pub struct TextContentRef {
|
||||
_handle: OwningHandle<
|
||||
|
@ -26,8 +26,8 @@ impl<T: View> TrackedView<T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Same as [`with_name`](Self::with_name())
|
||||
#[deprecated(note = "with_id is being renamed to with_name")]
|
||||
/// Same as [`with_name`](TrackedView::with_name)
|
||||
#[deprecated(note = "`with_id` is being renamed to `with_name`")]
|
||||
pub fn with_id(self, id: &str) -> NamedView<Self> {
|
||||
self.with_name(id)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user