polyhorn_ui/styles/
mod.rs

1//! Styles for each reactive component.
2
3mod flex;
4mod image;
5mod position;
6mod scrollable;
7mod text;
8mod transform;
9mod view;
10
11pub use flex::{Align, FlexDirection, Justify};
12pub use image::{ImageStyle, ImageViewStyle, ObjectFit};
13pub use position::{Absolute, Position, Relative};
14pub use scrollable::{ScrollableStyle, ScrollableViewStyle, ScrollbarColor};
15pub use text::{TextAlign, TextStyle};
16pub use transform::{Transform, TransformBuilder};
17pub use view::{Border, BorderStyle, Overflow, ViewStyle, Visibility};
18
19/// Represents a property that can optionally be inherited from a parent
20/// element.
21#[derive(Copy, Clone, Debug, Eq, PartialEq)]
22pub enum Inherited<T> {
23    /// If inherited, the value of this property is taken from the parent
24    /// element (transitively). If none of the parent elements have specified
25    /// a value for this property, the default value is used.
26    Inherited,
27
28    /// If specified, this overrides any value from a parent element
29    /// (transitively) for the same property.
30    Specified(T),
31}
32
33impl<T> Default for Inherited<T> {
34    fn default() -> Self {
35        Inherited::Inherited
36    }
37}
38
39impl<T> std::str::FromStr for Inherited<T>
40where
41    T: std::str::FromStr,
42{
43    type Err = ();
44
45    fn from_str(s: &str) -> Result<Self, Self::Err> {
46        match s {
47            "inherit" => Ok(Inherited::Inherited),
48            s => T::from_str(s)
49                .map(|value| Inherited::Specified(value))
50                .map_err(|_| ()),
51        }
52    }
53}