1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
use map_model::BuildingID;
use widgetry::{
Btn, Color, Drawable, EventCtx, GeomBatch, GfxCtx, HorizontalAlignment, Line, Outcome, Panel,
RewriteColor, State, Text, VerticalAlignment, Widget,
};
use self::isochrone::Isochrone;
use crate::app::App;
use crate::game::Transition;
mod isochrone;
pub struct Viewer {
panel: Panel,
highlight_start: Drawable,
isochrone: Isochrone,
}
impl Viewer {
pub fn new(ctx: &mut EventCtx, app: &App, start: BuildingID) -> Box<dyn State<App>> {
let start = app.primary.map.get_b(start);
let panel = Panel::new(Widget::col(vec![
Widget::row(vec![
Line("15-minute neighborhood explorer")
.small_heading()
.draw(ctx),
Btn::close(ctx),
]),
Text::from_all(vec![
Line("Starting from: ").secondary(),
Line(&start.address),
])
.draw(ctx),
]))
.aligned(HorizontalAlignment::Center, VerticalAlignment::Top)
.build(ctx);
let highlight_start = GeomBatch::load_svg(ctx.prerender, "system/assets/tools/star.svg")
.centered_on(start.polygon.center())
.color(RewriteColor::ChangeAll(Color::YELLOW));
Box::new(Viewer {
panel,
highlight_start: ctx.upload(highlight_start),
isochrone: Isochrone::new(ctx, app, start.id),
})
}
}
impl State<App> for Viewer {
fn event(&mut self, ctx: &mut EventCtx, _: &mut App) -> Transition {
ctx.canvas_movement();
match self.panel.event(ctx) {
Outcome::Clicked(x) => match x.as_ref() {
"close" => {
return Transition::Pop;
}
_ => unreachable!(),
},
_ => {}
}
Transition::Keep
}
fn draw(&self, g: &mut GfxCtx, _: &App) {
g.redraw(&self.isochrone.draw);
g.redraw(&self.highlight_start);
self.panel.draw(g);
}
}