diff --git a/clippy.sh b/clippy.sh index 5f800f2833..4af99e42d0 100755 --- a/clippy.sh +++ b/clippy.sh @@ -9,6 +9,7 @@ cargo clippy -- \ -A clippy::collapsible_if \ -A clippy::cyclomatic_complexity \ -A clippy::expect_fun_call \ + -A clippy::float_cmp \ -A clippy::if_same_then_else \ -A clippy::large_enum_variant \ -A clippy::many_single_char_names \ diff --git a/debug_initialmap/src/main.rs b/debug_initialmap/src/main.rs index 0e4c178ba4..0e4622bc9c 100644 --- a/debug_initialmap/src/main.rs +++ b/debug_initialmap/src/main.rs @@ -84,7 +84,7 @@ impl GUI for UI { self.world.draw_selected(g, id); } - g.draw_blocking_text(self.osd.clone(), ezgui::BOTTOM_LEFT); + g.draw_blocking_text(&self.osd, ezgui::BOTTOM_LEFT); None } } diff --git a/docs/design/notes/tutorial.md b/docs/design/notes/tutorial.md index 654871b5be..1d3a9aedde 100644 --- a/docs/design/notes/tutorial.md +++ b/docs/design/notes/tutorial.md @@ -237,3 +237,22 @@ other modes... maybe top menu changes by the mode! some stuff could be common (debug plugins?) + +Forget top menu, modal menu, OSD, right-click menus, all the current GUI things. Start over from each mode -- how should it work ideally? +- how do we indicate what major mode we're in and explain how to get out? top menu? + +- tutorial mode +- challenge creation mode + - manage neighborhoods and scenarios + - how should the main functions be chosen? load/save neighborhood/scenario +- interactive sandbox mode + - spawn traffic + - maybe choose the spawn tool, then can select a building or intersection or road? + - dont even allow selection of things that dont make sense + - persistent (but maybe hideable?) controls for sim, OSD showing time and agent count and stuff +- map edit mode + - this makes sense as a separate thing, to visualize the edits and make sure to save them + - and to make it clear that there's no mixing with a running sim + - but how fluidly should this be enterable from the sandbox mode? +- debug mode + - stuff like tooltips, warp, search only belong here... until i make more generally usable navigation tools diff --git a/editor/src/main.rs b/editor/src/main.rs index a5b85f3753..e08ecb9d33 100644 --- a/editor/src/main.rs +++ b/editor/src/main.rs @@ -163,7 +163,10 @@ impl GUI for GameState { txt.add_line("Great! Press ENTER to continue.".to_string()); } // TODO Get rid of top menu and OSD and then put this somewhere more sensible. :) - g.draw_blocking_text(txt, (HorizontalAlignment::Right, VerticalAlignment::Center)); + g.draw_blocking_text( + &txt, + (HorizontalAlignment::Right, VerticalAlignment::Center), + ); None } Mode::TutorialPart2(orig_cam_zoom) => { @@ -174,7 +177,10 @@ impl GUI for GameState { txt.add_line("".to_string()); txt.add_line("Great! Press ENTER to continue.".to_string()); } - g.draw_blocking_text(txt, (HorizontalAlignment::Right, VerticalAlignment::Center)); + g.draw_blocking_text( + &txt, + (HorizontalAlignment::Right, VerticalAlignment::Center), + ); None } } diff --git a/editor/src/plugins/debug/debug_objects.rs b/editor/src/plugins/debug/debug_objects.rs index 1fb46933cf..42bea61ed8 100644 --- a/editor/src/plugins/debug/debug_objects.rs +++ b/editor/src/plugins/debug/debug_objects.rs @@ -49,7 +49,7 @@ impl AmbientPlugin for DebugObjectsState { if self.tooltip_key_held { if let Some(id) = self.selected { let txt = id.tooltip_lines(g, ctx); - g.draw_mouse_tooltip(txt); + g.draw_mouse_tooltip(&txt); } } @@ -59,7 +59,7 @@ impl AmbientPlugin for DebugObjectsState { let mut txt = Text::new(); txt.add_line(format!("{}", pt)); txt.add_line(format!("{}", gps)); - g.draw_mouse_tooltip(txt); + g.draw_mouse_tooltip(&txt); } } } diff --git a/editor/src/plugins/debug/debug_polygon.rs b/editor/src/plugins/debug/debug_polygon.rs index d2ed5145b8..961b330ff5 100644 --- a/editor/src/plugins/debug/debug_polygon.rs +++ b/editor/src/plugins/debug/debug_polygon.rs @@ -140,21 +140,21 @@ impl BlockingPlugin for DebugPolygon { fn draw(&self, g: &mut GfxCtx, ctx: &DrawCtx) { match self.items[self.current] { Item::Point(pt) => { - g.draw_text_at(Text::from_line(format!("{}", self.current)), pt); + g.draw_text_at(&Text::from_line(format!("{}", self.current)), pt); } Item::Triangle(ref tri) => { for pt in &[tri.pt1, tri.pt2, tri.pt3] { - g.draw_text_at(Text::from_line(format!("{}", self.current)), *pt); + g.draw_text_at(&Text::from_line(format!("{}", self.current)), *pt); } g.draw_polygon(ctx.cs.get("selected"), &Polygon::from_triangle(tri)); } Item::Polygon(ref poly) => { g.draw_polygon(ctx.cs.get("selected"), poly); - g.draw_text_at(Text::from_line(format!("{}", self.current)), poly.center()); + g.draw_text_at(&Text::from_line(format!("{}", self.current)), poly.center()); } } if let Some(pt) = self.center { - g.draw_text_at(Text::from_line("c".to_string()), pt); + g.draw_text_at(&Text::from_line("c".to_string()), pt); } } } diff --git a/editor/src/plugins/sim/show_score.rs b/editor/src/plugins/sim/show_score.rs index 0dfe748108..87908f0f85 100644 --- a/editor/src/plugins/sim/show_score.rs +++ b/editor/src/plugins/sim/show_score.rs @@ -31,7 +31,7 @@ impl NonblockingPlugin for ShowScoreState { fn draw(&self, g: &mut GfxCtx, _ctx: &DrawCtx) { g.draw_blocking_text( - self.txt.clone(), + &self.txt, (HorizontalAlignment::Right, VerticalAlignment::BelowTopMenu), ); } diff --git a/editor/src/plugins/view/legend.rs b/editor/src/plugins/view/legend.rs index 84e16d8515..eed46a876d 100644 --- a/editor/src/plugins/view/legend.rs +++ b/editor/src/plugins/view/legend.rs @@ -68,7 +68,7 @@ impl NonblockingPlugin for Legend { ctx.cs.get("turns protected by traffic signal right now"), ); g.draw_text_at_screenspace_topleft( - Text::from_line("Protected turn".to_string()), + &Text::from_line("Protected turn".to_string()), ScreenPt::new(self.top_left.x + 20.0, self.top_left.y + 10.0), ); @@ -83,7 +83,7 @@ impl NonblockingPlugin for Legend { .get("turns allowed with yielding by traffic signal right now"), ); g.draw_text_at_screenspace_topleft( - Text::from_line("Yield turn".to_string()), + &Text::from_line("Yield turn".to_string()), ScreenPt::new(self.top_left.x + 20.0, self.top_left.y + 110.0), ); diff --git a/editor/src/plugins/view/neighborhood_summary.rs b/editor/src/plugins/view/neighborhood_summary.rs index d9f327f564..96ddab0c72 100644 --- a/editor/src/plugins/view/neighborhood_summary.rs +++ b/editor/src/plugins/view/neighborhood_summary.rs @@ -78,8 +78,7 @@ impl AmbientPlugin for NeighborhoodSummary { g.redraw(&self.draw_all_regions); for r in &self.regions { - // TODO ezgui should take borrows - g.draw_text_at(r.summary.clone(), r.center); + g.draw_text_at(&r.summary, r.center); } } } diff --git a/editor/src/render/intersection.rs b/editor/src/render/intersection.rs index 2e6cb470a3..00f7646301 100644 --- a/editor/src/render/intersection.rs +++ b/editor/src/render/intersection.rs @@ -375,7 +375,7 @@ pub fn draw_signal_diagram( draw_signal_cycle(&cycle, g, ctx); g.draw_text_at_screenspace_topleft( - txt, + &txt, ScreenPt::new(x1_screen + 10.0 + (intersection_width * zoom), y1), ); } diff --git a/editor/src/ui.rs b/editor/src/ui.rs index 3049352494..869c190d72 100644 --- a/editor/src/ui.rs +++ b/editor/src/ui.rs @@ -315,7 +315,7 @@ impl GUI for UI { abstutil::prettyprint_usize(g.get_num_uploads()), abstutil::prettyprint_usize(g.num_draw_calls), )); - g.draw_blocking_text(osd, BOTTOM_LEFT); + g.draw_blocking_text(&osd, BOTTOM_LEFT); } sample_intersection diff --git a/ezgui/src/drawing.rs b/ezgui/src/drawing.rs index a9d696c1df..22c0deefe3 100644 --- a/ezgui/src/drawing.rs +++ b/ezgui/src/drawing.rs @@ -141,7 +141,7 @@ impl<'a> GfxCtx<'a> { // The text box covers up what's beneath and eats the cursor (for get_cursor_in_map_space). pub fn draw_blocking_text( &mut self, - txt: Text, + txt: &Text, (horiz, vert): (HorizontalAlignment, VerticalAlignment), ) { if txt.is_empty() { @@ -175,7 +175,7 @@ impl<'a> GfxCtx<'a> { } // TODO Rename these draw_nonblocking_text_* - pub fn draw_text_at(&mut self, txt: Text, map_pt: Pt2D) { + pub fn draw_text_at(&mut self, txt: &Text, map_pt: Pt2D) { let (width, height) = self.text_dims(&txt); let pt = self.canvas.map_to_screen(map_pt); text::draw_text_bubble( @@ -190,12 +190,12 @@ impl<'a> GfxCtx<'a> { self.canvas.text_dims(txt) } - pub fn draw_text_at_screenspace_topleft(&mut self, txt: Text, pt: ScreenPt) { + pub fn draw_text_at_screenspace_topleft(&mut self, txt: &Text, pt: ScreenPt) { let dims = self.text_dims(&txt); text::draw_text_bubble(self, pt, txt, dims); } - pub fn draw_mouse_tooltip(&mut self, txt: Text) { + pub fn draw_mouse_tooltip(&mut self, txt: &Text) { let (width, height) = self.text_dims(&txt); let x1 = self.canvas.cursor_x - (width / 2.0); let y1 = self.canvas.cursor_y - (height / 2.0); diff --git a/ezgui/src/runner.rs b/ezgui/src/runner.rs index 867e951e69..f7a76982fe 100644 --- a/ezgui/src/runner.rs +++ b/ezgui/src/runner.rs @@ -230,7 +230,7 @@ pub fn run G>( let mut target = display.draw(); let mut g = GfxCtx::new(&canvas, &prerender, &mut target, &program); g.draw_blocking_text( - Text::from_line("Loading... Check terminal for details".to_string()), + &Text::from_line("Loading... Check terminal for details".to_string()), (HorizontalAlignment::Center, VerticalAlignment::Center), ); canvas diff --git a/ezgui/src/text.rs b/ezgui/src/text.rs index 651dc2abeb..1f7a7fa852 100644 --- a/ezgui/src/text.rs +++ b/ezgui/src/text.rs @@ -146,7 +146,7 @@ impl Text { pub fn draw_text_bubble( g: &mut GfxCtx, top_left: ScreenPt, - txt: Text, + txt: &Text, // Callers almost always calculate this anyway (total_width, total_height): (f64, f64), ) -> ScreenRectangle { diff --git a/ezgui/src/widgets/log_scroller.rs b/ezgui/src/widgets/log_scroller.rs index c25a10a6d0..632624f82f 100644 --- a/ezgui/src/widgets/log_scroller.rs +++ b/ezgui/src/widgets/log_scroller.rs @@ -34,6 +34,6 @@ impl LogScroller { } pub fn draw(&self, g: &mut GfxCtx) { - g.draw_blocking_text(self.text.clone(), CENTERED); + g.draw_blocking_text(&self.text, CENTERED); } } diff --git a/ezgui/src/widgets/menu.rs b/ezgui/src/widgets/menu.rs index 40c7c08db7..98fd39a2cf 100644 --- a/ezgui/src/widgets/menu.rs +++ b/ezgui/src/widgets/menu.rs @@ -230,7 +230,7 @@ impl Menu { x2: self.first_choice_row.x2, y2: self.top_left.y + (self.row_height * (txt.num_lines() as f64)), }); - g.draw_text_at_screenspace_topleft(txt, self.top_left); + g.draw_text_at_screenspace_topleft(&txt, self.top_left); } pub fn current_choice(&self) -> Option<&T> { diff --git a/ezgui/src/widgets/scrolling_menu.rs b/ezgui/src/widgets/scrolling_menu.rs index 0953edee52..39f8ff8447 100644 --- a/ezgui/src/widgets/scrolling_menu.rs +++ b/ezgui/src/widgets/scrolling_menu.rs @@ -62,7 +62,7 @@ impl ScrollingMenu { let n = (g.canvas.window_height / g.canvas.line_height).floor() as isize - 1 - 6; if n <= 0 { // Weird small window, just display the prompt and bail out. - g.draw_blocking_text(txt, CENTERED); + g.draw_blocking_text(&txt, CENTERED); return; } n as usize @@ -90,7 +90,7 @@ impl ScrollingMenu { } } - g.draw_blocking_text(txt, CENTERED); + g.draw_blocking_text(&txt, CENTERED); } pub fn current_choice(&self) -> &T { diff --git a/ezgui/src/widgets/text_box.rs b/ezgui/src/widgets/text_box.rs index 9a78a53e5e..f9f4e9be6b 100644 --- a/ezgui/src/widgets/text_box.rs +++ b/ezgui/src/widgets/text_box.rs @@ -36,7 +36,7 @@ impl TextBox { txt.append("|".to_string(), Some(text::SELECTED_COLOR)); } - g.draw_blocking_text(txt, CENTERED); + g.draw_blocking_text(&txt, CENTERED); } pub fn event(&mut self, input: &mut UserInput) -> InputResult<()> { diff --git a/ezgui/src/widgets/top_menu.rs b/ezgui/src/widgets/top_menu.rs index fd0cc44c97..db5f4e695b 100644 --- a/ezgui/src/widgets/top_menu.rs +++ b/ezgui/src/widgets/top_menu.rs @@ -147,7 +147,7 @@ impl TopMenu { None }); txt.add_line(f.name.to_string()); - g.draw_text_at_screenspace_topleft(txt, ScreenPt::new(f.rectangle.x1, f.rectangle.y1)); + g.draw_text_at_screenspace_topleft(&txt, ScreenPt::new(f.rectangle.x1, f.rectangle.y1)); } if let Some((_, ref menu)) = self.submenu { diff --git a/playground_gui/src/main.rs b/playground_gui/src/main.rs index 5139bc18b2..fa04753bcd 100644 --- a/playground_gui/src/main.rs +++ b/playground_gui/src/main.rs @@ -120,7 +120,7 @@ impl GUI for UI { if self.show_labels { for (pt, label) in labels.into_iter() { - g.draw_text_at(Text::from_line(label), pt); + g.draw_text_at(&Text::from_line(label), pt); } } None diff --git a/synthetic/src/lib.rs b/synthetic/src/lib.rs index 63bd299736..041e55ecba 100644 --- a/synthetic/src/lib.rs +++ b/synthetic/src/lib.rs @@ -123,13 +123,13 @@ impl Road { if let Some(ref label) = self.fwd_label { g.draw_text_at( - Text::from_line(label.to_string()), + &Text::from_line(label.to_string()), self.polygon(FORWARDS, model).center(), ); } if let Some(ref label) = self.back_label { g.draw_text_at( - Text::from_line(label.to_string()), + &Text::from_line(label.to_string()), self.polygon(BACKWARDS, model).center(), ); } @@ -226,7 +226,7 @@ impl Model { g.draw_circle(color, &i.circle()); if let Some(ref label) = i.label { - g.draw_text_at(Text::from_line(label.to_string()), i.center); + g.draw_text_at(&Text::from_line(label.to_string()), i.center); } } @@ -240,7 +240,7 @@ impl Model { g.draw_polygon(color, &b.polygon()); if let Some(ref label) = b.label { - g.draw_text_at(Text::from_line(label.to_string()), b.center); + g.draw_text_at(&Text::from_line(label.to_string()), b.center); } } } diff --git a/synthetic/src/main.rs b/synthetic/src/main.rs index a07533110b..9e14fad8d6 100644 --- a/synthetic/src/main.rs +++ b/synthetic/src/main.rs @@ -231,7 +231,7 @@ impl GUI for UI { _ => {} }; - g.draw_blocking_text(self.osd.clone(), ezgui::BOTTOM_LEFT); + g.draw_blocking_text(&self.osd, ezgui::BOTTOM_LEFT); None } } diff --git a/viewer/src/lib.rs b/viewer/src/lib.rs index 4d003e5bb2..7c33729565 100644 --- a/viewer/src/lib.rs +++ b/viewer/src/lib.rs @@ -46,7 +46,7 @@ impl World { pub fn draw_selected(&self, g: &mut GfxCtx, id: ID) { let obj = &self.objects[&id]; g.draw_polygon(Color::BLUE, &obj.polygon); - g.draw_mouse_tooltip(obj.info.clone()); + g.draw_mouse_tooltip(&obj.info); } pub fn mouseover_something(&self, ctx: &EventCtx, hide: &HashSet) -> Option {