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