Skip to content

Commit

Permalink
Make GUI in examples a feature, so that it won't bother automated tes…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
tdgne committed Aug 18, 2017
1 parent bc449a0 commit 1168812
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ license-file = "LICENCE"

[features]
default = ["rlibc"]
example-gui = ["gtk", "gdk-pixbuf"]

[dependencies]
rlibc = {version = "1.0.0", optional = true}
gtk = {version = "0.1.3", optional = true}
gdk-pixbuf = {version = "0.1.3", optional = true}

[dev-dependencies]
gtk = "0.1.3"
gdk-pixbuf = "0.1.3"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Requests and contributions are welcome!
## Screenshot

```sh
cargo run --release --example waveform
cargo run --features "example-gui" --example waveform
```

![examples/waveform.rs](https://user-images.githubusercontent.com/29127111/27250722-dd579ff6-5370-11e7-99c2-7dc3e7705c14.png)
Expand Down
44 changes: 31 additions & 13 deletions examples/waveform.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
extern crate waveform;

#[cfg(feature = "example-gui")]
extern crate gtk;
#[cfg(feature = "example-gui")]
extern crate gdk_pixbuf;

use waveform::*;
use waveform::direct::*;

#[cfg(feature = "example-gui")]
use gtk::{ContainerExt, Image, Inhibit, WidgetExt, Window, WindowExt, WindowType};
#[cfg(feature = "example-gui")]
use gdk_pixbuf::Pixbuf;

fn main() {
// Whether to use BinnedWaveformRenderer or DirectWaveformRenderer
let use_binned = true;

if gtk::init().is_err() {
panic!("Failed to initialize gtk.");
#[cfg(feature = "example-gui")]
{
if gtk::init().is_err() {
panic!("Failed to initialize gtk.");
}
}

#[cfg(feature = "example-gui")]
let window = Window::new(WindowType::Toplevel);
window.set_title("A simple waveform renderer test");
window.set_default_size(800, 100);
window.connect_delete_event(|_, _| {
gtk::main_quit();
Inhibit(false)
});
#[cfg(feature = "example-gui")]
{
window.set_title("A simple waveform renderer test");
window.set_default_size(800, 100);
window.connect_delete_event(|_, _| {
gtk::main_quit();
Inhibit(false)
});
}

let mut samples: Vec<f64> = Vec::new();
for t in 0..44100 {
samples.push(
Expand Down Expand Up @@ -62,9 +77,12 @@ fn main() {
vec = wfg.render_vec(&samples, (800, 100)).unwrap();
}

let pixbuf = Pixbuf::new_from_vec(vec, 0, true, 8, 800, 100, 800 * 4);
let image = Image::new_from_pixbuf(Some(&pixbuf));
window.add(&image);
window.show_all();
gtk::main();
#[cfg(feature = "example-gui")]
{
let pixbuf = Pixbuf::new_from_vec(vec, 0, true, 8, 800, 100, 800 * 4);
let image = Image::new_from_pixbuf(Some(&pixbuf));
window.add(&image);
window.show_all();
gtk::main();
}
}

0 comments on commit 1168812

Please sign in to comment.