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(
|
||||||
/// for i in 1..100 {
|
/// "Recent",
|
||||||
/// tree.add_leaf(format!("Item {}", i), |_| ())
|
/// MenuTree::new().with(|tree| {
|
||||||
/// }
|
/// for i in 1..100 {
|
||||||
/// }))
|
/// 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(
|
||||||
/// MenuTree::new()
|
/// "Help",
|
||||||
/// .leaf("General", |s| {
|
/// MenuTree::new()
|
||||||
/// s.add_layer(Dialog::info("Help message!"))
|
/// .leaf("General", |s| {
|
||||||
/// })
|
/// s.add_layer(Dialog::info("Help message!"))
|
||||||
/// .leaf("Online", |s| {
|
/// })
|
||||||
/// s.add_layer(Dialog::info("Online help?"))
|
/// .leaf("Online", |s| {
|
||||||
/// }))
|
/// 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)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ impl<'a, 'b> Printer<'a, 'b> {
|
|||||||
/// # let t = theme::load_default();
|
/// # let t = theme::load_default();
|
||||||
/// # let printer = Printer::new((6,4), &t, &*b);
|
/// # let printer = Printer::new((6,4), &t, &*b);
|
||||||
/// printer.with_color(theme::ColorStyle::highlight(), |printer| {
|
/// 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)
|
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 b = backend::Dummy::init();
|
||||||
/// # let t = theme::load_default();
|
/// # let t = theme::load_default();
|
||||||
/// # let printer = Printer::new((6,4), &t, &*b);
|
/// # 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>>(
|
pub fn print_box<T: Into<Vec2>, S: Into<Vec2>>(
|
||||||
&self,
|
&self,
|
||||||
|
@ -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(
|
||||||
/// // But here we mutate the environment! Crazy!
|
/// 'q',
|
||||||
/// i += 1;
|
/// immut1!(move |s: &mut Cursive| {
|
||||||
/// if i == 5 {
|
/// // But here we mutate the environment! Crazy!
|
||||||
/// s.quit();
|
/// i += 1;
|
||||||
/// }
|
/// if i == 5 {
|
||||||
/// }));
|
/// 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,
|
||||||
@ -66,14 +66,19 @@ impl Default for ScrollStrategy {
|
|||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn inner_important_area(&self, size: Vec2) -> Rect {
|
/// fn inner_important_area(&self, size: Vec2) -> Rect {
|
||||||
/// Rect::from_size((0,0), size)
|
/// Rect::from_size((0, 0), size)
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// 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,
|
||||||
|
@ -224,7 +224,7 @@ impl ScrollBase {
|
|||||||
/// # let printer = &printer;
|
/// # let printer = &printer;
|
||||||
/// let lines = ["Line 1", "Line number 2"];
|
/// let lines = ["Line 1", "Line number 2"];
|
||||||
/// scrollbase.draw(printer, |printer, i| {
|
/// 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)
|
pub fn draw<F>(&self, printer: &Printer, line_drawer: F)
|
||||||
|
@ -159,7 +159,7 @@ impl<T: ViewWrapper> View for T {
|
|||||||
/// view: T,
|
/// view: T,
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// impl <T: View> ViewWrapper for FooView<T> {
|
/// impl<T: View> ViewWrapper for FooView<T> {
|
||||||
/// cursive_core::wrap_impl!(self.view: T);
|
/// cursive_core::wrap_impl!(self.view: T);
|
||||||
/// }
|
/// }
|
||||||
/// # fn main() { }
|
/// # fn main() { }
|
||||||
@ -212,7 +212,7 @@ macro_rules! wrap_impl {
|
|||||||
/// cursive_core::inner_getters!(self.view: T);
|
/// 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);
|
/// cursive_core::wrap_impl!(self.view: T);
|
||||||
/// }
|
/// }
|
||||||
/// # fn main() { }
|
/// # fn main() { }
|
||||||
|
@ -16,35 +16,31 @@ 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.
|
||||||
/// let state = String::new();
|
/// let state = String::new();
|
||||||
/// let canvas = Canvas::new(state)
|
/// let canvas = Canvas::new(state)
|
||||||
/// .with_draw(|text: &String, printer| {
|
/// .with_draw(|text: &String, printer| {
|
||||||
/// // 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)
|
/// }
|
||||||
/// }
|
/// Event::Key(Key::Enter) => {
|
||||||
/// Event::Key(Key::Enter) => {
|
/// let text = text.clone();
|
||||||
/// let text = text.clone();
|
/// 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| (text.width(), 1).into());
|
||||||
/// })
|
|
||||||
/// .with_required_size(|text, _constraints| {
|
|
||||||
/// (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.
|
||||||
@ -113,8 +113,8 @@ impl Dialog {
|
|||||||
/// use cursive_core::views::{Dialog, TextView};
|
/// use cursive_core::views::{Dialog, TextView};
|
||||||
///
|
///
|
||||||
/// let dialog = Dialog::new()
|
/// let dialog = Dialog::new()
|
||||||
/// .content(TextView::new("Hello!"))
|
/// .content(TextView::new("Hello!"))
|
||||||
/// .button("Quit", |s| s.quit());
|
/// .button("Quit", |s| s.quit());
|
||||||
/// ```
|
/// ```
|
||||||
pub fn content<V: IntoBoxedView>(self, view: V) -> Self {
|
pub fn content<V: IntoBoxedView>(self, view: V) -> Self {
|
||||||
self.with(|s| s.set_content(view))
|
self.with(|s| s.set_content(view))
|
||||||
@ -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,15 +256,14 @@ 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()));
|
/// });
|
||||||
/// });
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn on_edit<F>(self, callback: F) -> Self
|
pub fn on_edit<F>(self, callback: F) -> Self
|
||||||
where
|
where
|
||||||
@ -329,10 +331,9 @@ 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));
|
/// });
|
||||||
/// });
|
|
||||||
/// ```
|
/// ```
|
||||||
pub fn on_submit<F>(self, callback: F) -> Self
|
pub fn on_submit<F>(self, callback: F) -> Self
|
||||||
where
|
where
|
||||||
|
@ -14,16 +14,19 @@ use crate::{
|
|||||||
///
|
///
|
||||||
/// ```rust
|
/// ```rust
|
||||||
/// use cursive_core::{
|
/// use cursive_core::{
|
||||||
/// views::{FixedLayout, TextView, Button},
|
/// views::{Button, FixedLayout, TextView},
|
||||||
/// Rect,
|
/// Rect,
|
||||||
/// };
|
/// };
|
||||||
///
|
///
|
||||||
/// let layout = FixedLayout::new()
|
/// let layout = FixedLayout::new()
|
||||||
/// .child(Rect::from_size((0,0), (1,1)), TextView::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((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"))
|
||||||
|
@ -35,8 +35,8 @@ use std::rc::Rc;
|
|||||||
/// # use cursive_core::event;;
|
/// # use cursive_core::event;;
|
||||||
/// # use cursive_core::views::{OnEventView, TextView};
|
/// # use cursive_core::views::{OnEventView, TextView};
|
||||||
/// let view = OnEventView::new(TextView::new("This view has an event!"))
|
/// let view = OnEventView::new(TextView::new("This view has an event!"))
|
||||||
/// .on_event('q', |s| s.quit())
|
/// .on_event('q', |s| s.quit())
|
||||||
/// .on_event(event::Key::Esc, |s| s.quit());
|
/// .on_event(event::Key::Esc, |s| s.quit());
|
||||||
/// ```
|
/// ```
|
||||||
pub struct OnEventView<T> {
|
pub struct OnEventView<T> {
|
||||||
view: T,
|
view: T,
|
||||||
|
@ -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,15 +24,14 @@ 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
|
/// // advancement back to the bar.
|
||||||
/// // advancement back to the bar.
|
/// counter.tick(1);
|
||||||
/// counter.tick(1);
|
/// }
|
||||||
/// }
|
/// });
|
||||||
/// });
|
|
||||||
/// ```
|
/// ```
|
||||||
pub struct ProgressBar {
|
pub struct ProgressBar {
|
||||||
min: usize,
|
min: usize,
|
||||||
|
@ -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,
|
||||||
|
@ -19,7 +19,7 @@ use crate::XY;
|
|||||||
/// use cursive_core::views::{ResizedView, TextView};
|
/// use cursive_core::views::{ResizedView, TextView};
|
||||||
///
|
///
|
||||||
/// // Creates a 20x4 ResizedView with a TextView content.
|
/// // 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.
|
/// 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| {
|
/// 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| {
|
||||||
/// s.add_layer(Dialog::info("5! Pick 5!"));
|
/// if n == 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