Add a commit method for text_render

This commit is contained in:
Gwilym Kuiper 2022-04-07 23:01:01 +01:00
parent 5701667f53
commit dc4ccee451
2 changed files with 10 additions and 2 deletions

View file

@ -42,6 +42,8 @@ fn main(mut gba: agb::Gba) -> ! {
writeln!(&mut writer, "Hello, World!").unwrap();
writeln!(&mut writer, "This is a font rendering example").unwrap();
writer.commit();
bg.commit();
bg.show();

View file

@ -142,6 +142,14 @@ impl<'a> Write for TextRenderer<'a> {
self.current_x_pos += letter.advance_width as i32;
}
Ok(())
}
}
impl<'a> TextRenderer<'a> {
pub fn commit(mut self) {
let tiles = core::mem::take(&mut self.tiles);
for ((x, y), tile) in tiles.into_iter() {
self.bg.set_tile(
self.vram_manager,
@ -151,7 +159,5 @@ impl<'a> Write for TextRenderer<'a> {
);
self.vram_manager.remove_dynamic_tile(tile);
}
Ok(())
}
}