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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
mod bike_network;
mod explore;
mod labels;
mod layers;
mod predict;
mod quick_sketch;
mod trip;
use map_gui::tools::{grey_out_map, open_browser, CityPicker};
use widgetry::{
EventCtx, GfxCtx, HorizontalAlignment, Key, Line, Panel, ScreenDims, SimpleState, State, Text,
VerticalAlignment, Widget,
};
pub use self::explore::ExploreMap;
pub use self::layers::Layers;
use crate::app::{App, Transition};
pub use predict::ModeShiftData;
pub use trip::RoutingPreferences;
#[derive(PartialEq)]
pub enum Tab {
Explore,
Trip,
AddLanes,
PredictImpact,
}
pub trait TakeLayers {
fn take_layers(self) -> Layers;
}
impl Tab {
pub fn make_left_panel(self, ctx: &mut EventCtx, app: &App, contents: Widget) -> Panel {
let mut contents = Some(contents.section(ctx));
let mut col = vec![Widget::row(vec![
ctx.style()
.btn_plain
.btn()
.image_path("system/assets/pregame/logo.svg")
.image_dims(50.0)
.build_widget(ctx, "about A/B Street"),
Line("Ungap the Map")
.small_heading()
.into_widget(ctx)
.centered_vert(),
map_gui::tools::change_map_btn(ctx, app)
.centered_vert()
.align_right(),
])];
col.push(
ctx.style()
.btn_tab
.icon_text("system/assets/tools/pan.svg", "Explore")
.hotkey(Key::Num1)
.disabled(self == Tab::Explore)
.build_def(ctx),
);
if self == Tab::Explore {
col.push(contents.take().unwrap());
}
col.push(
ctx.style()
.btn_tab
.icon_text("system/assets/tools/pin.svg", "Your Trip")
.hotkey(Key::Num2)
.disabled(self == Tab::Trip)
.build_def(ctx),
);
if self == Tab::Trip {
col.push(contents.take().unwrap());
}
col.push(
ctx.style()
.btn_tab
.icon_text("system/assets/tools/pencil.svg", "Add bike lanes")
.hotkey(Key::Num3)
.disabled(self == Tab::AddLanes)
.build_def(ctx),
);
if self == Tab::AddLanes {
col.push(contents.take().unwrap());
}
col.push(
ctx.style()
.btn_tab
.icon_text("system/assets/meters/trip_histogram.svg", "Predict impact")
.hotkey(Key::Num4)
.disabled(self == Tab::PredictImpact)
.build_def(ctx),
);
if self == Tab::PredictImpact {
col.push(contents.take().unwrap());
}
let mut panel = Panel::new_builder(Widget::col(col))
.exact_size(ScreenDims {
width: 620.0,
height: ctx.canvas.window_height,
})
.aligned(HorizontalAlignment::Left, VerticalAlignment::Top);
if self == Tab::Trip {
panel = panel.ignore_initial_events();
}
panel.build(ctx)
}
pub fn handle_action<T: TakeLayers + State<App>>(
self,
ctx: &mut EventCtx,
app: &mut App,
action: &str,
) -> Option<Transition> {
match action {
"about A/B Street" => Some(Transition::Push(About::new_state(ctx))),
"change map" => {
Some(Transition::Push(CityPicker::new_state(
ctx,
app,
Box::new(move |ctx, app| {
let layers = Layers::new(ctx, app);
Transition::Multi(vec![
Transition::Pop,
Transition::Replace(match self {
Tab::Explore => ExploreMap::new_state(ctx, app, layers),
Tab::Trip => trip::TripPlanner::new_state(ctx, app, layers),
Tab::AddLanes => {
quick_sketch::QuickSketch::new_state(ctx, app, layers)
}
Tab::PredictImpact => {
predict::ShowGaps::new_state(ctx, app, layers)
}
}),
])
}),
)))
}
"Explore" => Some(Transition::ConsumeState(Box::new(|state, ctx, app| {
let state = state.downcast::<T>().ok().unwrap();
vec![ExploreMap::new_state(ctx, app, state.take_layers())]
}))),
"Your Trip" => Some(Transition::ConsumeState(Box::new(|state, ctx, app| {
let state = state.downcast::<T>().ok().unwrap();
vec![trip::TripPlanner::new_state(ctx, app, state.take_layers())]
}))),
"Add bike lanes" => {
app.primary.current_selection = None;
Some(Transition::ConsumeState(Box::new(|state, ctx, app| {
let state = state.downcast::<T>().ok().unwrap();
vec![quick_sketch::QuickSketch::new_state(
ctx,
app,
state.take_layers(),
)]
})))
}
"Predict impact" => Some(Transition::ConsumeState(Box::new(|state, ctx, app| {
let state = state.downcast::<T>().ok().unwrap();
vec![predict::ShowGaps::new_state(ctx, app, state.take_layers())]
}))),
_ => None,
}
}
}
struct About;
impl About {
fn new_state(ctx: &mut EventCtx) -> Box<dyn State<App>> {
let panel = Panel::new_builder(Widget::col(vec![
Widget::row(vec![
Line("About A/B Street").small_heading().into_widget(ctx),
ctx.style().btn_close_widget(ctx),
]),
Text::from_multiline(vec![
Line("Created by Dustin Carlino, Yuwen Li, & Michael Kirk").small(),
Line("Data from OpenStreetMap, King County GIS, King County LIDAR").small(),
])
.into_widget(ctx),
ctx.style().btn_outline.text("Read more").build_def(ctx),
]))
.build(ctx);
<dyn SimpleState<_>>::new_state(panel, Box::new(About))
}
}
impl SimpleState<App> for About {
fn on_click(&mut self, _: &mut EventCtx, _: &mut App, x: &str, _: &Panel) -> Transition {
if x == "close" {
return Transition::Pop;
} else if x == "Read more" {
open_browser("https://a-b-street.github.io/docs/software/ungap_the_map/index.html");
}
Transition::Keep
}
fn draw(&self, g: &mut GfxCtx, app: &App) {
grey_out_map(g, app);
}
}