render: add api for setting the rectangle on a surface

This commit is contained in:
Victoria Fischer 2024-11-22 15:54:06 +01:00
parent 7b6cf42e4f
commit 73c3ced3d7
2 changed files with 8 additions and 2 deletions

View File

@ -59,6 +59,10 @@ impl Surface for BoundSurface<Rc<RefCell<ShaderBinding>>> {
fn clear_shader(&mut self) { fn clear_shader(&mut self) {
self.binding.borrow_mut().shader = None; self.binding.borrow_mut().shader = None;
} }
fn set_rect(&mut self, rect: &Rectangle<u8, Virtual>) {
self.binding.borrow_mut().rect = rect.clone();
}
} }
#[cfg(feature="threads")] #[cfg(feature="threads")]
@ -132,8 +136,9 @@ impl<S: Surface + Default> SurfacePool<S> {
} }
impl<S: Surface + Default> Surfaces<S> for SurfacePool<S> { impl<S: Surface + Default> Surfaces<S> for SurfacePool<S> {
fn new_surface(&mut self, _area: &Rectangle<u8, Virtual>) -> Result<S, io::Error> { fn new_surface(&mut self, area: &Rectangle<u8, Virtual>) -> Result<S, io::Error> {
let surface = S::default(); let mut surface = S::default();
surface.set_rect(area);
self.surfaces.push(surface.clone()); self.surfaces.push(surface.clone());
return Ok(surface); return Ok(surface);
} }

View File

@ -22,6 +22,7 @@ pub trait Surface: Default + Clone + Debug {
fn clear_shader(&mut self); fn clear_shader(&mut self);
fn rect(&self) -> Rectangle<u8, Virtual>; fn rect(&self) -> Rectangle<u8, Virtual>;
fn set_rect(&mut self, rect: &Rectangle<u8, Virtual>);
} }
pub trait Framed { pub trait Framed {