mirror of
https://github.com/FliegendeWurst/cursive.git
synced 2024-11-23 09:25:01 +00:00
Rename Dialog::new
-> Dialog::around
And `Dialog::empty` -> `Dialog::new`
This commit is contained in:
parent
53aea8e91c
commit
8fa704bcfa
@ -37,7 +37,7 @@ fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
// Creates a dialog with a single "Quit" button
|
||||
siv.add_layer(Dialog::new(TextView::new("Hello Dialog!"))
|
||||
siv.add_layer(Dialog::around(TextView::new("Hello Dialog!"))
|
||||
.title("Cursive")
|
||||
.button("Quit", |s| s.quit()));
|
||||
|
||||
|
@ -63,7 +63,7 @@ Instead of directly using a [`TextView`], we'll use a [`Dialog`] this time.
|
||||
A dialog is wrapper with a frame around another view, and optionally a title
|
||||
and/or buttons.
|
||||
|
||||
[`Dialog::new`] directly takes a view, so we'll directly give it the
|
||||
[`Dialog::around`] directly takes a view, so we'll directly give it the
|
||||
`TextView`:
|
||||
|
||||
```rust,no_run
|
||||
@ -76,7 +76,7 @@ use cursive::views::TextView;
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
siv.add_layer(Dialog::new(TextView::new("...")));
|
||||
siv.add_layer(Dialog::around(TextView::new("...")));
|
||||
|
||||
siv.run();
|
||||
}
|
||||
@ -105,7 +105,7 @@ and configuring it in one spot.
|
||||
|
||||
[`TextView`]: http://gyscos.github.io/Cursive/cursive/views/struct.TextView
|
||||
[`Dialog`]: http://gyscos.github.io/Cursive/cursive/views/struct.Dialog.html
|
||||
[`Dialog::new`]: http://gyscos.github.io/Cursive/cursive/views/struct.Dialog.html#method.new
|
||||
[`Dialog::around`]: http://gyscos.github.io/Cursive/cursive/views/struct.Dialog.html#method.around
|
||||
[`Dialog::text`]: http://gyscos.github.io/Cursive/cursive/views/struct.Dialog.html#method.text
|
||||
[`Dialog::title`]: http://gyscos.github.io/Cursive/cursive/views/struct.Dialog.html#method.title
|
||||
|
||||
|
@ -29,7 +29,7 @@ fn main() {
|
||||
.child(DummyView)
|
||||
.child(Button::new("Quit", Cursive::quit));
|
||||
|
||||
siv.add_layer(Dialog::new(LinearLayout::horizontal()
|
||||
siv.add_layer(Dialog::around(LinearLayout::horizontal()
|
||||
.child(select)
|
||||
.child(DummyView)
|
||||
.child(buttons))
|
||||
@ -44,7 +44,7 @@ fn add_name(s: &mut Cursive) {
|
||||
s.pop_layer();
|
||||
}
|
||||
|
||||
s.add_layer(Dialog::new(EditView::new()
|
||||
s.add_layer(Dialog::around(EditView::new()
|
||||
.on_submit(ok)
|
||||
.with_id("name")
|
||||
.fixed_width(10))
|
||||
@ -145,7 +145,7 @@ replace the layer with a simple dialog.
|
||||
|
||||
Our main screen is more complex than our previous examples: it is made of
|
||||
several views. There is a `SelectView` on the left, and three [`Button`]s to
|
||||
the right. But our [`Dialog::new`] method only takes one view! How will we do?
|
||||
the right. But our [`Dialog::around`] method only takes one view! How will we do?
|
||||
|
||||
The solution is to use a layout view to display multiple children side-by-side.
|
||||
[`LinearLayout`] for instance can display views in a line.
|
||||
@ -174,7 +174,7 @@ as a cheap spacer.
|
||||
We can now create the second linear layout inside a Dialog:
|
||||
|
||||
```rust,ignore
|
||||
siv.add_layer(Dialog::new(LinearLayout::horizontal()
|
||||
siv.add_layer(Dialog::around(LinearLayout::horizontal()
|
||||
.child(select)
|
||||
.child(DummyView)
|
||||
.child(buttons))
|
||||
@ -186,7 +186,7 @@ buttons. Though with an empty list, it doesn't look like much yet. Let's fill
|
||||
this list with names!
|
||||
|
||||
[`Button`]: http://gyscos.github.io/Cursive/cursive/views/struct.Button.html
|
||||
[`Dialog::new`]: http://gyscos.github.io/Cursive/cursive/views/struct.Dialog.html#method.new
|
||||
[`Dialog::around`]: http://gyscos.github.io/Cursive/cursive/views/struct.Dialog.html#method.new
|
||||
[`LinearLayout`]: http://gyscos.github.io/Cursive/cursive/views/struct.LinearLayout.html
|
||||
[`DummyView`]: http://gyscos.github.io/Cursive/cursive/views/struct.DummyView.html
|
||||
|
||||
@ -197,7 +197,7 @@ can enter a new name:
|
||||
|
||||
```rust,ignore
|
||||
fn add_name(s: &mut Cursive) {
|
||||
s.add_layer(Dialog::new(EditView::new()
|
||||
s.add_layer(Dialog::around(EditView::new()
|
||||
.fixed_width(10))
|
||||
.title("Enter a new name")
|
||||
.button("Ok", |s| {
|
||||
@ -231,7 +231,7 @@ Here's what it looks like in action:
|
||||
|
||||
```rust,ignore
|
||||
fn add_name(s: &mut Cursive) {
|
||||
s.add_layer(Dialog::new(EditView::new()
|
||||
s.add_layer(Dialog::around(EditView::new()
|
||||
.with_id("name")
|
||||
.fixed_width(10))
|
||||
.title("Enter a new name")
|
||||
@ -267,7 +267,7 @@ fn add_name(s: &mut Cursive) {
|
||||
s.pop_layer();
|
||||
}
|
||||
|
||||
s.add_layer(Dialog::new(EditView::new()
|
||||
s.add_layer(Dialog::around(EditView::new()
|
||||
.on_submit(ok)
|
||||
.with_id("name")
|
||||
.fixed_width(10))
|
||||
@ -304,7 +304,7 @@ when we try to add a new layer - one of the quirks of the borrow checker.
|
||||
|
||||
[`EditView`]: http://gyscos.github.io/Cursive/cursive/views/struct.EditView.html
|
||||
[`IdView`]: http://gyscos.github.io/Cursive/cursive/views/struct.IdView.html
|
||||
[`IdView::new`]: http://gyscos.github.io/Cursive/cursive/prelude/struct.IdView.html#method.new
|
||||
[`IdView::new`]: http://gyscos.github.io/Cursive/cursive/prelude/struct.IdView.html#method.around
|
||||
[`Identifiable`]: http://gyscos.github.io/Cursive/cursive/view/trait.Identifiable.html
|
||||
[`Cursive::find_id`]: http://gyscos.github.io/Cursive/cursive/struct.Cursive.html#method.find_id
|
||||
[`SelectView::selected_id`]: http://gyscos.github.io/Cursive/cursive/views/struct.SelectView.html#method.selected_id
|
||||
|
@ -8,7 +8,7 @@ fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
// Creates a dialog with a single "Quit" button
|
||||
siv.add_layer(Dialog::new(TextView::new("Hello Dialog!"))
|
||||
siv.add_layer(Dialog::around(TextView::new("Hello Dialog!"))
|
||||
.title("Cursive")
|
||||
.button("Quit", |s| s.quit()));
|
||||
|
||||
|
@ -10,7 +10,7 @@ fn main() {
|
||||
// Create a dialog with an edit text and a button.
|
||||
// The user can either hit the <Ok> button,
|
||||
// or press Enter on the edit text.
|
||||
siv.add_layer(Dialog::empty()
|
||||
siv.add_layer(Dialog::new()
|
||||
.title("Enter your name")
|
||||
.padding((1, 1, 1, 0))
|
||||
.content(EditView::new()
|
||||
@ -33,7 +33,7 @@ fn show_popup(s: &mut Cursive, name: &str) {
|
||||
} else {
|
||||
let content = format!("Hello {}!", name);
|
||||
s.pop_layer();
|
||||
s.add_layer(Dialog::new(TextView::new(content))
|
||||
s.add_layer(Dialog::around(TextView::new(content))
|
||||
.button("Quit", |s| s.quit()));
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ fn main() {
|
||||
has a fixed width, and the title is centered horizontally.";
|
||||
|
||||
// We'll create a dialog with a TextView serving as a title
|
||||
siv.add_layer(Dialog::new(LinearLayout::vertical()
|
||||
siv.add_layer(Dialog::around(LinearLayout::vertical()
|
||||
.child(TextView::new("Title").h_align(HAlign::Center))
|
||||
// Box the textview, so it doesn't get too wide.
|
||||
// A 0 height value means it will be unconstrained.
|
||||
|
@ -8,7 +8,7 @@ use cursive::traits::*;
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
siv.add_layer(Dialog::empty()
|
||||
siv.add_layer(Dialog::new()
|
||||
.title("Please fill out this form")
|
||||
.button("Ok", |s| s.quit())
|
||||
.content(ListView::new()
|
||||
|
@ -15,7 +15,7 @@ fn main() {
|
||||
|
||||
// The text is too long to fit on a line, so the view will wrap lines,
|
||||
// and will adapt to the terminal size.
|
||||
siv.add_layer(Dialog::new(TextView::new(content))
|
||||
siv.add_layer(Dialog::around(TextView::new(content))
|
||||
.h_align(HAlign::Center)
|
||||
.button("Quit", |s| s.quit()));
|
||||
// Show a popup on top of the view.
|
||||
|
@ -47,7 +47,7 @@ fn main() {
|
||||
|
||||
siv.add_global_callback(Key::Esc, |s| s.select_menubar());
|
||||
|
||||
siv.add_layer(Dialog::new(TextView::new("Hit <Esc> to show the menu!")));
|
||||
siv.add_layer(Dialog::around(TextView::new("Hit <Esc> to show the menu!")));
|
||||
|
||||
siv.run();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ fn show_popup(siv: &mut Cursive) {
|
||||
// Let's center the popup horizontally, but offset it down a few rows
|
||||
siv.screen_mut()
|
||||
.add_layer_at(Position::new(Offset::Center, Offset::Parent(3)),
|
||||
Dialog::new(TextView::new("Tak!"))
|
||||
Dialog::around(TextView::new("Tak!"))
|
||||
.button("Change", |s| {
|
||||
// Look for a view tagged "text". We _know_ it's there, so unwrap it.
|
||||
let view = s.find_id::<TextView>("text").unwrap();
|
||||
|
@ -16,7 +16,7 @@ fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
// We'll start slowly with a simple start button...
|
||||
siv.add_layer(Dialog::empty()
|
||||
siv.add_layer(Dialog::new()
|
||||
.title("Progress bar example")
|
||||
.padding((0, 0, 1, 1))
|
||||
.content(Button::new("Start", phase_1)));
|
||||
@ -46,7 +46,7 @@ fn phase_1(s: &mut Cursive) {
|
||||
let cb = s.cb_sink().clone();
|
||||
|
||||
s.pop_layer();
|
||||
s.add_layer(Dialog::new(ProgressBar::new()
|
||||
s.add_layer(Dialog::around(ProgressBar::new()
|
||||
.range(0, n_max)
|
||||
.with_task(move |counter| {
|
||||
// This closure will be called in a separate thread.
|
||||
@ -61,7 +61,7 @@ fn phase_1(s: &mut Cursive) {
|
||||
fn coffee_break(s: &mut Cursive) {
|
||||
// A little break before things get serious.
|
||||
s.pop_layer();
|
||||
s.add_layer(Dialog::empty()
|
||||
s.add_layer(Dialog::new()
|
||||
.title("Preparation complete")
|
||||
.content(TextView::new("Now, the real deal!").center())
|
||||
.button("Again??", phase_2));
|
||||
@ -90,7 +90,7 @@ fn phase_2(s: &mut Cursive) {
|
||||
}
|
||||
|
||||
s.pop_layer();
|
||||
s.add_layer(Dialog::new(linear.full_width()).title("Just a moment..."));
|
||||
s.add_layer(Dialog::around(linear.full_width()).title("Just a moment..."));
|
||||
|
||||
// And we start the worker thread.
|
||||
thread::spawn(move || {
|
||||
@ -116,7 +116,7 @@ fn phase_2(s: &mut Cursive) {
|
||||
fn final_step(s: &mut Cursive) {
|
||||
// A little break before things get serious.
|
||||
s.pop_layer();
|
||||
s.add_layer(Dialog::empty()
|
||||
s.add_layer(Dialog::new()
|
||||
.title("Report")
|
||||
.content(TextView::new("Time travel was a success!\n\
|
||||
We went forward a few seconds!!")
|
||||
|
@ -10,7 +10,7 @@ fn main() {
|
||||
let mut color_group: RadioGroup<String> = RadioGroup::new();
|
||||
let mut size_group: RadioGroup<u32> = RadioGroup::new();
|
||||
|
||||
siv.add_layer(Dialog::empty()
|
||||
siv.add_layer(Dialog::new()
|
||||
.title("Make your selection")
|
||||
// We'll have two columns side-by-side
|
||||
.content(LinearLayout::horizontal()
|
||||
|
@ -19,7 +19,7 @@ fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
// Let's add a BoxView to keep the list at a reasonable size - it can scroll anyway.
|
||||
siv.add_layer(Dialog::new(select.fixed_size((20, 10)))
|
||||
siv.add_layer(Dialog::around(select.fixed_size((20, 10)))
|
||||
.title("Where are you from?"));
|
||||
|
||||
siv.run();
|
||||
@ -29,6 +29,6 @@ fn main() {
|
||||
fn show_next_window(siv: &mut Cursive, city: &str) {
|
||||
siv.pop_layer();
|
||||
let text = format!("{} is a great city!", city);
|
||||
siv.add_layer(Dialog::new(TextView::new(text))
|
||||
siv.add_layer(Dialog::around(TextView::new(text))
|
||||
.button("Quit", |s| s.quit()));
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ fn main() {
|
||||
// Let's add a simple slider in a dialog.
|
||||
// Moving the slider will update the dialog's title.
|
||||
// And pressing "Enter" will show a new dialog.
|
||||
siv.add_layer(Dialog::new(SliderView::horizontal(15)
|
||||
siv.add_layer(Dialog::around(SliderView::horizontal(15)
|
||||
.value(7)
|
||||
.on_change(|s, v| {
|
||||
let title = format!("[ {} ]", v);
|
||||
|
@ -7,7 +7,7 @@ use cursive::traits::*;
|
||||
fn main() {
|
||||
let mut siv = Cursive::new();
|
||||
|
||||
siv.add_layer(Dialog::empty()
|
||||
siv.add_layer(Dialog::new()
|
||||
.title("Describe your issue")
|
||||
.padding((1, 1, 1, 0))
|
||||
.content(TextArea::new()
|
||||
|
@ -11,7 +11,7 @@ fn main() {
|
||||
// Or you can directly load it from a string for easy deployment.
|
||||
// siv.load_theme(include_str!("../assets/style.toml")).unwrap();
|
||||
|
||||
siv.add_layer(Dialog::new(TextView::new("This application uses a \
|
||||
siv.add_layer(Dialog::around(TextView::new("This application uses a \
|
||||
custom theme!"))
|
||||
.title("Themed dialog")
|
||||
.button("Quit", |s| s.quit()));
|
||||
|
@ -26,7 +26,7 @@ enum Focus {
|
||||
///
|
||||
/// ```
|
||||
/// # use cursive::views::{Dialog,TextView};
|
||||
/// let dialog = Dialog::new(TextView::new("Hello!"))
|
||||
/// let dialog = Dialog::around(TextView::new("Hello!"))
|
||||
/// .button("Ok", |s| s.quit());
|
||||
/// ```
|
||||
pub struct Dialog {
|
||||
@ -47,12 +47,12 @@ impl Dialog {
|
||||
/// Creates a new `Dialog` with empty content.
|
||||
///
|
||||
/// You should probably call `content()` next.
|
||||
pub fn empty() -> Self {
|
||||
Self::new(DummyView)
|
||||
pub fn new() -> Self {
|
||||
Self::around(DummyView)
|
||||
}
|
||||
|
||||
/// Creates a new `Dialog` with the given content.
|
||||
pub fn new<V: View + 'static>(view: V) -> Self {
|
||||
pub fn around<V: View + 'static>(view: V) -> Self {
|
||||
Dialog {
|
||||
content: Box::new(view),
|
||||
buttons: Vec::new(),
|
||||
@ -80,7 +80,7 @@ impl Dialog {
|
||||
|
||||
/// Convenient method to create a dialog with a simple text content.
|
||||
pub fn text<S: Into<String>>(text: S) -> Self {
|
||||
Self::new(TextView::new(text))
|
||||
Self::around(TextView::new(text))
|
||||
}
|
||||
|
||||
/// Convenient method to create an infobox.
|
||||
|
@ -31,7 +31,7 @@ use utils::simple_suffix_length;
|
||||
/// // Create a dialog with an edit text and a button.
|
||||
/// // The user can either hit the <Ok> button,
|
||||
/// // or press Enter on the edit text.
|
||||
/// siv.add_layer(Dialog::empty()
|
||||
/// siv.add_layer(Dialog::new()
|
||||
/// .title("Enter your name")
|
||||
/// .padding((1, 1, 1, 0))
|
||||
/// .content(EditView::new()
|
||||
@ -51,7 +51,7 @@ use utils::simple_suffix_length;
|
||||
/// } else {
|
||||
/// let content = format!("Hello {}!", name);
|
||||
/// s.pop_layer();
|
||||
/// s.add_layer(Dialog::new(TextView::new(content))
|
||||
/// s.add_layer(Dialog::around(TextView::new(content))
|
||||
/// .button("Quit", |s| s.quit()));
|
||||
/// }
|
||||
/// }
|
||||
|
@ -37,12 +37,12 @@ use unicode_width::UnicodeWidthStr;
|
||||
/// time_select.set_on_submit(|s, time| {
|
||||
/// s.pop_layer();
|
||||
/// let text = format!("You will wait for {} minutes...", time);
|
||||
/// s.add_layer(Dialog::new(TextView::new(text))
|
||||
/// s.add_layer(Dialog::around(TextView::new(text))
|
||||
/// .button("Quit", |s| s.quit()));
|
||||
/// });
|
||||
///
|
||||
/// let mut siv = Cursive::new();
|
||||
/// siv.add_layer(Dialog::new(time_select)
|
||||
/// siv.add_layer(Dialog::around(time_select)
|
||||
/// .title("How long is your wait?"));
|
||||
/// # }
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user