use crate::basic_display::{self, Dimensions, Rotation};
pub struct Builder {
dimensions: Option<Dimensions>,
rotation: Rotation,
auto_update: bool,
}
pub struct Config {
pub(crate) dimensions: Dimensions,
pub(crate) rotation: Rotation,
pub(crate) auto_update: bool,
}
#[derive(Debug)]
pub struct BuilderError {}
impl Default for Builder {
fn default() -> Self {
Builder {
dimensions: None,
rotation: Rotation::default(),
auto_update: true,
}
}
}
impl Builder {
pub fn new() -> Self {
Self::default()
}
pub fn dimensions(self, dimensions: Dimensions) -> Self {
assert!(
dimensions.cols % 8 == 0,
"Columns must be evenly divisibly by 8"
);
assert!(
dimensions.rows <= basic_display::MAX_GATE_OUTPUTS,
"rows must be less thn MAX_GATE_OUTPUTS"
);
assert!(
dimensions.cols <= basic_display::MAX_SOURCE_OUTPUTS,
"cols must be less than MAX_SOURCE_OUTPUTS"
);
Self {
dimensions: Some(dimensions),
..self
}
}
pub fn rotation(self, rotation: Rotation) -> Self {
Self { rotation, ..self }
}
pub fn auto_update(self, enabled: bool) -> Self {
Self {
auto_update: enabled,
..self
}
}
pub fn build(self) -> Result<Config, BuilderError> {
Ok(Config {
dimensions: self.dimensions.ok_or_else(|| BuilderError {})?,
rotation: self.rotation,
auto_update: self.auto_update,
})
}
}