pub(crate) fn new_space(&self, universe: &mut Universe, hud_blocks: &HudBlocks) -> URef<Space> {
        let Vector2 { x: w, y: h } = self.size;
        let grid = self.grid();
        let mut space = Space::empty(grid);

        space.set_physics(SpacePhysics {
            sky_color: palette::HUD_SKY,
            ..SpacePhysics::default()
        });

        if false {
            // Visualization of the bounds of the space we're drawing.
            let mut add_frame = |z, color| {
                let frame_block = Block::from(color);
                space
                    .fill_uniform(Grid::new((0, 0, z), (w, h, 1)), frame_block)
                    .unwrap();
                space
                    .fill_uniform(Grid::new((1, 1, z), (w - 2, h - 2, 1)), &AIR)
                    .unwrap();
            };
            add_frame(grid.lower_bounds().z, Rgba::new(0.5, 0., 0., 1.));
            add_frame(-1, Rgba::new(0.5, 0.5, 0.5, 1.));
            add_frame(grid.upper_bounds().z - 1, Rgba::new(0., 1., 1., 1.));
        }

        // Draw background for toolbar.
        let toolbar_disp = &mut space.draw_target(GridMatrix::from_origin(
            self.tool_icon_position(0),
            Face::PX,
            Face::NY,
            Face::PZ,
        ));
        Pixel(Point::new(-1, 0), &hud_blocks.toolbar_left_cap)
            .draw(toolbar_disp)
            .unwrap();
        Pixel(
            Point::new((self.toolbar_positions as i32 - 1) * TOOLBAR_STEP + 1, 0),
            &hud_blocks.toolbar_right_cap,
        )
        .draw(toolbar_disp)
        .unwrap();
        for index in 0..self.toolbar_positions {
            let x = index as i32 * TOOLBAR_STEP;
            Pixel(Point::new(x, 0), &hud_blocks.toolbar_middle)
                .draw(toolbar_disp)
                .unwrap();
            if index > 0 {
                Pixel(Point::new(x - 1, 0), &hud_blocks.toolbar_divider)
                    .draw(toolbar_disp)
                    .unwrap();
            }
        }

        // Set up toolbar info text space
        let frame = self.toolbar_text_frame();
        let mut toolbar_text_space = Space::empty(Grid::new(
            GridPoint::origin(),
            GridVector::new(
                frame.size().x * GridCoordinate::from(self.text_resolution()),
                frame.size().y * GridCoordinate::from(self.text_resolution()),
                2,
            ),
        ));
        toolbar_text_space.set_physics(SpacePhysics::DEFAULT_FOR_BLOCK);
        let toolbar_text_blocks = space_to_blocks(
            self.text_resolution(),
            BlockAttributes::default(),
            universe.insert_anonymous(toolbar_text_space),
        )
        .unwrap();
        debug_assert_eq!(toolbar_text_blocks.grid().size(), frame.size());
        space
            .fill(frame, |p| {
                Some(&toolbar_text_blocks[p - frame.lower_bounds().to_vec()])
            })
            .unwrap();

        universe.insert_anonymous(space)
    }
// TODO: taking the entire Universe doesn't seem like the best interface
// but we want room to set up new blocks. Figure out a route for that.
// TODO: validate this doesn't crash on wonky sizes.
taking the entire Universe doesn't seem like the best interface
but we want room to set up new blocks. Figure out a route for that.
TODO: validate this doesn't crash on wonky sizes.
taking the entire Universe doesn ' t seem like the best interface but we want room to set up new blocks . Figure out a route for that . TODO : validate this doesn ' t crash on wonky sizes .
pub(crate) fn new_space(&self, universe: &mut Universe, hud_blocks: &HudBlocks) -> URef<Space> {
        let Vector2 { x: w, y: h } = self.size;
        let grid = self.grid();
        let mut space = Space::empty(grid);
        space.set_physics(SpacePhysics {
            sky_color: palette::HUD_SKY,
            ..SpacePhysics::default()
        });
        if false {
            // Visualization of the bounds of the space we're drawing.
            let mut add_frame = |z, color| {
                let frame_block = Block::from(color);
                space
                    .fill_uniform(Grid::new((0, 0, z), (w, h, 1)), frame_block)
                    .unwrap();
                space
                    .fill_uniform(Grid::new((1, 1, z), (w - 2, h - 2, 1)), &AIR)
                    .unwrap();
            };
            add_frame(grid.lower_bounds().z, Rgba::new(0.5, 0., 0., 1.));
            add_frame(-1, Rgba::new(0.5, 0.5, 0.5, 1.));
            add_frame(grid.upper_bounds().z - 1, Rgba::new(0., 1., 1., 1.));
        }
        // Draw background for toolbar.
        let toolbar_disp = &mut space.draw_target(GridMatrix::from_origin(
            self.tool_icon_position(0),
            Face::PX,
            Face::NY,
            Face::PZ,
        ));
        Pixel(Point::new(-1, 0), &hud_blocks.toolbar_left_cap)
            .draw(toolbar_disp)
            .unwrap();
        Pixel(
            Point::new((self.toolbar_positions as i32 - 1) * TOOLBAR_STEP + 1, 0),
            &hud_blocks.toolbar_right_cap,
        )
        .draw(toolbar_disp)
        .unwrap();
        for index in 0..self.toolbar_positions {
            let x = index as i32 * TOOLBAR_STEP;
            Pixel(Point::new(x, 0), &hud_blocks.toolbar_middle)
                .draw(toolbar_disp)
                .unwrap();
            if index > 0 {
                Pixel(Point::new(x - 1, 0), &hud_blocks.toolbar_divider)
                    .draw(toolbar_disp)
                    .unwrap();
            }
        }
        // Set up toolbar info text space
        let frame = self.toolbar_text_frame();
        let mut toolbar_text_space = Space::empty(Grid::new(
            GridPoint::origin(),
            GridVector::new(
                frame.size().x * GridCoordinate::from(self.text_resolution()),
                frame.size().y * GridCoordinate::from(self.text_resolution()),
                2,
            ),
        ));
        toolbar_text_space.set_physics(SpacePhysics::DEFAULT_FOR_BLOCK);
        let toolbar_text_blocks = space_to_blocks(
            self.text_resolution(),
            BlockAttributes::default(),
            universe.insert_anonymous(toolbar_text_space),
        )
        .unwrap();
        debug_assert_eq!(toolbar_text_blocks.grid().size(), frame.size());
        space
            .fill(frame, |p| {
                Some(&toolbar_text_blocks[p - frame.lower_bounds().to_vec()])
            })
            .unwrap();
        universe.insert_anonymous(space)
    }
pub ( crate ) fn new_space ( & self , universe : & mut Universe , hud_blocks : & HudBlocks ) -> URef < Space > { let Vector2 { x : w , y : h } = self . size ; let grid = self . grid ( ) ; let mut space = Space :: empty ( grid ) ; space . set_physics ( SpacePhysics { sky_color : palette :: HUD_SKY , .. SpacePhysics :: default ( ) } ) ; if false { // Visualization of the bounds of the space we're drawing. let mut add_frame = | z , color | { let frame_block = Block :: from ( color ) ; space . fill_uniform ( Grid :: new ( ( 0 , 0 , z ) , ( w , h , 1 ) ) , frame_block ) . unwrap ( ) ; space . fill_uniform ( Grid :: new ( ( 1 , 1 , z ) , ( w - 2 , h - 2 , 1 ) ) , & AIR ) . unwrap ( ) ; } ; add_frame ( grid . lower_bounds ( ) . z , Rgba :: new ( 0.5 , 0. , 0. , 1. ) ) ; add_frame ( - 1 , Rgba :: new ( 0.5 , 0.5 , 0.5 , 1. ) ) ; add_frame ( grid . upper_bounds ( ) . z - 1 , Rgba :: new ( 0. , 1. , 1. , 1. ) ) ; } // Draw background for toolbar. let toolbar_disp = & mut space . draw_target ( GridMatrix :: from_origin ( self . tool_icon_position ( 0 ) , Face :: PX , Face :: NY , Face :: PZ , ) ) ; Pixel ( Point :: new ( - 1 , 0 ) , & hud_blocks . toolbar_left_cap ) . draw ( toolbar_disp ) . unwrap ( ) ; Pixel ( Point :: new ( ( self . toolbar_positions as i32 - 1 ) * TOOLBAR_STEP + 1 , 0 ) , & hud_blocks . toolbar_right_cap , ) . draw ( toolbar_disp ) . unwrap ( ) ; for index in 0 .. self . toolbar_positions { let x = index as i32 * TOOLBAR_STEP ; Pixel ( Point :: new ( x , 0 ) , & hud_blocks . toolbar_middle ) . draw ( toolbar_disp ) . unwrap ( ) ; if index > 0 { Pixel ( Point :: new ( x - 1 , 0 ) , & hud_blocks . toolbar_divider ) . draw ( toolbar_disp ) . unwrap ( ) ; } } // Set up toolbar info text space let frame = self . toolbar_text_frame ( ) ; let mut toolbar_text_space = Space :: empty ( Grid :: new ( GridPoint :: origin ( ) , GridVector :: new ( frame . size ( ) . x * GridCoordinate :: from ( self . text_resolution ( ) ) , frame . size ( ) . y * GridCoordinate :: from ( self . text_resolution ( ) ) , 2 , ) , ) ) ; toolbar_text_space . set_physics ( SpacePhysics :: DEFAULT_FOR_BLOCK ) ; let toolbar_text_blocks = space_to_blocks ( self . text_resolution ( ) , BlockAttributes :: default ( ) , universe . insert_anonymous ( toolbar_text_space ) , ) . unwrap ( ) ; debug_assert_eq ! ( toolbar_text_blocks grid ( ) size ( ) frame size ( ) ) ; space . fill ( frame , | p | { Some ( & toolbar_text_blocks [ p - frame . lower_bounds ( ) . to_vec ( ) ] ) } ) . unwrap ( ) ; universe . insert_anonymous ( space ) }
TODO: taking the entire Universe doesn't seem like the best interface
but we want room to set up new blocks.
TODO : taking the entire Universe doesn ' t seem like the best interface but we want room to set up new blocks .
&self
universe
&mut Universe
hud_blocks
&HudBlocks