use crate::layout::{Cells, LengthBound, Pos};
use crate::text::{Glyph, IntoGlyph, Theme};
use crate::{Result, Widget};
use std::ops::RangeBounds;
#[derive(Default)]
pub struct Spacer {
width_bounds: LengthBound,
height_bounds: LengthBound,
fill: Option<Glyph>,
}
impl Spacer {
pub fn with_columns<R>(mut self, col: R) -> Self
where
R: RangeBounds<u16>,
{
self.width_bounds = LengthBound::new(col);
self
}
pub fn with_rows<R>(mut self, row: R) -> Self
where
R: RangeBounds<u16>,
{
self.height_bounds = LengthBound::new(row);
self
}
pub fn with_fill<G: IntoGlyph>(mut self, fill: G) -> Result<Self> {
self.fill = Some(fill.into_glyph()?);
Ok(self)
}
}
impl Widget for Spacer {
fn width_bounds(&self, _theme: &Theme) -> LengthBound {
self.width_bounds
}
fn height_bounds(&self, _theme: &Theme, _width: u16) -> LengthBound {
self.height_bounds
}
fn draw(&self, cells: &mut Cells, _offset: Pos) -> Result<()> {
if let Some(fill) = &self.fill {
cells.fill(fill)?;
}
Ok(())
}
}