gioser

tawasuyu/taffy

A high performance rust-powered UI layout library

HTML 5544Rust 88Markdown 11TOML 91926 Sutichaykuna

⎇ 70341c9f697b610470b0806a53266aa75343563b src/style/float.rs Rust · 80 siq'ikuna · 2.2 KB Ñawpa willay Pi imata llamkarqan ch'uya

Add support for parsing Taffy style types from string (#929) 70341c9f6 · Nico Burns ·

1//! Style types for float layout
2
3/// Floats a box to the left or right.
4/// This property only applies to children of a block layout
5///
6/// See <https://developer.mozilla.org/en-US/docs/Web/CSS/float>
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
8#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
9pub enum Float {
10    /// The box is floated to the left
11    Left,
12    /// The box is floated to the right
13    Right,
14    /// The box is not floated
15    #[default]
16    None,
17}
18
19#[cfg(feature = "parse")]
20crate::util::parse::impl_parse_for_keyword_enum!(Float,
21    "left" => Left,
22    "right" => Right,
23    "none" => None,
24);
25
26/// Whether a box that is definitely floated is floated to the left
27/// of to the right.
28///
29/// This type is only used in the low-level parts of the
30#[derive(Debug, Copy, Clone, PartialEq, Eq)]
31#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
32#[repr(u8)]
33pub enum FloatDirection {
34    /// The box is floated to the left
35    Left = 0,
36    /// The box is floated to the right
37    Right = 1,
38}
39
40impl Float {
41    /// Whether the box is floated
42    pub fn is_floated(self) -> bool {
43        matches!(self, Self::Left | Self::Right)
44    }
45
46    /// Converts [`Float`] into `Option<FloatDirection>`ca
47    pub fn float_direction(&self) -> Option<FloatDirection> {
48        match self {
49            Float::Left => Some(FloatDirection::Left),
50            Float::Right => Some(FloatDirection::Right),
51            Float::None => None,
52        }
53    }
54}
55
56/// Gives a box "clearance", which moves it below floated boxes which precede
57/// it in the tree.
58///
59/// See <https://developer.mozilla.org/en-US/docs/Web/CSS/clear>
60#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
61#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
62pub enum Clear {
63    /// The box clears left-floated boxes
64    Left,
65    /// The box clears right-floated boxes
66    Right,
67    /// The box clears boxes floated in either direction
68    Both,
69    /// The box does not clear floated boxes
70    #[default]
71    None,
72}
73
74#[cfg(feature = "parse")]
75crate::util::parse::impl_parse_for_keyword_enum!(Clear,
76    "left" => Left,
77    "right" => Right,
78    "both" => Both,
79    "none" => None,
80);