Fix the theme example (#452)

- Remove the inline feature detection, it doesn't work for features of
  dependencies. Instead use `required-features` in `Cargo.toml` for the
  specific binary.

- The asset moved one level up relatively to `../../assets/style.toml`
This commit is contained in:
mara 2020-05-08 20:44:18 +02:00 committed by GitHub
parent fc59ee6f17
commit fc5060a8e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 27 deletions

View File

@ -20,3 +20,6 @@ cursive = { path = "../cursive", default-features=false }
[features]
default = ["cursive/default"]
[[bin]]
name = "theme"
required-features = ["cursive/toml"]

View File

@ -3,13 +3,11 @@ use cursive::views::{Dialog, TextView};
fn main() {
let mut siv = cursive::default();
#[cfg(feature = "toml")]
{
// You can load a theme from a file at runtime for fast development.
siv.load_theme_file("assets/style.toml").unwrap();
// Or you can directly load it from a string for easy deployment.
siv.load_toml(include_str!("../assets/style.toml")).unwrap();
siv.load_toml(include_str!("../../assets/style.toml")).unwrap();
siv.add_layer(
Dialog::around(TextView::new(
@ -19,19 +17,6 @@ fn main() {
.title("Themed dialog")
.button("Quit", |s| s.quit()),
);
}
#[cfg(not(feature = "toml"))]
{
siv.add_layer(
Dialog::around(TextView::new(
"Run this example again with the `toml` feature!\n\n\
cargo run --example theme --features toml",
))
.title("Themed dialog - missing `toml` feature")
.button("Quit", |s| s.quit()),
);
}
siv.run();
}