removed AsRef<>

This commit is contained in:
emilis 2023-01-07 23:04:33 +00:00
parent 85c2c528a7
commit 6f34278423
1 changed files with 16 additions and 17 deletions

View File

@ -1,13 +1,12 @@
use ril::prelude::*; use ril::prelude::*;
use std::path::Path;
pub struct Generate<T: AsRef<str>, V: AsRef<Path>> { pub struct Generate {
elements: Vec<Element<T, V>>, elements: Vec<Element>,
base: Image<Rgba>, base: Image<Rgba>,
} }
impl<T: AsRef<str>, V: AsRef<Path>> Generate<T, V> { impl Generate {
pub fn new(base: Vec<u8>, elements: Vec<Element<T, V>>) -> Result<Self, CowError> { pub fn new(base: Vec<u8>, elements: Vec<Element>) -> Result<Self, CowError> {
Ok(Self { Ok(Self {
base: Image::<Rgba>::from_bytes_inferred(&base)?, base: Image::<Rgba>::from_bytes_inferred(&base)?,
elements, elements,
@ -38,14 +37,14 @@ impl<T: AsRef<str>, V: AsRef<Path>> Generate<T, V> {
} }
} }
pub struct Element<T: AsRef<str>, V: AsRef<Path>> { pub struct Element {
position: (i32, i32), position: (i32, i32),
dimensions: (u32, u32), dimensions: (u32, u32),
media: Media<T, V>, media: Media,
} }
impl<T: AsRef<str>, V: AsRef<Path>> Element<T, V> { impl Element {
pub fn new(media: Media<T, V>, position: (i32, i32), dimensions: (u32, u32)) -> Self { pub fn new(media: Media, position: (i32, i32), dimensions: (u32, u32)) -> Self {
Self { Self {
position, position,
dimensions, dimensions,
@ -67,7 +66,7 @@ impl<T: AsRef<str>, V: AsRef<Path>> Element<T, V> {
) )
.with( .with(
&TextSegment::new( &TextSegment::new(
&Font::open(text.font, 12.0).unwrap(), &Font::from_bytes(&text.font, 12.0).unwrap(),
text.text, text.text,
Dynamic::Rgba(Rgba::new( Dynamic::Rgba(Rgba::new(
text.fill.0, text.fill.0,
@ -82,20 +81,20 @@ impl<T: AsRef<str>, V: AsRef<Path>> Element<T, V> {
} }
} }
pub enum Media<T: AsRef<str>, V: AsRef<Path>> { pub enum Media {
Text(Text<T, V>), Text(Text),
Image(Vec<u8>), Image(Vec<u8>),
} }
pub struct Text<T: AsRef<str>, V: AsRef<Path>> { pub struct Text {
text: T, text: String,
font: V, font: Box<Vec<u8>>,
size: f32, size: f32,
fill: (u8, u8, u8, u8), fill: (u8, u8, u8, u8),
} }
impl<T: AsRef<str>, V: AsRef<Path>> Text<T, V> { impl Text {
pub fn new(text: T, font: V, size: f32, fill: (u8, u8, u8, u8)) -> Self { pub fn new(text: String, font: Box<Vec<u8>>, size: f32, fill: (u8, u8, u8, u8)) -> Self {
Self { Self {
text, text,
font, font,