make UI generic over UIState

This commit is contained in:
Dustin Carlino 2018-12-13 14:26:12 -08:00
parent 28327b4905
commit bb71418fd3
2 changed files with 7 additions and 8 deletions

View File

@ -33,7 +33,7 @@ fn main() {
.start("./profile")
.unwrap();*/
ezgui::run(
ui::UI::new(flags.sim_flags, flags.kml),
ui::UI::<state::DefaultUIState>::new(flags.sim_flags, flags.kml),
"A/B Street",
1024,
768,

View File

@ -17,14 +17,13 @@ use std::process;
const MIN_ZOOM_FOR_MOUSEOVER: f64 = 4.0;
pub struct UI {
// TODO Use generics instead
state: Box<UIState>,
pub struct UI<S: UIState> {
state: S,
canvas: Canvas,
cs: ColorScheme,
}
impl GUI<RenderingHints> for UI {
impl<S: UIState> GUI<RenderingHints> for UI<S> {
fn event(&mut self, mut input: UserInput) -> (EventLoopMode, RenderingHints) {
let mut hints = RenderingHints {
mode: EventLoopMode::InputOnly,
@ -166,10 +165,10 @@ impl PerMapUI {
}
}
impl UI {
pub fn new(flags: SimFlags, kml: Option<String>) -> UI {
impl<S: UIState> UI<S> {
pub fn new(flags: SimFlags, kml: Option<String>) -> UI<DefaultUIState> {
let canvas = Canvas::new();
let state = Box::new(DefaultUIState::new(flags, kml, &canvas));
let state = DefaultUIState::new(flags, kml, &canvas);
let mut ui = UI {
state,