tui_lipan/widgets/spacer/
mod.rs1mod layout;
4mod node;
5mod reconcile;
6
7pub use layout::measure_spacer;
8pub use node::SpacerNode;
9pub use reconcile::reconcile_spacer;
10
11use crate::core::element::{Element, ElementKind};
12use crate::style::Length;
13
14#[derive(Clone, Debug)]
16pub struct Spacer {
17 pub(crate) width: Length,
18 pub(crate) height: Length,
19}
20
21impl Default for Spacer {
22 fn default() -> Self {
23 Self {
24 width: Length::Flex(1),
25 height: Length::Flex(1),
26 }
27 }
28}
29
30impl Spacer {
31 pub fn new() -> Self {
33 Self::default()
34 }
35
36 pub fn width(mut self, width: Length) -> Self {
38 self.width = width;
39 self
40 }
41
42 pub fn height(mut self, height: Length) -> Self {
44 self.height = height;
45 self
46 }
47}
48
49impl From<Spacer> for Element {
50 fn from(value: Spacer) -> Self {
51 Element::new(ElementKind::Spacer(value))
52 }
53}
54
55impl crate::layout::hash::LayoutHash for Spacer {
56 fn layout_hash(
57 &self,
58 hasher: &mut impl std::hash::Hasher,
59 _recurse: &dyn Fn(&Element) -> Option<u64>,
60 ) -> Option<()> {
61 use std::hash::Hash;
62 self.width.hash(hasher);
63 self.height.hash(hasher);
64 Some(())
65 }
66}