From e1585e176ed8a49dbb32ccd95ae70c7f3410640b Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Fri, 15 Nov 2019 11:41:05 -0800 Subject: [PATCH] Renaming: part 2 --- Cargo.toml | 1 + doc/tutorial_3.md | 6 +-- examples/colors.rs | 2 +- examples/dialog.rs | 4 +- examples/edit.rs | 13 +++---- examples/hello_world.rs | 4 +- examples/key_codes.rs | 2 +- examples/linear.rs | 18 ++++----- examples/list_view.rs | 39 ++++++++++---------- examples/logs.rs | 2 +- examples/lorem.rs | 19 +++++----- examples/markup.rs | 11 ++---- examples/mines/main.rs | 4 +- examples/mutation.rs | 8 ++-- examples/position.rs | 4 +- examples/progress.rs | 6 +-- examples/radio.rs | 6 +-- examples/refcell_view.rs | 18 ++++----- examples/scroll.rs | 3 +- examples/select.rs | 12 +++--- examples/slider.rs | 4 +- examples/tcp_server.rs | 14 +++---- examples/terminal_default.rs | 4 +- examples/text_area.rs | 20 +++++----- examples/theme.rs | 6 +-- examples/theme_manual.rs | 14 +++---- examples/vpv.rs | 2 +- src/cursive.rs | 35 +++++++++--------- src/lib.rs | 7 ++-- src/printer.rs | 2 +- src/traits.rs | 15 -------- src/{view => traits}/finder.rs | 10 +---- src/{view => traits}/identifiable.rs | 12 +++--- src/traits/mod.rs | 12 ++++++ src/{view/boxable.rs => traits/resizable.rs} | 4 +- src/{view => traits}/scrollable.rs | 0 src/{ => traits}/with.rs | 0 src/view/any.rs | 6 +-- src/view/mod.rs | 11 +----- src/view/scroll/core.rs | 2 +- src/view/selector.rs | 9 +++++ src/view/view_path.rs | 38 ++++++++----------- src/views/linear_layout.rs | 6 +-- src/views/resized.rs | 35 +++++++++--------- src/views/stack.rs | 2 +- src/views/text_area.rs | 2 +- 46 files changed, 218 insertions(+), 236 deletions(-) delete mode 100644 src/traits.rs rename src/{view => traits}/finder.rs (90%) rename src/{view => traits}/identifiable.rs (81%) create mode 100644 src/traits/mod.rs rename src/{view/boxable.rs => traits/resizable.rs} (97%) rename src/{view => traits}/scrollable.rs (100%) rename src/{ => traits}/with.rs (100%) create mode 100644 src/view/selector.rs diff --git a/Cargo.toml b/Cargo.toml index 746172d..c2c44ae 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ lazy_static = "1" chrono = "0.4.7" cfg-if = "0.1.9" ahash = "0.2.12" +stack_list = "0.1.0" [dependencies.toml] optional = true diff --git a/doc/tutorial_3.md b/doc/tutorial_3.md index 8db57ea..3475612 100644 --- a/doc/tutorial_3.md +++ b/doc/tutorial_3.md @@ -102,9 +102,9 @@ We could do: let select = BoxView::with_fixed_size((10, 5), SelectView::::new()); ``` -But there is another shorter way: the [`Boxable`] trait is conveniently +But there is another shorter way: the [`Resizable`] trait is conveniently implemented for any `View`, and allow to wrap in a `BoxView` with a chainable -call. `Boxable`, and a few other useful traits, are conveniently bundled in +call. `Resizable`, and a few other useful traits, are conveniently bundled in the [`traits`] prelude, ready to be imported: ```rust,ignore @@ -140,7 +140,7 @@ replace the layer with a simple dialog. [`SelectView`]: https://docs.rs/cursive/0/cursive/views/struct.SelectView.html [`BoxView`]: https://docs.rs/cursive/0/cursive/views/struct.BoxView.html -[`Boxable`]: https://docs.rs/cursive/0/cursive/view/trait.Boxable.html +[`Resizable`]: https://docs.rs/cursive/0/cursive/view/trait.Resizable.html [`traits`]: https://docs.rs/cursive/0/cursive/traits/index.html [`SelectView::on_submit`]: https://docs.rs/cursive/0/cursive/views/struct.SelectView.html#method.on_submit diff --git a/examples/colors.rs b/examples/colors.rs index a385f38..cfa7097 100644 --- a/examples/colors.rs +++ b/examples/colors.rs @@ -1,5 +1,5 @@ use cursive::theme::{Color, ColorStyle}; -use cursive::view::Boxable; +use cursive::traits::Resizable as _; use cursive::views::Canvas; use cursive::{Cursive, Printer}; diff --git a/examples/dialog.rs b/examples/dialog.rs index 4255112..43acccf 100644 --- a/examples/dialog.rs +++ b/examples/dialog.rs @@ -1,4 +1,4 @@ -use cursive::views::{CircularFocus, Dialog, TextView}; +use cursive::views::{CircularFocus, Dialog, Text}; use cursive::Cursive; fn main() { @@ -9,7 +9,7 @@ fn main() { siv.add_layer( // Most views can be configured in a chainable way CircularFocus::wrap_tab( - Dialog::around(TextView::new("Hello Dialog!")) + Dialog::around(Text::new("Hello Dialog!")) .title("Cursive") .button("Foo", |_s| ()) .button("Quit", |s| s.quit()), diff --git a/examples/edit.rs b/examples/edit.rs index e7429c9..0ca69fc 100644 --- a/examples/edit.rs +++ b/examples/edit.rs @@ -1,5 +1,5 @@ use cursive::traits::*; -use cursive::views::{Dialog, EditView, TextView}; +use cursive::views::{Dialog, Edit, Text}; use cursive::Cursive; fn main() { @@ -14,21 +14,21 @@ fn main() { // Padding is (left, right, top, bottom) .padding((1, 1, 1, 0)) .content( - EditView::new() + Edit::new() // Call `show_popup` when the user presses `Enter` .on_submit(show_popup) - // Give the `EditView` a name so we can refer to it later. + // Give the `Edit` a name so we can refer to it later. .with_id("name") // Wrap this in a `BoxView` with a fixed width. // Do this _after_ `with_id` or the name will point to the - // `BoxView` instead of `EditView`! + // `BoxView` instead of `Edit`! .fixed_width(20), ) .button("Ok", |s| { // This will run the given closure, *ONLY* if a view with the // correct type and the given ID is found. let name = s - .call_on_id("name", |view: &mut EditView| { + .call_on_id("name", |view: &mut Edit| { // We can return content from the closure! view.get_content() }) @@ -54,8 +54,7 @@ fn show_popup(s: &mut Cursive, name: &str) { s.pop_layer(); // And put a new one instead s.add_layer( - Dialog::around(TextView::new(content)) - .button("Quit", |s| s.quit()), + Dialog::around(Text::new(content)).button("Quit", |s| s.quit()), ); } } diff --git a/examples/hello_world.rs b/examples/hello_world.rs index 0ec8a08..4cc32ed 100644 --- a/examples/hello_world.rs +++ b/examples/hello_world.rs @@ -1,4 +1,4 @@ -use cursive::views::TextView; +use cursive::views::Text; use cursive::Cursive; fn main() { @@ -8,7 +8,7 @@ fn main() { siv.add_global_callback('q', Cursive::quit); // Add a simple view - siv.add_layer(TextView::new( + siv.add_layer(Text::new( "Hello World!\n\ Press q to quit the application.", )); diff --git a/examples/key_codes.rs b/examples/key_codes.rs index 9d876c2..69b7355 100644 --- a/examples/key_codes.rs +++ b/examples/key_codes.rs @@ -29,7 +29,7 @@ impl KeyCodeView { // Let's implement the `View` trait. // `View` contains many methods, but only a few are required. -impl View for KeyCodeView { +impl cursive::View for KeyCodeView { fn draw(&self, printer: &Printer) { // We simply draw every event from the history. for (y, line) in self.history.iter().enumerate() { diff --git a/examples/linear.rs b/examples/linear.rs index 7e61713..337895a 100644 --- a/examples/linear.rs +++ b/examples/linear.rs @@ -1,6 +1,6 @@ use cursive::align::HAlign; use cursive::traits::*; -use cursive::views::{Dialog, DummyView, LinearLayout, TextView}; +use cursive::views::{Dialog, Dummy, LinearLayout, Text}; use cursive::Cursive; // This example uses a LinearLayout to stick multiple views next to each other. @@ -13,19 +13,19 @@ fn main() { are present, a short title above, and this text. The text \ has a fixed width, and the title is centered horizontally."; - // We'll create a dialog with a TextView serving as a title + // We'll create a dialog with a Text serving as a title siv.add_layer( Dialog::around( LinearLayout::vertical() - .child(TextView::new("Title").h_align(HAlign::Center)) - // Use a DummyView as spacer - .child(DummyView.fixed_height(1)) + .child(Text::new("Title").h_align(HAlign::Center)) + // Use a Dummy as spacer + .child(Dummy.fixed_height(1)) // Disabling scrollable means the view cannot shrink. - .child(TextView::new(text)) + .child(Text::new(text)) // The other views will share the remaining space. - .child(TextView::new(text).scrollable()) - .child(TextView::new(text).scrollable()) - .child(TextView::new(text).scrollable()) + .child(Text::new(text).scrollable()) + .child(Text::new(text).scrollable()) + .child(Text::new(text).scrollable()) .fixed_width(30), ) .button("Quit", |s| s.quit()) diff --git a/examples/list_view.rs b/examples/list_view.rs index 2fc6fb4..975cb4b 100644 --- a/examples/list_view.rs +++ b/examples/list_view.rs @@ -1,32 +1,33 @@ use cursive::traits::*; -use cursive::views::{ - Checkbox, Dialog, EditView, LinearLayout, ListView, SelectView, TextView, -}; +use cursive::views; use cursive::Cursive; -// This example uses a ListView. +// This example uses a views::List. // -// ListView can be used to build forms, with a list of inputs. +// views::List can be used to build forms, with a list of inputs. fn main() { let mut siv = Cursive::default(); siv.add_layer( - Dialog::new() + views::Dialog::new() .title("Please fill out this form") .button("Ok", |s| s.quit()) .content( - ListView::new() + views::List::new() // Each child is a single-line view with a label - .child("Name", EditView::new().fixed_width(10)) + .child("Name", views::Edit::new().fixed_width(10)) .child( "Receive spam?", - Checkbox::new().on_change(|s, checked| { + views::Checkbox::new().on_change(|s, checked| { // Enable/Disable the next field depending on this checkbox for name in &["email1", "email2"] { - s.call_on_id(name, |view: &mut EditView| { - view.set_enabled(checked) - }); + s.call_on_id( + name, + |view: &mut views::Edit| { + view.set_enabled(checked) + }, + ); if checked { s.focus_id("email1").unwrap(); } @@ -37,16 +38,16 @@ fn main() { "Email", // Each child must have a height of 1 line, // but we can still combine multiple views! - LinearLayout::horizontal() + views::LinearLayout::horizontal() .child( - EditView::new() + views::Edit::new() .disabled() .with_id("email1") .fixed_width(15), ) - .child(TextView::new("@")) + .child(views::Text::new("@")) .child( - EditView::new() + views::Edit::new() .disabled() .with_id("email2") .fixed_width(10), @@ -56,8 +57,8 @@ fn main() { .delimiter() .child( "Age", - // Popup-mode SelectView are small enough to fit here - SelectView::new() + // Popup-mode views::Select are small enough to fit here + views::Select::new() .popup() .item_str("0-18") .item_str("19-30") @@ -69,7 +70,7 @@ fn main() { for i in 0..50 { list.add_child( &format!("Item {}", i), - EditView::new(), + views::Edit::new(), ); } }) diff --git a/examples/logs.rs b/examples/logs.rs index 88f5337..8396fc4 100644 --- a/examples/logs.rs +++ b/examples/logs.rs @@ -76,7 +76,7 @@ impl BufferView { } } -impl View for BufferView { +impl cursive::View for BufferView { fn layout(&mut self, _: Vec2) { // Before drawing, we'll want to update the buffer self.update(); diff --git a/examples/lorem.rs b/examples/lorem.rs index 5e38959..4739b19 100644 --- a/examples/lorem.rs +++ b/examples/lorem.rs @@ -1,7 +1,6 @@ use cursive::align::HAlign; -use cursive::view::Scrollable; -use cursive::views::{Dialog, Panel, TextView}; -use cursive::Cursive; +use cursive::traits::Scrollable as _; +use cursive::{views, Cursive}; fn main() { // Read some long text from a file. @@ -15,14 +14,16 @@ 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_fullscreen_layer( - Dialog::around(Panel::new(TextView::new(content).scrollable())) - .title("Unicode and wide-character support") - // This is the alignment for the button - .h_align(HAlign::Center) - .button("Quit", |s| s.quit()), + views::Dialog::around(views::Panel::new( + views::Text::new(content).scrollable(), + )) + .title("Unicode and wide-character support") + // This is the alignment for the button + .h_align(HAlign::Center) + .button("Quit", |s| s.quit()), ); // Show a popup on top of the view. - siv.add_layer(Dialog::info( + siv.add_layer(views::Dialog::info( "Try resizing the terminal!\n(Press 'q' to \ quit when you're done.)", )); diff --git a/examples/markup.rs b/examples/markup.rs index b3544bd..a721256 100644 --- a/examples/markup.rs +++ b/examples/markup.rs @@ -1,9 +1,6 @@ -use cursive::theme::BaseColor; -use cursive::theme::Color; -use cursive::theme::Effect; -use cursive::theme::Style; +use cursive::theme::{BaseColor, Color, Effect, Style}; use cursive::utils::markup::StyledString; -use cursive::views::{Dialog, TextView}; +use cursive::views; use cursive::Cursive; fn main() { @@ -16,9 +13,9 @@ fn main() { Style::from(Color::Light(BaseColor::Blue)).combine(Effect::Bold), )); - // TextView can natively accept StyledString. + // views::Text can natively accept StyledString. siv.add_layer( - Dialog::around(TextView::new(styled)) + views::Dialog::around(views::Text::new(styled)) .button("Hell yeah!", |s| s.quit()), ); diff --git a/examples/mines/main.rs b/examples/mines/main.rs index 0da4435..4da5972 100644 --- a/examples/mines/main.rs +++ b/examples/mines/main.rs @@ -4,7 +4,7 @@ use cursive::direction::Direction; use cursive::event::{Event, EventResult, MouseButton, MouseEvent}; use cursive::theme::{BaseColor, Color, ColorStyle}; use cursive::vec::Vec2; -use cursive::views::{Button, Dialog, LinearLayout, Panel, SelectView}; +use cursive::views::{Button, Dialog, LinearLayout, Panel, Select}; use cursive::Cursive; use cursive::Printer; @@ -33,7 +33,7 @@ fn show_options(siv: &mut Cursive) { Dialog::new() .title("Select difficulty") .content( - SelectView::new() + Select::new() .item( "Easy: 8x8, 10 mines", game::Options { diff --git a/examples/mutation.rs b/examples/mutation.rs index 2947cf9..8152376 100644 --- a/examples/mutation.rs +++ b/examples/mutation.rs @@ -1,6 +1,6 @@ use cursive::traits::*; use cursive::view::{Offset, Position}; -use cursive::views::{Dialog, OnEventView, TextView}; +use cursive::views::{Dialog, OnEvent, Text}; use cursive::Cursive; // This example modifies a view after creation. @@ -17,7 +17,7 @@ fn main() { // We add the P callback on the textview only (and not globally), // so that we can't call it when the popup is already visible. siv.add_layer( - OnEventView::new(TextView::new(content).with_id("text")) + OnEvent::new(Text::new(content).with_id("text")) .on_event('p', |s| show_popup(s)), ); @@ -29,11 +29,11 @@ fn show_popup(siv: &mut Cursive) { // so the user can see both the popup and the view underneath. siv.screen_mut().add_layer_at( Position::new(Offset::Center, Offset::Parent(5)), - Dialog::around(TextView::new("Tak!")) + Dialog::around(Text::new("Tak!")) .button("Change", |s| { // Look for a view tagged "text". // We _know_ it's there, so unwrap it. - s.call_on_id("text", |view: &mut TextView| { + s.call_on_id("text", |view: &mut Text| { let content = reverse(view.get_content().source()); view.set_content(content); }); diff --git a/examples/position.rs b/examples/position.rs index 1703a88..9e848db 100644 --- a/examples/position.rs +++ b/examples/position.rs @@ -1,6 +1,6 @@ use cursive::view::Position; use cursive::views::LayerPosition; -use cursive::views::TextView; +use cursive::views::Text; use cursive::Cursive; /// Moves top layer by the specified amount @@ -31,7 +31,7 @@ fn main() { siv.add_global_callback('d', |s| move_top(s, 1, 0)); // Add window to fly around. - siv.add_layer(TextView::new( + siv.add_layer(Text::new( "Press w,a,s,d to move the window.\n\ Press q to quit the application.", )); diff --git a/examples/progress.rs b/examples/progress.rs index b6a5b3f..981a40c 100644 --- a/examples/progress.rs +++ b/examples/progress.rs @@ -1,6 +1,6 @@ use cursive::traits::*; use cursive::utils::Counter; -use cursive::views::{Button, Dialog, LinearLayout, ProgressBar, TextView}; +use cursive::views::{Button, Dialog, LinearLayout, ProgressBar, Text}; use cursive::Cursive; use rand::Rng; use std::cmp::min; @@ -60,7 +60,7 @@ fn coffee_break(s: &mut Cursive) { s.add_layer( Dialog::new() .title("Preparation complete") - .content(TextView::new("Now, the real deal!").center()) + .content(Text::new("Now, the real deal!").center()) .button("Again??", phase_2), ); } @@ -119,7 +119,7 @@ fn final_step(s: &mut Cursive) { Dialog::new() .title("Report") .content( - TextView::new( + Text::new( "Time travel was a success!\n\ We went forward a few seconds!!", ) diff --git a/examples/radio.rs b/examples/radio.rs index ab6c268..efbab6d 100644 --- a/examples/radio.rs +++ b/examples/radio.rs @@ -1,4 +1,4 @@ -use cursive::views::{Dialog, DummyView, LinearLayout, RadioGroup}; +use cursive::views::{Dialog, Dummy, LinearLayout, RadioGroup}; use cursive::Cursive; // This example uses radio buttons. @@ -24,8 +24,8 @@ fn main() { .child(color_group.button_str("Green")) .child(color_group.button_str("Blue")), ) - // A DummyView is used as a spacer - .child(DummyView) + // A Dummy is used as a spacer + .child(Dummy) .child( LinearLayout::vertical() // For the size, we store a number separately diff --git a/examples/refcell_view.rs b/examples/refcell_view.rs index a2abf16..2709dc7 100644 --- a/examples/refcell_view.rs +++ b/examples/refcell_view.rs @@ -1,5 +1,5 @@ -use cursive::view::{Boxable, Identifiable}; -use cursive::views::{Dialog, EditView, LinearLayout, TextView}; +use cursive::traits::{Identifiable, Resizable}; +use cursive::views::{Dialog, Edit, LinearLayout, Text}; use cursive::Cursive; // This example shows a way to access multiple views at the same time. @@ -12,9 +12,9 @@ fn main() { siv.add_layer( Dialog::around( LinearLayout::vertical() - .child(EditView::new().on_edit(on_edit).with_id("1")) - .child(EditView::new().on_edit(on_edit).with_id("2")) - .child(TextView::new("match").with_id("match")) + .child(Edit::new().on_edit(on_edit).with_id("1")) + .child(Edit::new().on_edit(on_edit).with_id("2")) + .child(Text::new("match").with_id("match")) .fixed_width(10), ) .button("Quit", Cursive::quit), @@ -24,19 +24,19 @@ fn main() { } // Compare the content of the two edit views, -// and update the TextView accordingly. +// and update the Text accordingly. // // We'll ignore the `content` and `cursor` arguments, // and directly retrieve the content from the `Cursive` root. fn on_edit(siv: &mut Cursive, _content: &str, _cursor: usize) { // Get handles for each view. - let edit_1 = siv.find_id::("1").unwrap(); - let edit_2 = siv.find_id::("2").unwrap(); + let edit_1 = siv.find_id::("1").unwrap(); + let edit_2 = siv.find_id::("2").unwrap(); // Directly compare references to edit_1 and edit_2. let matches = edit_1.get_content() == edit_2.get_content(); - siv.call_on_id("match", |v: &mut TextView| { + siv.call_on_id("match", |v: &mut Text| { v.set_content(if matches { "match" } else { "no match" }) }); } diff --git a/examples/scroll.rs b/examples/scroll.rs index 037aca8..b533b9f 100644 --- a/examples/scroll.rs +++ b/examples/scroll.rs @@ -1,5 +1,4 @@ -use cursive::traits::Boxable; -use cursive::view::Scrollable; +use cursive::traits::{Resizable, Scrollable}; use cursive::views::{Button, Canvas, Dialog, LinearLayout}; use cursive::Printer; diff --git a/examples/select.rs b/examples/select.rs index 521aaf4..f3a6c16 100644 --- a/examples/select.rs +++ b/examples/select.rs @@ -1,16 +1,16 @@ use cursive::align::HAlign; use cursive::event::EventResult; use cursive::traits::*; -use cursive::views::{Dialog, OnEventView, SelectView, TextView}; +use cursive::views::{Dialog, OnEvent, Select, Text}; use cursive::Cursive; -// We'll use a SelectView here. +// We'll use a Select here. // -// A SelectView is a scrollable list of items, from which the user can select +// A Select is a scrollable list of items, from which the user can select // one. fn main() { - let mut select = SelectView::new() + let mut select = Select::new() // Center the text horizontally .h_align(HAlign::Center) // Use keyboard to jump to the pressed letters @@ -25,7 +25,7 @@ fn main() { select.set_on_submit(show_next_window); // Let's override the `j` and `k` keys for navigation - let select = OnEventView::new(select) + let select = OnEvent::new(select) .on_pre_event_inner('k', |s, _| { s.select_up(1); Some(EventResult::Consumed(None)) @@ -53,6 +53,6 @@ fn show_next_window(siv: &mut Cursive, city: &str) { siv.pop_layer(); let text = format!("{} is a great city!", city); siv.add_layer( - Dialog::around(TextView::new(text)).button("Quit", |s| s.quit()), + Dialog::around(Text::new(text)).button("Quit", |s| s.quit()), ); } diff --git a/examples/slider.rs b/examples/slider.rs index 70b5978..a1f33b3 100644 --- a/examples/slider.rs +++ b/examples/slider.rs @@ -1,5 +1,5 @@ use cursive::traits::*; -use cursive::views::{Dialog, SliderView}; +use cursive::views::{Dialog, Slider}; use cursive::Cursive; fn main() { @@ -13,7 +13,7 @@ fn main() { siv.add_layer( Dialog::around( // We give the number of steps in the constructor - SliderView::horizontal(15) + Slider::horizontal(15) // Sets the initial value .value(7) .on_change(|s, v| { diff --git a/examples/tcp_server.rs b/examples/tcp_server.rs index 86f7fc6..50fb92b 100644 --- a/examples/tcp_server.rs +++ b/examples/tcp_server.rs @@ -108,7 +108,7 @@ fn build_ui(model: Model) -> impl cursive::view::View { views::LinearLayout::vertical() .child(build_selector(Arc::clone(&model))) .child(build_tester(Arc::clone(&model))) - .child(views::DummyView.fixed_height(1)) + .child(views::Dummy.fixed_height(1)) .child(build_log_viewer(Arc::clone(&model))) } @@ -151,15 +151,15 @@ fn build_selector(model: Model) -> impl cursive::view::View { let offset = model.lock().unwrap().offset; views::LinearLayout::horizontal() .child( - views::EditView::new() + views::Edit::new() .content(format!("{}", offset)) .with_id("edit") .min_width(5), ) - .child(views::DummyView.fixed_width(1)) + .child(views::Dummy.fixed_width(1)) .child(views::Button::new("Update", move |s| { if let Some(n) = s - .call_on_id("edit", |edit: &mut views::EditView| { + .call_on_id("edit", |edit: &mut views::Edit| { edit.get_content() }) .and_then(|content| content.parse().ok()) @@ -176,8 +176,8 @@ fn build_selector(model: Model) -> impl cursive::view::View { /// Build a view that can run test connections. fn build_tester(model: Model) -> impl cursive::view::View { views::LinearLayout::horizontal() - .child(views::TextView::new("Current value:")) - .child(views::DummyView.fixed_width(1)) + .child(views::Text::new("Current value:")) + .child(views::Dummy.fixed_width(1)) .child( views::Canvas::new(model) .with_draw(|model, printer| { @@ -188,7 +188,7 @@ fn build_tester(model: Model) -> impl cursive::view::View { }) .with_required_size(|_, _| cursive::Vec2::new(3, 1)), ) - .child(views::DummyView.fixed_width(1)) + .child(views::Dummy.fixed_width(1)) .child(views::Button::new("Test", |s| { if let Err(err) = test_server() { s.add_layer( diff --git a/examples/terminal_default.rs b/examples/terminal_default.rs index 00de7fb..43330ed 100644 --- a/examples/terminal_default.rs +++ b/examples/terminal_default.rs @@ -1,5 +1,5 @@ use cursive::theme::{Color, PaletteColor, Theme}; -use cursive::views::TextView; +use cursive::views::Text; use cursive::Cursive; // This example sets the background color to the terminal default. @@ -15,7 +15,7 @@ fn main() { // We can quit by pressing `q` siv.add_global_callback('q', Cursive::quit); - siv.add_layer(TextView::new( + siv.add_layer(Text::new( "Hello World with default terminal background color!\n\ Press q to quit the application.", )); diff --git a/examples/text_area.rs b/examples/text_area.rs index 34bf739..492b1e9 100644 --- a/examples/text_area.rs +++ b/examples/text_area.rs @@ -1,6 +1,6 @@ use cursive::event::{Event, Key}; use cursive::traits::*; -use cursive::views::{Dialog, EditView, OnEventView, TextArea}; +use cursive::views; use cursive::Cursive; fn main() { @@ -9,32 +9,32 @@ fn main() { // The main dialog will just have a textarea. // Its size expand automatically with the content. siv.add_layer( - Dialog::new() + views::Dialog::new() .title("Describe your issue") .padding((1, 1, 1, 0)) - .content(TextArea::new().with_id("text")) + .content(views::TextArea::new().with_id("text")) .button("Ok", Cursive::quit), ); // We'll add a find feature! - siv.add_layer(Dialog::info("Hint: press Ctrl-F to find in text!")); + siv.add_layer(views::Dialog::info("Hint: press Ctrl-F to find in text!")); siv.add_global_callback(Event::CtrlChar('f'), |s| { // When Ctrl-F is pressed, show the Find popup. // Pressing the Escape key will discard it. s.add_layer( - OnEventView::new( - Dialog::new() + views::OnEvent::new( + views::Dialog::new() .title("Find") .content( - EditView::new() + views::Edit::new() .on_submit(find) .with_id("edit") .min_width(10), ) .button("Ok", |s| { let text = s - .call_on_id("edit", |view: &mut EditView| { + .call_on_id("edit", |view: &mut views::Edit| { view.get_content() }) .unwrap(); @@ -55,7 +55,7 @@ fn find(siv: &mut Cursive, text: &str) { // First, remove the find popup siv.pop_layer(); - let res = siv.call_on_id("text", |v: &mut TextArea| { + let res = siv.call_on_id("text", |v: &mut views::TextArea| { // Find the given text from the text area content // Possible improvement: search after the current cursor. if let Some(i) = v.get_content().find(text) { @@ -70,6 +70,6 @@ fn find(siv: &mut Cursive, text: &str) { if let Some(Err(())) = res { // If we didn't find anything, tell the user! - siv.add_layer(Dialog::info(format!("`{}` not found", text))); + siv.add_layer(views::Dialog::info(format!("`{}` not found", text))); } } diff --git a/examples/theme.rs b/examples/theme.rs index f03385f..379415e 100644 --- a/examples/theme.rs +++ b/examples/theme.rs @@ -1,4 +1,4 @@ -use cursive::views::{Dialog, TextView}; +use cursive::views::{Dialog, Text}; use cursive::Cursive; fn main() { @@ -13,7 +13,7 @@ fn main() { siv.load_toml(include_str!("../assets/style.toml")).unwrap(); siv.add_layer( - Dialog::around(TextView::new( + Dialog::around(Text::new( "This application uses a \ custom theme!", )) @@ -25,7 +25,7 @@ fn main() { #[cfg(not(feature = "toml"))] { siv.add_layer( - Dialog::around(TextView::new( + Dialog::around(Text::new( "Run this example again with the `toml` feature!\n\n\ cargo run --example theme --features toml", )) diff --git a/examples/theme_manual.rs b/examples/theme_manual.rs index 7dbb6b8..b4ad34f 100644 --- a/examples/theme_manual.rs +++ b/examples/theme_manual.rs @@ -1,18 +1,16 @@ use cursive::theme::{BaseColor, BorderStyle, Color, ColorStyle}; -use cursive::views::{Dialog, EditView, LinearLayout, TextView}; +use cursive::views::{Dialog, Edit, LinearLayout, Text}; use cursive::Cursive; fn main() { let mut siv = Cursive::default(); let layout = LinearLayout::vertical() - .child(TextView::new("This is a dynamic theme example!")) - .child(EditView::new().content("Woo! colors!").style( - ColorStyle::new( - Color::Rgb(200, 150, 150), - Color::Dark(BaseColor::Blue), - ), - )); + .child(Text::new("This is a dynamic theme example!")) + .child(Edit::new().content("Woo! colors!").style(ColorStyle::new( + Color::Rgb(200, 150, 150), + Color::Dark(BaseColor::Blue), + ))); siv.add_layer( Dialog::around(layout) diff --git a/examples/vpv.rs b/examples/vpv.rs index ce5f8d9..2144508 100644 --- a/examples/vpv.rs +++ b/examples/vpv.rs @@ -1,6 +1,6 @@ use std::io; -use cursive::traits::{Boxable, With}; +use cursive::traits::{Resizable, With}; use cursive::utils; use cursive::views::{Canvas, Dialog, LinearLayout, ProgressBar}; use cursive::Cursive; diff --git a/src/cursive.rs b/src/cursive.rs index c0b84b1..8913922 100644 --- a/src/cursive.rs +++ b/src/cursive.rs @@ -9,11 +9,12 @@ use crossbeam_channel::{self, Receiver, Sender}; use crate::backend; use crate::direction; use crate::event::{Callback, Event, EventResult}; -use crate::printer::Printer; use crate::theme; -use crate::vec::Vec2; -use crate::view::{self, Finder, IntoBoxedView, Position, View}; +use crate::traits::Finder as _; +use crate::view::{self, IntoBoxedView, Position, View}; use crate::views::{self, LayerPosition}; +use crate::Printer; +use crate::Vec2; static DEBUG_VIEW_ID: &str = "_cursive_debug_view"; @@ -524,12 +525,12 @@ impl Cursive { /// # use cursive::traits::*; /// let mut siv = Cursive::dummy(); /// - /// siv.add_layer(views::TextView::new("Text #1").with_id("text")); + /// siv.add_layer(views::Text::new("Text #1").with_id("text")); /// /// siv.add_global_callback('p', |s| { /// s.call_on( /// &view::Selector::Id("text"), - /// |view: &mut views::TextView| { + /// |view: &mut views::Text| { /// view.set_content("Text #2"); /// }, /// ); @@ -558,11 +559,11 @@ impl Cursive { /// # use cursive::traits::*; /// let mut siv = Cursive::dummy(); /// - /// siv.add_layer(views::TextView::new("Text #1") + /// siv.add_layer(views::Text::new("Text #1") /// .with_id("text")); /// /// siv.add_global_callback('p', |s| { - /// s.call_on_id("text", |view: &mut views::TextView| { + /// s.call_on_id("text", |view: &mut views::Text| { /// view.set_content("Text #2"); /// }); /// }); @@ -585,37 +586,37 @@ impl Cursive { /// /// ```rust /// # use cursive::Cursive; - /// # use cursive::views::{TextView, ViewRef}; + /// # use cursive::views::{Text, ViewRef}; /// # let mut siv = Cursive::dummy(); /// use cursive::traits::Identifiable; /// - /// siv.add_layer(TextView::new("foo").with_id("id")); + /// siv.add_layer(Text::new("foo").with_id("id")); /// /// // Could be called in a callback - /// let mut view: ViewRef = siv.find_id("id").unwrap(); + /// let mut view: ViewRef = siv.find_id("id").unwrap(); /// view.set_content("bar"); /// ``` /// /// Note that you must specify the exact type for the view you're after; for example, using the - /// wrong item type in a `SelectView` will not find anything: + /// wrong item type in a `Select` will not find anything: /// /// ```rust /// # use cursive::Cursive; - /// # use cursive::views::{SelectView}; + /// # use cursive::views::{Select}; /// # let mut siv = Cursive::dummy(); /// use cursive::traits::Identifiable; /// - /// let select = SelectView::new().item("zero", 0u32).item("one", 1u32); + /// let select = Select::new().item("zero", 0u32).item("one", 1u32); /// siv.add_layer(select.with_id("select")); /// /// // Specifying a wrong type will not return anything. - /// assert!(siv.find_id::>("select").is_none()); + /// assert!(siv.find_id::>("select").is_none()); /// /// // Omitting the type will use the default type, in this case `String`. - /// assert!(siv.find_id::("select").is_none()); + /// assert!(siv.find_id::