mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-09 10:50:40 +00:00
Update rustfmt config
Now uses nightly rustfmt.
This commit is contained in:
parent
368dca6033
commit
418fda99ba
@ -309,14 +309,18 @@ impl Cursive {
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
/// siv.menubar()
|
||||
/// .add_subtree("File",
|
||||
/// .add_subtree(
|
||||
/// "File",
|
||||
/// MenuTree::new()
|
||||
/// .leaf("New", |s| s.add_layer(Dialog::info("New file!")))
|
||||
/// .subtree("Recent", MenuTree::new().with(|tree| {
|
||||
/// for i in 1..100 {
|
||||
/// tree.add_leaf(format!("Item {}", i), |_| ())
|
||||
/// }
|
||||
/// }))
|
||||
/// .subtree(
|
||||
/// "Recent",
|
||||
/// MenuTree::new().with(|tree| {
|
||||
/// for i in 1..100 {
|
||||
/// tree.add_leaf(format!("Item {}", i), |_| ())
|
||||
/// }
|
||||
/// }),
|
||||
/// )
|
||||
/// .delimiter()
|
||||
/// .with(|tree| {
|
||||
/// for i in 1..10 {
|
||||
@ -324,19 +328,25 @@ impl Cursive {
|
||||
/// }
|
||||
/// })
|
||||
/// .delimiter()
|
||||
/// .leaf("Quit", |s| s.quit()))
|
||||
/// .add_subtree("Help",
|
||||
/// .leaf("Quit", |s| s.quit()),
|
||||
/// )
|
||||
/// .add_subtree(
|
||||
/// "Help",
|
||||
/// MenuTree::new()
|
||||
/// .subtree("Help",
|
||||
/// MenuTree::new()
|
||||
/// .leaf("General", |s| {
|
||||
/// s.add_layer(Dialog::info("Help message!"))
|
||||
/// })
|
||||
/// .leaf("Online", |s| {
|
||||
/// s.add_layer(Dialog::info("Online help?"))
|
||||
/// }))
|
||||
/// .leaf("About",
|
||||
/// |s| s.add_layer(Dialog::info("Cursive v0.0.0"))));
|
||||
/// .subtree(
|
||||
/// "Help",
|
||||
/// MenuTree::new()
|
||||
/// .leaf("General", |s| {
|
||||
/// s.add_layer(Dialog::info("Help message!"))
|
||||
/// })
|
||||
/// .leaf("Online", |s| {
|
||||
/// s.add_layer(Dialog::info("Online help?"))
|
||||
/// }),
|
||||
/// )
|
||||
/// .leaf("About", |s| {
|
||||
/// s.add_layer(Dialog::info("Cursive v0.0.0"))
|
||||
/// }),
|
||||
/// );
|
||||
///
|
||||
/// siv.add_global_callback(event::Key::Esc, |s| s.select_menubar());
|
||||
/// ```
|
||||
@ -503,8 +513,7 @@ impl Cursive {
|
||||
/// # use cursive_core::traits::*;
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
/// siv.add_layer(views::TextView::new("Text #1")
|
||||
/// .with_name("text"));
|
||||
/// siv.add_layer(views::TextView::new("Text #1").with_name("text"));
|
||||
///
|
||||
/// siv.add_global_callback('p', |s| {
|
||||
/// s.call_on_name("text", |view: &mut views::TextView| {
|
||||
@ -754,7 +763,7 @@ impl Cursive {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use cursive_core::{Cursive, views};
|
||||
/// use cursive_core::{views, Cursive};
|
||||
/// let mut siv = Cursive::new();
|
||||
///
|
||||
/// siv.add_layer(views::TextView::new("Hello world!"));
|
||||
|
@ -82,7 +82,10 @@ impl EventTrigger {
|
||||
///
|
||||
/// let event = Event::CtrlChar('c');
|
||||
/// let trigger: EventTrigger = event.clone().into();
|
||||
/// assert!(trigger.has_tag(&event), "Trigger does not recognize its own tag.");
|
||||
/// assert!(
|
||||
/// trigger.has_tag(&event),
|
||||
/// "Trigger does not recognize its own tag."
|
||||
/// );
|
||||
/// ```
|
||||
pub fn has_tag<T: PartialEq + 'static>(&self, tag: &T) -> bool {
|
||||
(*self.tag)
|
||||
@ -116,13 +119,7 @@ impl EventTrigger {
|
||||
|
||||
/// Returns an `EventTrigger` that only accepts mouse events.
|
||||
pub fn mouse() -> Self {
|
||||
Self::from_fn_and_tag(
|
||||
|e| {
|
||||
matches!(e,
|
||||
Event::Mouse { .. })
|
||||
},
|
||||
"mouse",
|
||||
)
|
||||
Self::from_fn_and_tag(|e| matches!(e, Event::Mouse { .. }), "mouse")
|
||||
}
|
||||
|
||||
/// Returns an `EventTrigger` that accepts any event.
|
||||
@ -459,10 +456,10 @@ impl MouseEvent {
|
||||
/// It means you should be able to grab a scroll bar, and move the mouse
|
||||
/// away from the view, without actually changing the focus.
|
||||
pub fn grabs_focus(self) -> bool {
|
||||
matches!(self,
|
||||
MouseEvent::Press(_)
|
||||
| MouseEvent::WheelUp
|
||||
| MouseEvent::WheelDown)
|
||||
matches!(
|
||||
self,
|
||||
MouseEvent::Press(_) | MouseEvent::WheelUp | MouseEvent::WheelDown
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -299,7 +299,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// # let t = theme::load_default();
|
||||
/// # let printer = Printer::new((6,4), &t, &*b);
|
||||
/// printer.with_color(theme::ColorStyle::highlight(), |printer| {
|
||||
/// printer.print((0,0), "This text is highlighted!");
|
||||
/// printer.print((0, 0), "This text is highlighted!");
|
||||
/// });
|
||||
/// ```
|
||||
pub fn with_color<F>(&self, c: ColorStyle, f: F)
|
||||
@ -394,7 +394,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
||||
/// # let b = backend::Dummy::init();
|
||||
/// # let t = theme::load_default();
|
||||
/// # let printer = Printer::new((6,4), &t, &*b);
|
||||
/// printer.print_box((0,0), (6,4), false);
|
||||
/// printer.print_box((0, 0), (6, 4), false);
|
||||
/// ```
|
||||
pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(
|
||||
&self,
|
||||
|
@ -57,13 +57,16 @@ pub fn immutify<F: FnMut(&mut Cursive)>(
|
||||
/// # let mut siv = Cursive::new();
|
||||
/// let mut i = 0;
|
||||
/// // `Cursive::add_global_callback` takes a `Fn(&mut Cursive)`
|
||||
/// siv.add_global_callback('q', immut1!(move |s: &mut Cursive| {
|
||||
/// // But here we mutate the environment! Crazy!
|
||||
/// i += 1;
|
||||
/// if i == 5 {
|
||||
/// s.quit();
|
||||
/// }
|
||||
/// }));
|
||||
/// siv.add_global_callback(
|
||||
/// 'q',
|
||||
/// immut1!(move |s: &mut Cursive| {
|
||||
/// // But here we mutate the environment! Crazy!
|
||||
/// i += 1;
|
||||
/// if i == 5 {
|
||||
/// s.quit();
|
||||
/// }
|
||||
/// }),
|
||||
/// );
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
|
@ -20,11 +20,7 @@ pub trait Nameable: View + Sized {
|
||||
/// use cursive_core::view::Nameable;
|
||||
///
|
||||
/// let mut siv = Cursive::new();
|
||||
/// siv.add_layer(
|
||||
/// TextView::new("foo")
|
||||
/// .with_name("text")
|
||||
/// .fixed_width(10)
|
||||
/// );
|
||||
/// siv.add_layer(TextView::new("foo").with_name("text").fixed_width(10));
|
||||
///
|
||||
/// // You could call this from an event callback
|
||||
/// siv.call_on_name("text", |view: &mut TextView| {
|
||||
@ -40,7 +36,6 @@ pub trait Nameable: View + Sized {
|
||||
///
|
||||
/// [`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)
|
||||
}
|
||||
|
@ -50,9 +50,9 @@ impl Default for ScrollStrategy {
|
||||
/// Example:
|
||||
///
|
||||
/// ```
|
||||
/// use cursive_core::{Printer, Vec2, Rect};
|
||||
/// use cursive_core::event::{Event, EventResult};
|
||||
/// use cursive_core::view::{View, scroll};
|
||||
/// use cursive_core::view::{scroll, View};
|
||||
/// use cursive_core::{Printer, Rect, Vec2};
|
||||
///
|
||||
/// struct MyView {
|
||||
/// core: scroll::Core,
|
||||
@ -66,14 +66,19 @@ impl Default for ScrollStrategy {
|
||||
/// }
|
||||
///
|
||||
/// fn inner_important_area(&self, size: Vec2) -> Rect {
|
||||
/// Rect::from_size((0,0), size)
|
||||
/// Rect::from_size((0, 0), size)
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// impl View for MyView {
|
||||
/// # fn draw(&self, printer: &Printer) {}
|
||||
/// fn on_event(&mut self, event: Event) -> EventResult {
|
||||
/// scroll::on_event(self, event, Self::inner_on_event, Self::inner_important_area)
|
||||
/// scroll::on_event(
|
||||
/// self,
|
||||
/// event,
|
||||
/// Self::inner_on_event,
|
||||
/// Self::inner_important_area,
|
||||
/// )
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -2,7 +2,6 @@
|
||||
//!
|
||||
//! Most functions take a generic `Model` class, and various closures to get
|
||||
//! the required things from this model.
|
||||
//!
|
||||
use crate::{
|
||||
event::{Event, EventResult, Key, MouseButton, MouseEvent},
|
||||
rect::Rect,
|
||||
|
@ -224,7 +224,7 @@ impl ScrollBase {
|
||||
/// # let printer = &printer;
|
||||
/// let lines = ["Line 1", "Line number 2"];
|
||||
/// scrollbase.draw(printer, |printer, i| {
|
||||
/// printer.print((0,0), lines[i]);
|
||||
/// printer.print((0, 0), lines[i]);
|
||||
/// });
|
||||
/// ```
|
||||
pub fn draw<F>(&self, printer: &Printer, line_drawer: F)
|
||||
|
@ -159,7 +159,7 @@ impl<T: ViewWrapper> View for T {
|
||||
/// view: T,
|
||||
/// }
|
||||
///
|
||||
/// impl <T: View> ViewWrapper for FooView<T> {
|
||||
/// impl<T: View> ViewWrapper for FooView<T> {
|
||||
/// cursive_core::wrap_impl!(self.view: T);
|
||||
/// }
|
||||
/// # fn main() { }
|
||||
@ -212,7 +212,7 @@ macro_rules! wrap_impl {
|
||||
/// cursive_core::inner_getters!(self.view: T);
|
||||
/// }
|
||||
///
|
||||
/// impl <T: View> ViewWrapper for FooView<T> {
|
||||
/// impl<T: View> ViewWrapper for FooView<T> {
|
||||
/// cursive_core::wrap_impl!(self.view: T);
|
||||
/// }
|
||||
/// # fn main() { }
|
||||
|
@ -16,35 +16,31 @@ type CallOnAny<T> = Box<dyn for<'a> FnMut(&mut T, &Selector, AnyCb<'a>)>;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// use cursive_core::views::{Canvas, Dialog};
|
||||
/// use cursive_core::event::{Event, EventResult, Key};
|
||||
/// use cursive_core::views::{Canvas, Dialog};
|
||||
/// use unicode_width::UnicodeWidthStr; // To get the width of some text.
|
||||
///
|
||||
/// // Build a canvas around a string.
|
||||
/// let state = String::new();
|
||||
/// let canvas = Canvas::new(state)
|
||||
/// .with_draw(|text: &String, printer| {
|
||||
/// // Simply print our string
|
||||
/// printer.print((0,0), text);
|
||||
/// })
|
||||
/// .with_on_event(|text: &mut String, event| {
|
||||
/// match event {
|
||||
/// Event::Char(c) => {
|
||||
/// text.push(c);
|
||||
/// EventResult::Consumed(None)
|
||||
/// }
|
||||
/// Event::Key(Key::Enter) => {
|
||||
/// let text = text.clone();
|
||||
/// EventResult::with_cb(move |s| {
|
||||
/// s.add_layer(Dialog::info(&text));
|
||||
/// })
|
||||
/// },
|
||||
/// _ => EventResult::Ignored,
|
||||
/// }
|
||||
/// })
|
||||
/// .with_required_size(|text, _constraints| {
|
||||
/// (text.width(), 1).into()
|
||||
/// });
|
||||
/// .with_draw(|text: &String, printer| {
|
||||
/// // Simply print our string
|
||||
/// printer.print((0, 0), text);
|
||||
/// })
|
||||
/// .with_on_event(|text: &mut String, event| match event {
|
||||
/// Event::Char(c) => {
|
||||
/// text.push(c);
|
||||
/// EventResult::Consumed(None)
|
||||
/// }
|
||||
/// Event::Key(Key::Enter) => {
|
||||
/// let text = text.clone();
|
||||
/// EventResult::with_cb(move |s| {
|
||||
/// s.add_layer(Dialog::info(&text));
|
||||
/// })
|
||||
/// }
|
||||
/// _ => EventResult::Ignored,
|
||||
/// })
|
||||
/// .with_required_size(|text, _constraints| (text.width(), 1).into());
|
||||
/// ```
|
||||
pub struct Canvas<T> {
|
||||
state: T,
|
||||
|
@ -13,8 +13,8 @@ use std::rc::Rc;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use cursive_core::views::Checkbox;
|
||||
/// use cursive_core::traits::Identifiable;
|
||||
/// use cursive_core::views::Checkbox;
|
||||
///
|
||||
/// let checkbox = Checkbox::new().checked().with_name("check");
|
||||
/// ```
|
||||
|
@ -45,8 +45,8 @@ impl ChildButton {
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive_core::views::{Dialog,TextView};
|
||||
/// let dialog = Dialog::around(TextView::new("Hello!"))
|
||||
/// .button("Ok", |s| s.quit());
|
||||
/// let dialog =
|
||||
/// Dialog::around(TextView::new("Hello!")).button("Ok", |s| s.quit());
|
||||
/// ```
|
||||
pub struct Dialog {
|
||||
// Possibly empty title.
|
||||
@ -113,8 +113,8 @@ impl Dialog {
|
||||
/// use cursive_core::views::{Dialog, TextView};
|
||||
///
|
||||
/// let dialog = Dialog::new()
|
||||
/// .content(TextView::new("Hello!"))
|
||||
/// .button("Quit", |s| s.quit());
|
||||
/// .content(TextView::new("Hello!"))
|
||||
/// .button("Quit", |s| s.quit());
|
||||
/// ```
|
||||
pub fn content<V: IntoBoxedView>(self, view: V) -> Self {
|
||||
self.with(|s| s.set_content(view))
|
||||
@ -125,10 +125,8 @@ impl Dialog {
|
||||
/// ```
|
||||
/// use cursive_core::views::{Dialog, TextView};
|
||||
/// let dialog = Dialog::around(TextView::new("Hello!"));
|
||||
/// let text_view: &TextView = dialog
|
||||
/// .get_content()
|
||||
/// .downcast_ref::<TextView>()
|
||||
/// .unwrap();
|
||||
/// let text_view: &TextView =
|
||||
/// dialog.get_content().downcast_ref::<TextView>().unwrap();
|
||||
/// assert_eq!(text_view.get_content().source(), "Hello!");
|
||||
/// ```
|
||||
pub fn get_content(&self) -> &dyn View {
|
||||
@ -146,8 +144,8 @@ impl Dialog {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use cursive_core::views::{Dialog, TextView};
|
||||
/// use cursive_core::view::View;
|
||||
/// use cursive_core::views::{Dialog, TextView};
|
||||
///
|
||||
/// let dialog = Dialog::around(TextView::new("abc"));
|
||||
///
|
||||
@ -176,8 +174,7 @@ impl Dialog {
|
||||
/// ```
|
||||
/// use cursive_core::views::Dialog;
|
||||
///
|
||||
/// let dialog = Dialog::text("Hello!")
|
||||
/// .button("Quit", |s| s.quit());
|
||||
/// let dialog = Dialog::text("Hello!").button("Quit", |s| s.quit());
|
||||
/// ```
|
||||
pub fn text<S: Into<StyledString>>(text: S) -> Self {
|
||||
Self::around(TextView::new(text))
|
||||
@ -267,8 +264,7 @@ impl Dialog {
|
||||
/// ```
|
||||
/// use cursive_core::views::Dialog;
|
||||
///
|
||||
/// let dialog = Dialog::text("Hello!")
|
||||
/// .dismiss_button("Close");
|
||||
/// let dialog = Dialog::text("Hello!").dismiss_button("Close");
|
||||
/// ```
|
||||
pub fn dismiss_button<S: Into<String>>(self, label: S) -> Self {
|
||||
self.button(label, |s| {
|
||||
@ -285,8 +281,7 @@ impl Dialog {
|
||||
/// ```
|
||||
/// use cursive_core::views::Dialog;
|
||||
///
|
||||
/// let dialog = Dialog::info("Some info")
|
||||
/// .title("Read me!");
|
||||
/// let dialog = Dialog::info("Some info").title("Read me!");
|
||||
/// ```
|
||||
pub fn title<S: Into<String>>(self, label: S) -> Self {
|
||||
self.with(|s| s.set_title(label))
|
||||
|
@ -50,10 +50,11 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
||||
/// .fixed_width(20),
|
||||
/// )
|
||||
/// .button("Ok", |s| {
|
||||
/// let name = s.call_on_name(
|
||||
/// "name",
|
||||
/// |view: &mut EditView| view.get_content(),
|
||||
/// ).unwrap();
|
||||
/// let name = s
|
||||
/// .call_on_name("name", |view: &mut EditView| {
|
||||
/// view.get_content()
|
||||
/// })
|
||||
/// .unwrap();
|
||||
/// show_popup(s, &name);
|
||||
/// }),
|
||||
/// );
|
||||
@ -64,8 +65,10 @@ pub type OnSubmit = dyn Fn(&mut Cursive, &str);
|
||||
/// } else {
|
||||
/// let content = format!("Hello {}!", name);
|
||||
/// s.pop_layer();
|
||||
/// s.add_layer(Dialog::around(TextView::new(content))
|
||||
/// .button("Quit", |s| s.quit()));
|
||||
/// s.add_layer(
|
||||
/// Dialog::around(TextView::new(content))
|
||||
/// .button("Quit", |s| s.quit()),
|
||||
/// );
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@ -253,15 +256,14 @@ impl EditView {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use cursive_core::views::{TextContent, TextView, EditView};
|
||||
/// use cursive_core::views::{EditView, TextContent, TextView};
|
||||
/// // Keep the length of the text in a separate view.
|
||||
/// let mut content = TextContent::new("0");
|
||||
/// let text_view = TextView::new_with_content(content.clone());
|
||||
///
|
||||
/// let on_edit = EditView::new()
|
||||
/// .on_edit(move |_s, text, _cursor| {
|
||||
/// content.set_content(format!("{}", text.len()));
|
||||
/// });
|
||||
/// let on_edit = EditView::new().on_edit(move |_s, text, _cursor| {
|
||||
/// content.set_content(format!("{}", text.len()));
|
||||
/// });
|
||||
/// ```
|
||||
pub fn on_edit<F>(self, callback: F) -> Self
|
||||
where
|
||||
@ -329,10 +331,9 @@ impl EditView {
|
||||
/// ```
|
||||
/// use cursive_core::views::{Dialog, EditView};
|
||||
///
|
||||
/// let edit_view = EditView::new()
|
||||
/// .on_submit(|s, text| {
|
||||
/// s.add_layer(Dialog::info(text));
|
||||
/// });
|
||||
/// let edit_view = EditView::new().on_submit(|s, text| {
|
||||
/// s.add_layer(Dialog::info(text));
|
||||
/// });
|
||||
/// ```
|
||||
pub fn on_submit<F>(self, callback: F) -> Self
|
||||
where
|
||||
|
@ -14,16 +14,19 @@ use crate::{
|
||||
///
|
||||
/// ```rust
|
||||
/// use cursive_core::{
|
||||
/// views::{FixedLayout, TextView, Button},
|
||||
/// views::{Button, FixedLayout, TextView},
|
||||
/// Rect,
|
||||
/// };
|
||||
///
|
||||
/// let layout = FixedLayout::new()
|
||||
/// .child(Rect::from_size((0,0), (1,1)), TextView::new("/"))
|
||||
/// .child(Rect::from_size((14,0), (1,1)), TextView::new(r"\"))
|
||||
/// .child(Rect::from_size((0,2), (1,1)), TextView::new(r"\"))
|
||||
/// .child(Rect::from_size((14,2), (1,1)), TextView::new("/"))
|
||||
/// .child(Rect::from_size((3,1), (11,1)), Button::new("Clickme", |s| s.quit()));
|
||||
/// .child(Rect::from_size((0, 0), (1, 1)), TextView::new("/"))
|
||||
/// .child(Rect::from_size((14, 0), (1, 1)), TextView::new(r"\"))
|
||||
/// .child(Rect::from_size((0, 2), (1, 1)), TextView::new(r"\"))
|
||||
/// .child(Rect::from_size((14, 2), (1, 1)), TextView::new("/"))
|
||||
/// .child(
|
||||
/// Rect::from_size((3, 1), (11, 1)),
|
||||
/// Button::new("Clickme", |s| s.quit()),
|
||||
/// );
|
||||
/// ```
|
||||
pub struct FixedLayout {
|
||||
children: Vec<Child>,
|
||||
|
@ -15,8 +15,8 @@ use std::ops::Deref;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use cursive_core::views::{Button, LinearLayout, TextView, TextArea};
|
||||
/// use cursive_core::traits::Boxable;
|
||||
/// use cursive_core::views::{Button, LinearLayout, TextArea, TextView};
|
||||
///
|
||||
/// let linear_layout = LinearLayout::horizontal()
|
||||
/// .child(TextView::new("Top of the page"))
|
||||
|
@ -35,8 +35,8 @@ use std::rc::Rc;
|
||||
/// # use cursive_core::event;;
|
||||
/// # use cursive_core::views::{OnEventView, TextView};
|
||||
/// let view = OnEventView::new(TextView::new("This view has an event!"))
|
||||
/// .on_event('q', |s| s.quit())
|
||||
/// .on_event(event::Key::Esc, |s| s.quit());
|
||||
/// .on_event('q', |s| s.quit())
|
||||
/// .on_event(event::Key::Esc, |s| s.quit());
|
||||
/// ```
|
||||
pub struct OnEventView<T> {
|
||||
view: T,
|
||||
|
@ -12,7 +12,10 @@ impl<V> OnLayoutView<V> {
|
||||
/// Will run the given closure for layout _instead_ of the one from `view`.
|
||||
///
|
||||
/// ```rust
|
||||
/// use cursive_core::{View, views::{TextView, OnLayoutView}};
|
||||
/// use cursive_core::{
|
||||
/// views::{OnLayoutView, TextView},
|
||||
/// View,
|
||||
/// };
|
||||
///
|
||||
/// let view = TextView::new("foo");
|
||||
///
|
||||
|
@ -15,10 +15,9 @@ use crate::Vec2;
|
||||
/// ```rust
|
||||
/// # use cursive_core::views::{TextView, PaddedView};
|
||||
/// // Adds 2 columns of padding to the left and to the right.
|
||||
/// let view = PaddedView::lrtb(
|
||||
/// 2,2,0,0, // Left, Right, Top, Bottom
|
||||
/// TextView::new("Padded text")
|
||||
/// );
|
||||
///
|
||||
/// // lrtb = Left, Right, Top, Bottom
|
||||
/// let view = PaddedView::lrtb(2, 2, 0, 0, TextView::new("Padded text"));
|
||||
/// ```
|
||||
pub struct PaddedView<V> {
|
||||
view: V,
|
||||
|
@ -24,15 +24,14 @@ use std::thread;
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive_core::views::ProgressBar;
|
||||
/// let bar = ProgressBar::new()
|
||||
/// .with_task(|counter| {
|
||||
/// // This closure is called in parallel.
|
||||
/// for _ in 0..100 {
|
||||
/// // Here we can communicate some
|
||||
/// // advancement back to the bar.
|
||||
/// counter.tick(1);
|
||||
/// }
|
||||
/// });
|
||||
/// let bar = ProgressBar::new().with_task(|counter| {
|
||||
/// // This closure is called in parallel.
|
||||
/// for _ in 0..100 {
|
||||
/// // Here we can communicate some
|
||||
/// // advancement back to the bar.
|
||||
/// counter.tick(1);
|
||||
/// }
|
||||
/// });
|
||||
/// ```
|
||||
pub struct ProgressBar {
|
||||
min: usize,
|
||||
|
@ -120,7 +120,6 @@ impl RadioGroup<String> {
|
||||
///
|
||||
/// `RadioButton`s are not created directly, but through
|
||||
/// [`RadioGroup::button`].
|
||||
///
|
||||
pub struct RadioButton<T> {
|
||||
state: Rc<RefCell<SharedState<T>>>,
|
||||
id: usize,
|
||||
|
@ -19,7 +19,7 @@ use crate::XY;
|
||||
/// use cursive_core::views::{ResizedView, TextView};
|
||||
///
|
||||
/// // Creates a 20x4 ResizedView with a TextView content.
|
||||
/// let view = ResizedView::with_fixed_size((20,4), TextView::new("Hello!"));
|
||||
/// let view = ResizedView::with_fixed_size((20, 4), TextView::new("Hello!"));
|
||||
/// ```
|
||||
///
|
||||
/// See also [`Boxable`](crate::view::Boxable) for an easy way to wrap any view.
|
||||
|
@ -36,13 +36,13 @@ use std::rc::Rc;
|
||||
/// time_select.set_on_submit(|s, time| {
|
||||
/// s.pop_layer();
|
||||
/// let text = format!("You will wait for {} minutes...", time);
|
||||
/// s.add_layer(Dialog::around(TextView::new(text))
|
||||
/// .button("Quit", |s| s.quit()));
|
||||
/// s.add_layer(
|
||||
/// Dialog::around(TextView::new(text)).button("Quit", |s| s.quit()),
|
||||
/// );
|
||||
/// });
|
||||
///
|
||||
/// let mut siv = Cursive::new();
|
||||
/// siv.add_layer(Dialog::around(time_select)
|
||||
/// .title("How long is your wait?"));
|
||||
/// 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
|
||||
@ -149,7 +149,7 @@ impl<T: 'static> SelectView<T> {
|
||||
///
|
||||
/// ```
|
||||
/// use cursive_core::traits::Identifiable;
|
||||
/// use cursive_core::views::{TextView, SelectView};
|
||||
/// use cursive_core::views::{SelectView, TextView};
|
||||
///
|
||||
/// let text_view = TextView::new("").with_name("text");
|
||||
///
|
||||
@ -166,7 +166,8 @@ impl<T: 'static> SelectView<T> {
|
||||
/// // Update the textview with the currently selected item.
|
||||
/// s.call_on_name("text", |v: &mut TextView| {
|
||||
/// v.set_content(content);
|
||||
/// }).unwrap();
|
||||
/// })
|
||||
/// .unwrap();
|
||||
/// });
|
||||
/// ```
|
||||
pub fn on_select<F>(self, cb: F) -> Self
|
||||
@ -298,10 +299,9 @@ impl<T: 'static> SelectView<T> {
|
||||
/// Gets an item at given idx or None.
|
||||
///
|
||||
/// ```
|
||||
/// use cursive_core::Cursive;
|
||||
/// use cursive_core::views::{SelectView, TextView};
|
||||
/// let select = SelectView::new()
|
||||
/// .item("Short", 1);
|
||||
/// use cursive_core::Cursive;
|
||||
/// let select = SelectView::new().item("Short", 1);
|
||||
/// assert_eq!(select.get_item(0), Some(("Short", &1)));
|
||||
/// ```
|
||||
pub fn get_item(&self, i: usize) -> Option<(&str, &T)> {
|
||||
@ -430,9 +430,7 @@ impl<T: 'static> SelectView<T> {
|
||||
///
|
||||
/// // Create a SelectView with 100 items
|
||||
/// let select_view = SelectView::new()
|
||||
/// .with_all((1u8..100).into_iter().map(|i| {
|
||||
/// (format!("Item {}", i), i)
|
||||
/// }));
|
||||
/// .with_all((1u8..100).into_iter().map(|i| (format!("Item {}", i), i)));
|
||||
/// ```
|
||||
pub fn with_all<S, I>(self, iter: I) -> Self
|
||||
where
|
||||
@ -845,8 +843,7 @@ impl SelectView<String> {
|
||||
///
|
||||
/// let text = "..."; // Maybe read some config file
|
||||
///
|
||||
/// let select_view = SelectView::new()
|
||||
/// .with_all_str(text.lines());
|
||||
/// let select_view = SelectView::new().with_all_str(text.lines());
|
||||
/// ```
|
||||
pub fn with_all_str<S, I>(self, iter: I) -> Self
|
||||
where
|
||||
|
@ -17,8 +17,10 @@ use std::rc::Rc;
|
||||
/// use cursive_core::views::{Dialog, SliderView};
|
||||
///
|
||||
/// let slider_view = SliderView::horizontal(10)
|
||||
/// .on_change(|s, n| if n == 5 {
|
||||
/// s.add_layer(Dialog::info("5! Pick 5!"));
|
||||
/// .on_change(|s, n| {
|
||||
/// if n == 5 {
|
||||
/// s.add_layer(Dialog::info("5! Pick 5!"));
|
||||
/// }
|
||||
/// })
|
||||
/// .on_enter(|s, n| match n {
|
||||
/// 5 => s.add_layer(Dialog::info("You did it!")),
|
||||
|
@ -21,7 +21,7 @@ use unicode_width::UnicodeWidthStr;
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// use cursive_core::traits::{Resizable, Identifiable};
|
||||
/// use cursive_core::traits::{Identifiable, Resizable};
|
||||
/// use cursive_core::views::TextArea;
|
||||
///
|
||||
/// let text_area = TextArea::new()
|
||||
|
@ -88,7 +88,6 @@ impl<T> XY<T> {
|
||||
/// let cond = XY::new(true, false);
|
||||
///
|
||||
/// assert_eq!(xy.map_if(cond, |v| v * 3), XY::new(3, 2));
|
||||
///
|
||||
/// ```
|
||||
pub fn map_if<F>(self, condition: XY<bool>, f: F) -> Self
|
||||
where
|
||||
@ -305,8 +304,8 @@ impl<T> XY<T> {
|
||||
/// let d = XY::new(vec![1], vec![2, 3, 4]);
|
||||
/// let e = XY::new('a', 'b');
|
||||
///
|
||||
/// let xy: XY<Option<char>> = XY::zip5(a, b, c, d, e)
|
||||
/// .map(|(a, b, c, d, e)| {
|
||||
/// let xy: XY<Option<char>> =
|
||||
/// XY::zip5(a, b, c, d, e).map(|(a, b, c, d, e)| {
|
||||
/// if b && d.contains(&a) {
|
||||
/// Some(e)
|
||||
/// } else {
|
||||
|
10
rustfmt.toml
10
rustfmt.toml
@ -1,3 +1,9 @@
|
||||
max_width = 79
|
||||
reorder_imports = true
|
||||
edition = "2018"
|
||||
fn_args_layout = "Tall"
|
||||
format_code_in_doc_comments = true
|
||||
max_width = 79
|
||||
merge_derives = true
|
||||
reorder_imports = true
|
||||
reorder_modules = true
|
||||
use_field_init_shorthand = true
|
||||
use_try_shorthand = true
|
||||
|
Loading…
Reference in New Issue
Block a user