Skip to content

Commit

Permalink
Merge pull request #9 from gyscos/master
Browse files Browse the repository at this point in the history
Update cursive-core to 0.4.0
  • Loading branch information
fin-ger authored Aug 12, 2024
2 parents d116b78 + 1877d43 commit 99b17a5
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
23 changes: 23 additions & 0 deletions examples/builder.rs
Original file line number Diff line number Diff line change
@@ -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();
}
5 changes: 1 addition & 4 deletions examples/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {
Expand Down
5 changes: 1 addition & 4 deletions examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
47 changes: 47 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,50 @@ impl<T: View> ViewWrapper for AlignedView<T> {
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))
});

0 comments on commit 99b17a5

Please sign in to comment.