From 37e9fe50660d4cddb89a92f47b0f239c61b633eb Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 30 Apr 2024 20:39:50 +0100 Subject: [PATCH 1/3] Add a set_next method on OamIterator --- agb/src/display/object/unmanaged/object.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/agb/src/display/object/unmanaged/object.rs b/agb/src/display/object/unmanaged/object.rs index 9059f4ca..b4badab9 100644 --- a/agb/src/display/object/unmanaged/object.rs +++ b/agb/src/display/object/unmanaged/object.rs @@ -71,6 +71,27 @@ pub struct OamIterator<'oam> { frame_data: &'oam UnsafeCell, } +impl<'oam> OamIterator<'oam> { + /// Sets the next oam slot with the provided `object`. + /// + /// Is equivalent to the following: + /// ```rust + /// # #![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. /// From 609e55155bd7ce20ca4940e76588e3164ae66703 Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 30 Apr 2024 20:41:01 +0100 Subject: [PATCH 2/3] Add changelog entry for set_next --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8d9524d..00d65835 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 8ede32ea7bfebb1ea89fa8d2a839b3aaa50d380c Mon Sep 17 00:00:00 2001 From: Gwilym Inzani Date: Tue, 30 Apr 2024 20:53:06 +0100 Subject: [PATCH 3/3] Mark the test as no_run rather than rust --- agb/src/display/object/unmanaged/object.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agb/src/display/object/unmanaged/object.rs b/agb/src/display/object/unmanaged/object.rs index b4badab9..bcc36a4e 100644 --- a/agb/src/display/object/unmanaged/object.rs +++ b/agb/src/display/object/unmanaged/object.rs @@ -75,7 +75,7 @@ impl<'oam> OamIterator<'oam> { /// Sets the next oam slot with the provided `object`. /// /// Is equivalent to the following: - /// ```rust + /// ```no_run /// # #![no_main] /// # #![no_std] /// # use agb::display::object::{OamIterator, ObjectUnmanaged};