diff --git a/Cargo.toml b/Cargo.toml index a3e454b..1f4a494 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,10 @@ documentation = "https://docs.rs/cursive-aligned-view" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -cursive_core = "0.3" +cursive_core = "0.4.4" [dev-dependencies] serde_json = "1.0.74" -cursive = "0.17.0" +cursive = { version = "0.21.0", features = ["builder"] } crossbeam = "0.8.1" insta = "1.10.0" diff --git a/examples/builder.rs b/examples/builder.rs new file mode 100644 index 0000000..eb08462 --- /dev/null +++ b/examples/builder.rs @@ -0,0 +1,23 @@ +use cursive_aligned_view as _; // This needs to be imported to enable the blueprints. +use serde_json::json; + +fn main() { + // This is the same layout as the `simple` example, but using a builder config. + let config = json! ({ + "Panel": { + "title": "Hello, world!", + "view": "DummyView", + "with": [ + {"fixed_width": 20}, + "align_center", + "full_screen", + ] + }, + }); + + let context = cursive::builder::Context::new(); + + let mut siv = cursive::default(); + siv.add_layer(context.build(&config).unwrap()); + siv.run(); +} diff --git a/examples/dynamic.rs b/examples/dynamic.rs index e807b43..3f7f007 100644 --- a/examples/dynamic.rs +++ b/examples/dynamic.rs @@ -15,10 +15,7 @@ fn main() { .fixed_width(20) .align_top_left() .with_name("panel") - .resized( - cursive::view::SizeConstraint::Full, - cursive::view::SizeConstraint::Full, - ); + .full_screen(); let sink = siv.cb_sink().clone(); std::thread::spawn(move || { diff --git a/examples/simple.rs b/examples/simple.rs index 96d0455..dd85077 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -10,10 +10,7 @@ fn main() { .title("Hello, world!") .fixed_width(20) .align_center() - .resized( - cursive::view::SizeConstraint::Full, - cursive::view::SizeConstraint::Full, - ); + .full_screen(); siv.add_layer(panel); siv.run() diff --git a/src/lib.rs b/src/lib.rs index 8886e30..0d90744 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -366,3 +366,50 @@ impl ViewWrapper for AlignedView { self.view.important_area(self.last_size) + self.offset } } + +#[cursive_core::blueprint(AlignedView::new(view, alignment))] +struct Blueprint { + view: cursive_core::views::BoxedView, + alignment: Align, +} + +cursive_core::manual_blueprint!(with align, |config, context| { + let alignment = context.resolve(config)?; + Ok(move |view| AlignedView::new(view, alignment)) +}); + +cursive_core::manual_blueprint!(with align_top_left, |_config, _context| { + Ok(|view| AlignedView::with_top_left(view)) +}); + +cursive_core::manual_blueprint!(with align_top_center, |_config, _context| { + Ok(|view| AlignedView::with_top_center(view)) +}); + +cursive_core::manual_blueprint!(with align_top_right, |_config, _context| { + Ok(|view| AlignedView::with_top_right(view)) +}); + +cursive_core::manual_blueprint!(with align_center_left, |_config, _context| { + Ok(|view| AlignedView::with_center_left(view)) +}); + +cursive_core::manual_blueprint!(with align_center, |_config, _context| { + Ok(|view| AlignedView::with_center(view)) +}); + +cursive_core::manual_blueprint!(with align_center_right, |_config, _context| { + Ok(|view| AlignedView::with_center_right(view)) +}); + +cursive_core::manual_blueprint!(with align_bottom_left, |_config, _context| { + Ok(|view| AlignedView::with_bottom_left(view)) +}); + +cursive_core::manual_blueprint!(with align_bottom_center, |_config, _context| { + Ok(|view| AlignedView::with_bottom_center(view)) +}); + +cursive_core::manual_blueprint!(with align_bottom_right, |_config, _context| { + Ok(|view| AlignedView::with_bottom_right(view)) +});