pub use euclid::Rect;
use crate::{
alignment::Alignment,
direction::DirectionMode,
gaps::Gaps,
geometry::Length,
prelude::{
Content,
Position,
},
scaled::Scaled,
size::Size,
};
#[derive(PartialEq, Clone, Debug, Default)]
pub struct Node {
pub width: Size,
pub height: Size,
pub minimum_width: Size,
pub minimum_height: Size,
pub maximum_width: Size,
pub maximum_height: Size,
pub main_alignment: Alignment,
pub cross_alignment: Alignment,
pub padding: Gaps,
pub margin: Gaps,
pub offset_x: Length,
pub offset_y: Length,
pub direction: DirectionMode,
pub position: Position,
pub content: Content,
pub has_layout_references: bool,
pub contains_text: bool,
}
impl Scaled for Node {
fn scale(&mut self, scale_factor: f32) {
self.width.scale(scale_factor);
self.height.scale(scale_factor);
self.minimum_width.scale(scale_factor);
self.minimum_height.scale(scale_factor);
self.maximum_width.scale(scale_factor);
self.maximum_height.scale(scale_factor);
self.margin.scale(scale_factor);
self.padding.scale(scale_factor);
self.offset_x *= scale_factor;
self.offset_y *= scale_factor;
self.position.scale(scale_factor);
}
}
impl Node {
pub fn new() -> Self {
Self::default()
}
pub fn from_size_and_direction(width: Size, height: Size, direction: DirectionMode) -> Self {
Self {
width,
height,
direction,
..Default::default()
}
}
pub fn from_size_and_scroll(
width: Size,
height: Size,
offset_x: Length,
offset_y: Length,
) -> Self {
Self {
width,
height,
offset_x,
offset_y,
..Default::default()
}
}
pub fn from_size_and_padding(width: Size, height: Size, padding: Gaps) -> Self {
Self {
width,
height,
padding,
..Default::default()
}
}
pub fn from_size_and_alignments_and_direction(
width: Size,
height: Size,
main_alignment: Alignment,
cross_alignment: Alignment,
direction: DirectionMode,
) -> Self {
Self {
width,
height,
main_alignment,
cross_alignment,
direction,
..Default::default()
}
}
pub fn from_size_and_margin(width: Size, height: Size, margin: Gaps) -> Self {
Self {
width,
height,
margin,
..Default::default()
}
}
pub fn from_size_and_direction_and_margin(
width: Size,
height: Size,
direction: DirectionMode,
margin: Gaps,
) -> Self {
Self {
width,
height,
direction,
margin,
..Default::default()
}
}
pub fn from_size_and_alignments_and_direction_and_padding(
width: Size,
height: Size,
main_alignment: Alignment,
cross_alignment: Alignment,
direction: DirectionMode,
padding: Gaps,
) -> Self {
Self {
width,
height,
main_alignment,
cross_alignment,
direction,
padding,
..Default::default()
}
}
pub fn from_size_and_position(width: Size, height: Size, position: Position) -> Self {
Self {
width,
height,
position,
..Default::default()
}
}
pub fn from_size_and_content(width: Size, height: Size, content: Content) -> Self {
Self {
width,
height,
content,
..Default::default()
}
}
pub fn does_depend_on_inner(&self) -> bool {
self.width.inner_sized()
|| self.height.inner_sized()
|| self.has_layout_references
|| self.cross_alignment.is_not_start()
|| self.main_alignment.is_not_start()
|| self.contains_text
}
}