Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cursive-core to 0.4.0 #9

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 = "0.21.0"
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))
});