mod layout;
mod node;
mod reconcile;
pub(crate) use self::layout::measure_center_pin;
pub use self::node::CenterPinNode;
pub(crate) use self::reconcile::reconcile_center_pin;
use crate::core::element::{Element, ElementKind};
use crate::style::{LayoutConstraints, Length, Style};
#[derive(Clone, Default)]
pub struct CenterPin {
pub(crate) top: Option<Box<Element>>,
pub(crate) center: Option<Box<Element>>,
pub(crate) bottom: Option<Box<Element>>,
pub(crate) style: Style,
}
impl CenterPin {
pub fn new() -> Self {
Self::default()
}
pub fn top(mut self, top: impl Into<Element>) -> Self {
self.top = Some(Box::new(top.into()));
self
}
pub fn center(mut self, center: impl Into<Element>) -> Self {
self.center = Some(Box::new(center.into()));
self
}
pub fn bottom(mut self, bottom: impl Into<Element>) -> Self {
self.bottom = Some(Box::new(bottom.into()));
self
}
pub fn style(mut self, style: Style) -> Self {
self.style = style;
self
}
}
impl From<CenterPin> for Element {
fn from(value: CenterPin) -> Self {
let (min_w, min_h) = measure_center_pin(&value, None, None);
Element::new(ElementKind::CenterPin(value)).with_layout(
LayoutConstraints::default()
.min_width(Length::Px(min_w))
.min_height(Length::Px(min_h)),
)
}
}