Add a set_next method on OamIterator (#664)

It was annoying me how often I had to write this

- [x] Changelog updated
This commit is contained in:
Gwilym Inzani 2024-04-30 21:28:07 +01:00 committed by GitHub
commit 6049593aa7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
your rustflags field. This can also be disabled by removing the `backtrace` feature.
- Initial unicode support for font rendering.
- Kerning support for font rendering.
- Added `set_next` method to `OamIterator` to avoid repeated boilerplate when dealing with unmanaged objects.
### Fixed

View file

@ -71,6 +71,27 @@ pub struct OamIterator<'oam> {
frame_data: &'oam UnsafeCell<OamFrameModifyables>,
}
impl<'oam> OamIterator<'oam> {
/// Sets the next oam slot with the provided `object`.
///
/// Is equivalent to the following:
/// ```no_run
/// # #![no_main]
/// # #![no_std]
/// # use agb::display::object::{OamIterator, ObjectUnmanaged};
/// # fn set_next_example(oam_iterator: &mut OamIterator, object: &ObjectUnmanaged) {
/// if let Some(slot) = oam_iterator.next() {
/// slot.set(object);
/// }
/// # }
/// ```
pub fn set_next(&mut self, object: &ObjectUnmanaged) {
if let Some(slot) = self.next() {
slot.set(object);
}
}
}
/// A slot in Oam that you can write to. Note that you must call [OamSlot::set]
/// or else it is a bug and will panic when dropped.
///