From b7c91274c19f04d57853b47743d40a3239923461 Mon Sep 17 00:00:00 2001 From: bendn Date: Wed, 6 Dec 2023 07:45:14 +0700 Subject: [PATCH] add `Image::fill` --- Cargo.toml | 2 +- src/builder.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index a84d271..f9bc1e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "fimg" -version = "0.4.28" +version = "0.4.29" authors = ["bend-n "] license = "MIT" edition = "2021" diff --git a/src/builder.rs b/src/builder.rs index bff5e7c..6ae970e 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -61,6 +61,20 @@ impl Builder, C> { } } +impl Builder, 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, C> { + Image::build(self.width, self.height) + .buf((0..self.width * self.height).flat_map(|_| with).collect()) + } +} + /// seals the [`Buffer`] trait mod buf { /// A valid buffer for use in the builder