fix up other ezgui apps, run clippy

This commit is contained in:
Dustin Carlino 2019-05-04 17:22:27 -07:00
parent a921469da9
commit 73f32854be
7 changed files with 25 additions and 27 deletions

View File

@ -1,5 +1,5 @@
use abstutil::{find_next_file, find_prev_file, read_binary, Timer};
use ezgui::{Canvas, Color, EventCtx, EventLoopMode, GfxCtx, Key, Prerender, Text, GUI};
use ezgui::{Color, EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI};
use geom::{Distance, Polygon};
use map_model::raw_data;
use map_model::raw_data::{StableIntersectionID, StableRoadID};
@ -28,7 +28,7 @@ impl UI {
}
fn load_different(&mut self, filename: String, ctx: &mut EventCtx) {
self.world = load_initial_map(&filename, ctx.canvas, ctx.prerender);
self.world = load_initial_map(&filename, ctx);
self.selected = None;
self.filename = filename;
self.hide.clear();
@ -90,9 +90,9 @@ impl GUI for UI {
fn main() {
let args: Vec<String> = env::args().collect();
ezgui::run("InitialMap debugger", 1024.0, 768.0, |canvas, prerender| {
canvas.cam_zoom = 4.0;
UI::new(&args[1], load_initial_map(&args[1], canvas, prerender))
ezgui::run("InitialMap debugger", 1024.0, 768.0, |ctx| {
ctx.canvas.cam_zoom = 4.0;
UI::new(&args[1], load_initial_map(&args[1], ctx))
});
}
@ -112,7 +112,7 @@ impl viewer::ObjectID for ID {
}
}
fn load_initial_map(filename: &str, canvas: &mut Canvas, prerender: &Prerender) -> World<ID> {
fn load_initial_map(filename: &str, ctx: &mut EventCtx) -> World<ID> {
let data: raw_data::InitialMap =
read_binary(filename, &mut Timer::new("load InitialMap")).unwrap();
@ -121,7 +121,7 @@ fn load_initial_map(filename: &str, canvas: &mut Canvas, prerender: &Prerender)
for r in data.roads.values() {
if r.fwd_width > Distance::ZERO {
w.add_obj(
prerender,
ctx.prerender,
ID::HalfRoad(r.id, true),
r.trimmed_center_pts
.shift_right(r.fwd_width / 2.0)
@ -137,7 +137,7 @@ fn load_initial_map(filename: &str, canvas: &mut Canvas, prerender: &Prerender)
}
if r.back_width > Distance::ZERO {
w.add_obj(
prerender,
ctx.prerender,
ID::HalfRoad(r.id, false),
r.trimmed_center_pts
.shift_left(r.back_width / 2.0)
@ -155,7 +155,7 @@ fn load_initial_map(filename: &str, canvas: &mut Canvas, prerender: &Prerender)
for i in data.intersections.values() {
w.add_obj(
prerender,
ctx.prerender,
ID::Intersection(i.id),
Polygon::new(&i.polygon),
Color::RED,
@ -164,7 +164,8 @@ fn load_initial_map(filename: &str, canvas: &mut Canvas, prerender: &Prerender)
}
if let Some(id) = data.focus_on {
canvas.center_on_map_pt(w.get_center(ID::Intersection(id)));
ctx.canvas
.center_on_map_pt(w.get_center(ID::Intersection(id)));
}
w

View File

@ -255,7 +255,7 @@ impl<'a> GfxCtx<'a> {
match self.context_menu {
ContextMenu::Inactive(ref keys) => keys.iter().cloned().collect(),
ContextMenu::Displaying(ref menu) => {
menu.active_choices().into_iter().map(|key| *key).collect()
menu.active_choices().into_iter().cloned().collect()
}
_ => Vec::new(),
}

View File

@ -51,11 +51,8 @@ impl<G: GUI> State<G> {
program: &glium::Program,
) -> (State<G>, EventLoopMode, bool) {
// Clear out the possible keys
match self.context_menu {
ContextMenu::Inactive(_) => {
self.context_menu = ContextMenu::new();
}
_ => {}
if let ContextMenu::Inactive(_) = self.context_menu {
self.context_menu = ContextMenu::new();
}
// It's impossible / very unlikey we'll grab the cursor in map space before the very first

View File

@ -4,7 +4,7 @@ mod timer;
use crate::render::DrawMap;
use crate::timer::Cycler;
use abstutil::Timer;
use ezgui::{EventCtx, EventLoopMode, GfxCtx, Key, Prerender, GUI};
use ezgui::{EventCtx, EventLoopMode, GfxCtx, Key, GUI};
use map_model::Map;
use std::path::{Path, PathBuf};
use std::process;
@ -26,7 +26,7 @@ struct UI {
}
impl UI {
fn new(flags: Flags, prerender: &Prerender) -> UI {
fn new(flags: Flags, ctx: &mut EventCtx) -> UI {
// TODO Consolidate with sim::load
let map: Map = if flags.load_map.starts_with(Path::new("../data/raw_maps/")) {
Map::new(
@ -43,7 +43,7 @@ impl UI {
};
UI {
draw_map: DrawMap::new(map, prerender),
draw_map: DrawMap::new(map, ctx.prerender),
cycler: Cycler::new(ANIMATION_PERIOD_S),
}
}
@ -65,7 +65,7 @@ impl GUI for UI {
fn main() {
let flags = Flags::from_args();
ezgui::run("Halloween tech demo", 1024.0, 768.0, |_, prerender| {
UI::new(flags, prerender)
ezgui::run("Halloween tech demo", 1024.0, 768.0, |ctx| {
UI::new(flags, ctx)
});
}

View File

@ -62,6 +62,6 @@ impl Building {
.map(|street| format!("{} {}", num, street))
})
})
.unwrap_or("???".to_string())
.unwrap_or_else(|| "???".to_string())
}
}

View File

@ -5,7 +5,7 @@ mod debug_polyline;
mod moving_polyline;
mod trim_polyline;
use ezgui::{Canvas, EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI};
use ezgui::{EventCtx, EventLoopMode, GfxCtx, Key, Text, GUI};
use geom::Pt2D;
use std::process;
@ -16,8 +16,8 @@ pub struct UI {
}
impl UI {
pub fn new(canvas: &mut Canvas) -> UI {
canvas.center_on_map_pt(Pt2D::new(305.0, 324.0));
pub fn new(ctx: &mut EventCtx) -> UI {
ctx.canvas.center_on_map_pt(Pt2D::new(305.0, 324.0));
UI {
p3_offset: (200.0, 150.0),
@ -127,5 +127,5 @@ impl GUI for UI {
}
fn main() {
ezgui::run("GUI Playground", 1024.0, 768.0, |canvas, _| UI::new(canvas));
ezgui::run("GUI Playground", 1024.0, 768.0, |ctx| UI::new(ctx));
}

View File

@ -228,7 +228,7 @@ impl GUI for UI {
fn main() {
let args: Vec<String> = env::args().collect();
ezgui::run("Synthetic map editor", 1024.0, 768.0, |_, _| {
ezgui::run("Synthetic map editor", 1024.0, 768.0, |_| {
UI::new(args.get(1))
});
}