mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 09:25:01 +00:00
Add PaddedView::get_inner(_mut) and fix clippy warnings
This commit is contained in:
parent
985e4ebf96
commit
884796fb02
@ -334,12 +334,10 @@ impl Cursive {
|
||||
///
|
||||
/// ```rust
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// // quit() will be called during the next event cycle
|
||||
/// siv.cb_sink().send(Box::new(|s| s.quit())).unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn cb_sink(&self) -> &CbSink {
|
||||
&self.cb_sink
|
||||
@ -370,7 +368,6 @@ impl Cursive {
|
||||
/// # use cursive::traits::*;
|
||||
/// # use cursive::menu::*;
|
||||
/// #
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// siv.menubar()
|
||||
@ -404,7 +401,6 @@ impl Cursive {
|
||||
/// |s| s.add_layer(Dialog::info("Cursive v0.0.0"))));
|
||||
///
|
||||
/// siv.add_global_callback(event::Key::Esc, |s| s.select_menubar());
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn menubar(&mut self) -> &mut views::Menubar {
|
||||
&mut self.menubar
|
||||
@ -526,23 +522,18 @@ impl Cursive {
|
||||
/// ```rust
|
||||
/// # use cursive::{Cursive, views, view};
|
||||
/// # use cursive::traits::*;
|
||||
/// # fn main() {
|
||||
/// fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
/// 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_id("text"));
|
||||
///
|
||||
/// siv.add_global_callback('p', |s| {
|
||||
/// s.call_on(
|
||||
/// &view::Selector::Id("text"),
|
||||
/// |view: &mut views::TextView| {
|
||||
/// view.set_content("Text #2");
|
||||
/// },
|
||||
/// );
|
||||
/// });
|
||||
///
|
||||
/// }
|
||||
/// # }
|
||||
/// siv.add_global_callback('p', |s| {
|
||||
/// s.call_on(
|
||||
/// &view::Selector::Id("text"),
|
||||
/// |view: &mut views::TextView| {
|
||||
/// view.set_content("Text #2");
|
||||
/// },
|
||||
/// );
|
||||
/// });
|
||||
/// ```
|
||||
pub fn call_on<V, F, R>(
|
||||
&mut self,
|
||||
@ -565,7 +556,6 @@ impl Cursive {
|
||||
/// ```rust
|
||||
/// # use cursive::{Cursive, views};
|
||||
/// # use cursive::traits::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// siv.add_layer(views::TextView::new("Text #1")
|
||||
@ -576,7 +566,6 @@ impl Cursive {
|
||||
/// view.set_content("Text #2");
|
||||
/// });
|
||||
/// });
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn call_on_id<V, F, R>(&mut self, id: &str, callback: F) -> Option<R>
|
||||
where
|
||||
@ -658,11 +647,9 @@ impl Cursive {
|
||||
///
|
||||
/// ```rust
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// siv.add_global_callback('q', |s| s.quit());
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn add_global_callback<F, E: Into<Event>>(&mut self, event: E, cb: F)
|
||||
where
|
||||
@ -679,13 +666,11 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// use cursive::Cursive;
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// siv.add_global_callback('q', |s| s.quit());
|
||||
/// siv.clear_global_callbacks('q');
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn clear_global_callbacks<E>(&mut self, event: E)
|
||||
where
|
||||
@ -700,12 +685,10 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use cursive::*;
|
||||
/// # fn main() {
|
||||
/// use cursive::{Cursive, views};
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// siv.add_layer(views::TextView::new("Hello world!"));
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn add_layer<T>(&mut self, view: T)
|
||||
where
|
||||
|
10
src/lib.rs
10
src/lib.rs
@ -36,15 +36,13 @@
|
||||
//! use cursive::Cursive;
|
||||
//! use cursive::views::TextView;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let mut siv = Cursive::dummy();
|
||||
//! let mut siv = Cursive::dummy();
|
||||
//!
|
||||
//! siv.add_layer(TextView::new("Hello World!\nPress q to quit."));
|
||||
//! siv.add_layer(TextView::new("Hello World!\nPress q to quit."));
|
||||
//!
|
||||
//! siv.add_global_callback('q', |s| s.quit());
|
||||
//! siv.add_global_callback('q', |s| s.quit());
|
||||
//!
|
||||
//! siv.run();
|
||||
//! }
|
||||
//! siv.run();
|
||||
//! ```
|
||||
//!
|
||||
//! ## Debugging
|
||||
|
@ -42,12 +42,10 @@ pub fn make_lines(content: &str, width: usize) -> Vec<Row> {
|
||||
/// use unicode_segmentation::UnicodeSegmentation;
|
||||
///
|
||||
/// # use cursive::utils::lines::simple::prefix;
|
||||
/// # fn main() {
|
||||
/// let my_text = "blah...";
|
||||
/// // This returns the number of bytes for a prefix of `my_text` that
|
||||
/// // fits within 5 cells.
|
||||
/// prefix(my_text.graphemes(true), 5, "");
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Span
|
||||
where
|
||||
|
@ -20,10 +20,8 @@ pub trait AnyView {
|
||||
/// ```rust
|
||||
/// # use cursive::views::TextView;
|
||||
/// # use cursive::view::View;
|
||||
/// # fn main() {
|
||||
/// let boxed: Box<View> = Box::new(TextView::new("text"));
|
||||
/// let text: Box<TextView> = boxed.as_boxed_any().downcast().unwrap();
|
||||
/// # }
|
||||
/// ```
|
||||
fn as_boxed_any(self: Box<Self>) -> Box<dyn Any>;
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
||||
/// # use cursive::Cursive;
|
||||
/// # use cursive::traits::*;
|
||||
/// # use cursive::views::{Dialog, EditView, TextView};
|
||||
/// # fn main() {
|
||||
/// let mut siv = Cursive::dummy();
|
||||
///
|
||||
/// // Create a dialog with an edit text and a button.
|
||||
@ -69,8 +68,6 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
||||
/// .button("Quit", |s| s.quit()));
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// # }
|
||||
/// ```
|
||||
pub struct EditView {
|
||||
/// Current content.
|
||||
|
@ -25,6 +25,8 @@ pub struct PaddedView<V> {
|
||||
}
|
||||
|
||||
impl<V: View> PaddedView<V> {
|
||||
inner_getters!(self.view: V);
|
||||
|
||||
/// Wraps `view` in a new `PaddedView` with the given margins.
|
||||
pub fn new<M: Into<Margins>>(margins: M, view: V) -> Self {
|
||||
let margins = margins.into();
|
||||
|
@ -28,7 +28,6 @@ use std::rc::Rc;
|
||||
/// # use cursive::Cursive;
|
||||
/// # use cursive::views::{SelectView, Dialog, TextView};
|
||||
/// # use cursive::align::HAlign;
|
||||
/// # fn main() {
|
||||
/// let mut time_select = SelectView::new().h_align(HAlign::Center);
|
||||
/// time_select.add_item("Short", 1);
|
||||
/// time_select.add_item("Medium", 5);
|
||||
@ -44,8 +43,6 @@ use std::rc::Rc;
|
||||
/// let mut siv = Cursive::dummy();
|
||||
/// siv.add_layer(Dialog::around(time_select)
|
||||
/// .title("How long is your wait?"));
|
||||
/// # }
|
||||
///
|
||||
/// ```
|
||||
pub struct SelectView<T = String> {
|
||||
// The core of the view: we store a list of items
|
||||
@ -586,7 +583,6 @@ impl<T: 'static> SelectView<T> {
|
||||
/// ```rust
|
||||
/// # use cursive::Cursive;
|
||||
/// # use cursive::views::SelectView;
|
||||
/// # fn main() {}
|
||||
/// fn select_up(siv: &mut Cursive, view: &mut SelectView<()>) {
|
||||
/// let cb = view.select_up(1);
|
||||
/// cb(siv);
|
||||
|
@ -310,14 +310,12 @@ impl StackView {
|
||||
/// ```rust
|
||||
/// # use cursive::views::{TextView, StackView, Dialog, LayerPosition};
|
||||
/// # use cursive::view::Identifiable;
|
||||
/// # fn main() {
|
||||
/// 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(TextView::new("Front"));
|
||||
///
|
||||
/// assert_eq!(stack.find_layer_from_id("text"), Some(LayerPosition::FromBack(1)));
|
||||
/// # }
|
||||
/// ```
|
||||
pub fn find_layer_from_id(&mut self, id: &str) -> Option<LayerPosition> {
|
||||
let selector = Selector::Id(id);
|
||||
|
Loading…
Reference in New Issue
Block a user