use crate::core::{Element, ElementType, Style};
#[derive(Debug, Clone, Default)]
pub struct Spacer {
flex_grow: f32,
}
impl Spacer {
pub fn new() -> Self {
Self { flex_grow: 1.0 }
}
pub fn flex(mut self, grow: f32) -> Self {
self.flex_grow = grow;
self
}
pub fn into_element(self) -> Element {
let mut element = Element::new(ElementType::Box);
element.style = Style::new();
element.style.flex_grow = self.flex_grow;
element.style.flex_shrink = 0.0;
element
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_spacer_default() {
let element = Spacer::new().into_element();
assert_eq!(element.style.flex_grow, 1.0);
assert_eq!(element.style.flex_shrink, 0.0);
}
#[test]
fn test_spacer_custom_flex() {
let element = Spacer::new().flex(2.0).into_element();
assert_eq!(element.style.flex_grow, 2.0);
}
}