tawasuyu

tawasuyu/taffy

A high performance rust-powered UI layout library

Rust 501HTML 254C 19JavaScript 81412 Sutichaykuna

⎇ direction-floats src/style/float.rs Rust · 65 siq'ikuna · 1.9 KB Ñawpa willay Pi imata llamkarqan ch'uya

Implement Floats (#866) 25759dad4 · 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/// Whether a box that is definitely floated is floated to the left
20/// of to the right.
21///
22/// This type is only used in the low-level parts of the
23#[derive(Debug, Copy, Clone, PartialEq, Eq)]
24#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
25#[repr(u8)]
26pub enum FloatDirection {
27    /// The box is floated to the left
28    Left = 0,
29    /// The box is floated to the right
30    Right = 1,
31}
32
33impl Float {
34    /// Whether the box is floated
35    pub fn is_floated(self) -> bool {
36        matches!(self, Self::Left | Self::Right)
37    }
38
39    /// Converts [`Float`] into `Option<FloatDirection>`ca
40    pub fn float_direction(&self) -> Option<FloatDirection> {
41        match self {
42            Float::Left => Some(FloatDirection::Left),
43            Float::Right => Some(FloatDirection::Right),
44            Float::None => None,
45        }
46    }
47}
48
49/// Gives a box "clearance", which moves it below floated boxes which precede
50/// it in the tree.
51///
52/// See <https://developer.mozilla.org/en-US/docs/Web/CSS/clear>
53#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
54#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
55pub enum Clear {
56    /// The box clears left-floated boxes
57    Left,
58    /// The box clears right-floated boxes
59    Right,
60    /// The box clears boxes floated in either direction
61    Both,
62    /// The box does not clear floated boxes
63    #[default]
64    None,
65}