mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-26 16:02:23 +03:00
clean up ezgui runner API
This commit is contained in:
parent
669fd886d5
commit
4b1107bf57
@ -73,7 +73,7 @@ impl GUI<Text> for UI {
|
||||
(EventLoopMode::InputOnly, osd)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, osd: &Text) {
|
||||
fn draw(&self, g: &mut GfxCtx, osd: &Text, _screencap: bool) -> Option<String> {
|
||||
g.clear(Color::WHITE);
|
||||
|
||||
self.world.draw(g, &self.hide);
|
||||
@ -83,6 +83,7 @@ impl GUI<Text> for UI {
|
||||
}
|
||||
|
||||
g.draw_blocking_text(osd.clone(), ezgui::BOTTOM_LEFT);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -186,3 +186,10 @@ Almost done organizing plugins. For the last stretch, I think I need to solve a
|
||||
Callbacks get so confusing. How about SimMode just exposes the most recent
|
||||
events, and other things can reach in and query. They're responsible for not
|
||||
double-counting.
|
||||
|
||||
## Overall loop / splash screen
|
||||
|
||||
I don't really want the top menu active at all during the splash screen.
|
||||
Probably have to make each application own this state instead, which I
|
||||
suspected from early on. :) But UserInput is very entangled with stuff,
|
||||
probably hard to do right now.
|
||||
|
@ -40,6 +40,10 @@ pub struct Flags {
|
||||
/// Number of agents to generate when small_spawn called
|
||||
#[structopt(long = "num_agents", default_value = "100")]
|
||||
pub num_agents: usize,
|
||||
|
||||
/// Start with the splash screen and menu
|
||||
#[structopt(long = "splash")]
|
||||
pub splash: bool,
|
||||
}
|
||||
|
||||
pub trait UIState {
|
||||
|
@ -263,9 +263,7 @@ impl<S: UIState> GUI<RenderingHints> for UI<S> {
|
||||
(hints.mode.clone(), hints)
|
||||
}
|
||||
|
||||
fn draw(&self, _: &mut GfxCtx, _: &RenderingHints) {}
|
||||
|
||||
fn new_draw(&self, g: &mut GfxCtx, hints: &RenderingHints, screencap: bool) -> Option<String> {
|
||||
fn draw(&self, g: &mut GfxCtx, hints: &RenderingHints, screencap: bool) -> Option<String> {
|
||||
let state = self.state.get_state();
|
||||
|
||||
let ctx = DrawCtx {
|
||||
|
@ -23,13 +23,8 @@ pub trait GUI<T> {
|
||||
Vec::new()
|
||||
}
|
||||
fn event(&mut self, ctx: EventCtx) -> (EventLoopMode, T);
|
||||
// TODO Migrate all callers
|
||||
fn draw(&self, g: &mut GfxCtx, data: &T);
|
||||
// Return optional naming hint for screencap. TODO This API is getting gross.
|
||||
fn new_draw(&self, g: &mut GfxCtx, data: &T, _screencap: bool) -> Option<String> {
|
||||
self.draw(g, data);
|
||||
None
|
||||
}
|
||||
fn draw(&self, g: &mut GfxCtx, data: &T, _screencap: bool) -> Option<String>;
|
||||
// Will be called if event or draw panics.
|
||||
fn dump_before_abort(&self, _canvas: &Canvas) {}
|
||||
// Only before a normal exit, like window close
|
||||
@ -136,7 +131,7 @@ impl<T, G: GUI<T>> State<T, G> {
|
||||
self.canvas.start_drawing();
|
||||
|
||||
if let Err(err) = panic::catch_unwind(panic::AssertUnwindSafe(|| {
|
||||
naming_hint = self.gui.new_draw(&mut g, data, screenshot);
|
||||
naming_hint = self.gui.draw(&mut g, data, screenshot);
|
||||
})) {
|
||||
self.gui.dump_before_abort(&self.canvas);
|
||||
panic::resume_unwind(err);
|
||||
|
@ -58,8 +58,9 @@ impl GUI<()> for UI {
|
||||
(EventLoopMode::Animation, ())
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, _: &()) {
|
||||
fn draw(&self, g: &mut GfxCtx, _: &(), _screencap: bool) -> Option<String> {
|
||||
self.draw_map.draw(g, self.cycler.value());
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ pub fn make_bus_stops(
|
||||
.cloned()
|
||||
.collect();
|
||||
if stops.len() < 2 {
|
||||
if stops.len() > 0 {
|
||||
if !stops.is_empty() {
|
||||
timer.warn(format!(
|
||||
"Skipping route {} since it only has {} stop in the slice of the map",
|
||||
route_name,
|
||||
|
@ -101,7 +101,7 @@ impl GUI<()> for UI {
|
||||
(EventLoopMode::InputOnly, ())
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, _: &()) {
|
||||
fn draw(&self, g: &mut GfxCtx, _: &(), _screencap: bool) -> Option<String> {
|
||||
g.clear(common::WHITE);
|
||||
|
||||
let mut labels: Vec<(Pt2D, String)> = Vec::new();
|
||||
@ -123,6 +123,7 @@ impl GUI<()> for UI {
|
||||
g.draw_text_at(Text::from_line(label), pt);
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -206,7 +206,7 @@ impl GUI<Text> for UI {
|
||||
(EventLoopMode::InputOnly, osd)
|
||||
}
|
||||
|
||||
fn draw(&self, g: &mut GfxCtx, osd: &Text) {
|
||||
fn draw(&self, g: &mut GfxCtx, osd: &Text, _screencap: bool) -> Option<String> {
|
||||
self.model.draw(g, self.quadtree.as_ref());
|
||||
|
||||
match self.state {
|
||||
@ -230,6 +230,7 @@ impl GUI<Text> for UI {
|
||||
};
|
||||
|
||||
g.draw_blocking_text(osd.clone(), ezgui::BOTTOM_LEFT);
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user