hyaenidae/toolkit/src/thumbnail.rs

41 lines
974 B
Rust

use crate::image::Image;
use crate::tile::{Indicator, IndicatorColor};
use std::rc::Rc;
pub struct Thumbnail {
image: Rc<dyn Image>,
pub(crate) title: String,
pub(crate) author: String,
pub(crate) indicator: Option<Indicator>,
pub(crate) href: Option<String>,
}
impl Thumbnail {
pub fn new(image: impl Image + 'static, title: &str, author: &str) -> Self {
Thumbnail {
image: Rc::new(image),
title: title.to_owned(),
author: author.to_owned(),
indicator: None,
href: None,
}
}
pub fn indicator(mut self, text: &str, color: IndicatorColor) -> Self {
self.indicator = Some(Indicator {
text: text.to_owned(),
color,
});
self
}
pub fn link(mut self, href: &str) -> Self {
self.href = Some(href.to_owned());
self
}
pub(crate) fn image(&self) -> &dyn Image {
&*self.image
}
}