diff --git a/agb/src/display/window.rs b/agb/src/display/window.rs index 87a5ffe7..92c5ef7e 100644 --- a/agb/src/display/window.rs +++ b/agb/src/display/window.rs @@ -2,7 +2,7 @@ use agb_fixnum::Rect; use crate::memory_mapped::MemoryMapped; -use super::{tiled::BackgroundID, DISPLAY_CONTROL}; +use super::{tiled::BackgroundID, DISPLAY_CONTROL, HEIGHT, WIDTH}; pub struct Windows { wins: [MovableWindow; 2], @@ -188,7 +188,11 @@ impl MovableWindow { pub fn set_position(&mut self, rect: &Rect) -> &mut Self { let new_rect = Rect::new( - (rect.position.x as u8, rect.position.y as u8).into(), + ( + rect.position.x.clamp(0, WIDTH) as u8, + rect.position.y.clamp(0, HEIGHT) as u8, + ) + .into(), (rect.size.x as u8, rect.size.y as u8).into(), ); self.set_position_u8(new_rect)