use blinc_core::Color;
use blinc_theme::{ColorToken, ThemeState};
use crate::div::{div, Div};
#[derive(Clone, Debug)]
pub struct HrConfig {
pub color: Color,
pub thickness: f32,
pub margin_y: f32,
}
impl Default for HrConfig {
fn default() -> Self {
let theme = ThemeState::get();
Self {
color: theme.color(ColorToken::Border),
thickness: 1.0,
margin_y: 2.0,
}
}
}
pub fn hr() -> Div {
hr_with_config(HrConfig::default())
}
pub fn hr_with_config(config: HrConfig) -> Div {
div().w_full().py(config.margin_y).child(
div().w_full().h(config.thickness).bg(config.color),
)
}
pub fn hr_color(color: Color) -> Div {
let config = HrConfig {
color,
..HrConfig::default()
};
hr_with_config(config)
}
pub fn hr_with_bg(wrapper_bg: Color) -> Div {
let config = HrConfig::default();
div()
.w_full()
.py(config.margin_y)
.bg(wrapper_bg)
.child(div().w_full().h(config.thickness).bg(config.color))
}
pub fn hr_thick(thickness: f32) -> Div {
let config = HrConfig {
thickness,
..HrConfig::default()
};
hr_with_config(config)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::div::ElementBuilder;
use crate::tree::LayoutTree;
fn init_theme() {
let _ = ThemeState::try_get().unwrap_or_else(|| {
ThemeState::init_default();
ThemeState::get()
});
}
#[test]
fn test_hr_creates_div() {
init_theme();
let mut tree = LayoutTree::new();
let rule = hr();
rule.build(&mut tree);
assert!(!tree.is_empty());
}
#[test]
fn test_hr_with_custom_color() {
init_theme();
let mut tree = LayoutTree::new();
let rule = hr_color(Color::RED);
rule.build(&mut tree);
assert!(!tree.is_empty());
}
}