mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-24 09:24:26 +03:00
the important stuff: adding a face browser to the ezgui demo
This commit is contained in:
parent
c191ffde9a
commit
f90e506fbf
3
Cargo.lock
generated
3
Cargo.lock
generated
@ -776,10 +776,13 @@ dependencies = [
|
||||
"instant 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lru 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lyon 0.15.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand_xorshift 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.110 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"simsearch 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"stdweb 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"stretch 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"svg_face 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ttf-parser 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"usvg 0.10.0 (git+https://github.com/RazrFalcon/resvg)",
|
||||
"webgl_stdweb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -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"
|
||||
|
@ -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() {
|
||||
@ -154,6 +156,9 @@ impl GUI for App {
|
||||
.named("stopwatch"),
|
||||
);
|
||||
}
|
||||
"generate new faces" => {
|
||||
self.scrollable_canvas = setup_scrollable_canvas(ctx);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
},
|
||||
None => {}
|
||||
@ -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)
|
||||
@ -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),
|
||||
])
|
||||
|
Loading…
Reference in New Issue
Block a user