1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Styles for each reactive component.

mod flex;
mod image;
mod position;
mod scrollable;
mod text;
mod transform;
mod view;

pub use flex::{Align, FlexDirection, Justify};
pub use image::{ImageStyle, ImageViewStyle, ObjectFit};
pub use position::{Absolute, Position, Relative};
pub use scrollable::{ScrollableStyle, ScrollableViewStyle, ScrollbarColor};
pub use text::{TextAlign, TextStyle};
pub use transform::{Transform, TransformBuilder};
pub use view::{Border, BorderStyle, Overflow, ViewStyle, Visibility};

/// Represents a property that can optionally be inherited from a parent
/// element.
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub enum Inherited<T> {
    /// If inherited, the value of this property is taken from the parent
    /// element (transitively). If none of the parent elements have specified
    /// a value for this property, the default value is used.
    Inherited,

    /// If specified, this overrides any value from a parent element
    /// (transitively) for the same property.
    Specified(T),
}

impl<T> Default for Inherited<T> {
    fn default() -> Self {
        Inherited::Inherited
    }
}

impl<T> std::str::FromStr for Inherited<T>
where
    T: std::str::FromStr,
{
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "inherit" => Ok(Inherited::Inherited),
            s => T::from_str(s)
                .map(|value| Inherited::Specified(value))
                .map_err(|_| ()),
        }
    }
}