use crate::core::{Result, Font, FontInfo, Context};
#[must_use]
#[derive(Clone)]
pub struct FontBuilder<'a> {
info : FontInfo,
context : &'a Context,
file : Option<&'a str>,
}
impl<'a> FontBuilder<'a> {
pub fn family(mut self: Self, family: &str) -> Self {
self.info.family = family.to_string();
self
}
pub fn file(mut self: Self, file: &'a str) -> Self {
self.file = Some(file);
self
}
pub fn italic(mut self: Self) -> Self {
self.info.italic = true;
self
}
pub fn oblique(mut self: Self) -> Self {
self.info.oblique = true;
self
}
pub fn monospace(mut self: Self) -> Self {
self.info.monospace = true;
self
}
pub fn bold(mut self: Self) -> Self {
self.info.bold = true;
self
}
pub fn size(mut self: Self, size: f32) -> Self {
self.info.size = size;
self
}
pub fn build(self: Self) -> Result<Font> {
if let Some(file) = self.file {
Font::from_file(self.context, file)
} else {
Font::from_info(self.context, self.info)
}
}
pub(crate) fn new<'b>(context: &'b Context) -> FontBuilder<'b> {
FontBuilder {
context : context,
info : FontInfo { ..FontInfo::default() },
file : None,
}
}
}