use crate::render::AvatarFormat;
pub const DEFAULT_SIZE: u32 = 256;
pub const DEFAULT_SVG_SIZE: i32 = 256;
pub const DEFAULT_OPTIMIZE_SVG: bool = true;
#[derive(Debug, Clone)]
pub struct AvatarOptions {
sans_env: bool,
part: Option<String>,
theme: Option<String>,
size: u32,
svg_width: i32,
svg_height: i32,
format: AvatarFormat,
optimize_svg: bool,
}
impl AvatarOptions {
pub fn builder() -> AvatarOptionsBuilder {
AvatarOptionsBuilder::default()
}
pub fn defaults() -> AvatarOptions {
AvatarOptionsBuilder::default().build()
}
pub fn sans_env(&self) -> bool {
self.sans_env
}
pub fn part(&self) -> Option<&str> {
self.part.as_deref()
}
pub fn theme(&self) -> Option<&str> {
self.theme.as_deref()
}
pub fn size(&self) -> u32 {
self.size
}
pub fn svg_width(&self) -> i32 {
self.svg_width
}
pub fn svg_height(&self) -> i32 {
self.svg_height
}
pub fn format(&self) -> AvatarFormat {
self.format
}
pub fn optimize_svg(&self) -> bool {
self.optimize_svg
}
}
#[derive(Debug, Clone)]
pub struct AvatarOptionsBuilder {
sans_env: bool,
part: Option<String>,
theme: Option<String>,
size: u32,
svg_width: i32,
svg_height: i32,
format: AvatarFormat,
optimize_svg: bool,
}
impl Default for AvatarOptionsBuilder {
fn default() -> Self {
AvatarOptionsBuilder {
sans_env: false,
part: None,
theme: None,
size: DEFAULT_SIZE,
svg_width: DEFAULT_SVG_SIZE,
svg_height: DEFAULT_SVG_SIZE,
format: AvatarFormat::Svg,
optimize_svg: DEFAULT_OPTIMIZE_SVG,
}
}
}
impl AvatarOptionsBuilder {
pub fn sans_env(mut self, sans_env: bool) -> Self {
self.sans_env = sans_env;
self
}
pub fn part(mut self, part: impl Into<String>) -> Self {
self.part = Some(part.into());
self
}
pub fn part_owned(mut self, part: Option<String>) -> Self {
self.part = part;
self
}
pub fn theme(mut self, theme: impl Into<String>) -> Self {
self.theme = Some(theme.into());
self
}
pub fn theme_owned(mut self, theme: Option<String>) -> Self {
self.theme = theme;
self
}
pub fn size(mut self, size: u32) -> Self {
self.size = size.max(1);
self
}
pub fn svg_size(mut self, width: i32, height: i32) -> Self {
self.svg_width = width.max(1);
self.svg_height = height.max(1);
self
}
pub fn format(mut self, format: AvatarFormat) -> Self {
self.format = format;
self
}
pub fn optimize_svg(mut self, optimize_svg: bool) -> Self {
self.optimize_svg = optimize_svg;
self
}
pub fn build(self) -> AvatarOptions {
AvatarOptions {
sans_env: self.sans_env,
part: self.part,
theme: self.theme,
size: self.size,
svg_width: self.svg_width,
svg_height: self.svg_height,
format: self.format,
optimize_svg: self.optimize_svg,
}
}
}