add Image::fill

This commit is contained in:
bendn 2023-12-06 07:45:14 +07:00
parent 5839881e25
commit b7c91274c1
No known key found for this signature in database
GPG key ID: 0D9D3A2A3B2A93D6
2 changed files with 15 additions and 1 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "fimg" name = "fimg"
version = "0.4.28" version = "0.4.29"
authors = ["bend-n <bend.n@outlook.com>"] authors = ["bend-n <bend.n@outlook.com>"]
license = "MIT" license = "MIT"
edition = "2021" edition = "2021"

View file

@ -61,6 +61,20 @@ impl<const C: usize> Builder<Vec<u8>, C> {
} }
} }
impl<T: Copy, const C: usize> Builder<Box<[T]>, C> {
/// Fill this image with a certain pixel.
/// ```
/// # use fimg::Image;
///
/// // fill black
/// Image::build(50, 50).fill([0, 0, 0, 255]);
/// ```
pub fn fill(self, with: [T; C]) -> Image<Box<[T]>, C> {
Image::build(self.width, self.height)
.buf((0..self.width * self.height).flat_map(|_| with).collect())
}
}
/// seals the [`Buffer`] trait /// seals the [`Buffer`] trait
mod buf { mod buf {
/// A valid buffer for use in the builder /// A valid buffer for use in the builder