From 9d70f1598dde72e4de8628d9474883cd56065a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cel=20=F0=9F=8C=B8?= Date: Wed, 2 Nov 2022 00:51:06 +0000 Subject: [PATCH] work on cowgen --- cowgen/Cargo.toml | 1 + cowgen/src/lib.rs | 80 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/cowgen/Cargo.toml b/cowgen/Cargo.toml index e6a101d..59fad44 100644 --- a/cowgen/Cargo.toml +++ b/cowgen/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +ril = { version = "0", features = ["all"] } diff --git a/cowgen/src/lib.rs b/cowgen/src/lib.rs index 1b4a90c..6b12b65 100644 --- a/cowgen/src/lib.rs +++ b/cowgen/src/lib.rs @@ -1,3 +1,83 @@ +use ril::prelude::*; +use std::fs::File; + +struct Template> { + elements: Vec>, + dimensions: (u32, u32), + base: Image, +} + +impl> Template { + pub fn new(elements: Vec>) -> Self { + Self { + elements, + } + } + + pub fn produce(self, image: File) -> Result { + for element in self.elements { + + image.draw + } + } +} + +struct Element> { + position: (i32, i32), + dimensions: (u32, u32), + media: Media, +} + +impl> Element { + pub fn new(media: Media, position: (i32, i32), dimensions: (u32, u32)) -> Self { + Self { + position, + dimensions, + media, + } + } +} + +impl> Into for Element { + pub fn into(self) -> Image { + match self.media { + Media::Image(image) => { + image.resized(self.dimensions.0, self.dimensions.1, ResizeAlgorithm::Bicubic) + }, + Media::Text(text) => { + Image::new(self.dimensions.0, self.dimensions.1, Rgba::transparent()) + .with(TextSegment::new(text.font, text.text, Rgb::new(text.fill.0, text.fill.1, text.fill.2)) + .with_size(text.size)) + }, + } + } +} + +pub enum Media> { + Text(Text), + Image(Image), +} + +struct Text> { + text: T, + font: File, + size: f32, + fill: (u8, u8, u8), +} + +impl> Text { + pub fn new(contents: T, font: File, size: f32, fill: (u8, u8, u8)) -> Self { + Self { + contents, + font, + size, + fill, + } + } +} + + + #[cfg(test)] mod tests { #[test]