Skip to content

Commit

Permalink
the important stuff: adding a face browser to the ezgui demo
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jul 1, 2020
1 parent c191ffd commit f90e506
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions ezgui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ ttf-parser = "0.6.1"
usvg = { git = "https://github.com/RazrFalcon/resvg", default-features=false }
webgl_stdweb = { version = "0.3", optional = true }
winit = "0.22.2"

[dev-dependencies]
rand = "0.7.0"
rand_xorshift = "0.2.0"
svg_face = "0.1.2"
23 changes: 22 additions & 1 deletion ezgui/examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use ezgui::{
VerticalAlignment, Widget, GUI,
};
use geom::{Angle, Duration, Polygon, Pt2D, Time};
use rand::SeedableRng;
use rand_xorshift::XorShiftRng;
use std::collections::HashSet;

fn main() {
Expand Down Expand Up @@ -154,6 +156,9 @@ impl GUI for App {
.named("stopwatch"),
);
}
"generate new faces" => {
self.scrollable_canvas = setup_scrollable_canvas(ctx);
}
_ => unreachable!(),
},
None => {}
Expand Down Expand Up @@ -242,6 +247,19 @@ fn setup_scrollable_canvas(ctx: &mut EventCtx) -> Drawable {
.centered_on(Pt2D::new(600.0, 500.0))
.rotate(Angle::new_degs(-30.0)),
);

let mut rng = XorShiftRng::from_entropy();
for i in 0..10 {
let mut svg_data = Vec::new();
svg_face::generate_face(&mut svg_data, &mut rng).unwrap();
let face = GeomBatch::from_svg_contents(svg_data).autocrop();
let dims = face.get_dims();
batch.append(
face.scale((200.0 / dims.width).min(200.0 / dims.height))
.translate(250.0 * (i as f64), 0.0),
);
}

// This is a bit of a hack; it's needed so that zooming in/out has reasonable limits.
ctx.canvas.map_dims = (5000.0, 5000.0);
batch.upload(ctx)
Expand All @@ -266,9 +284,12 @@ fn make_controls(ctx: &mut EventCtx) -> Composite {
)
.named("paused")
.margin(5),
Btn::text_fg("Reset")
Btn::text_fg("Reset timer")
.build(ctx, "reset the stopwatch", None)
.margin(5),
Btn::text_fg("New faces")
.build(ctx, "generate new faces", hotkey(Key::F))
.margin(5),
Checkbox::text(ctx, "Draw scrollable canvas", None, true).margin(5),
Checkbox::text(ctx, "Show timeseries", lctrl(Key::T), false).margin(5),
])
Expand Down

0 comments on commit f90e506

Please sign in to comment.