Skip to content
Snippets Groups Projects
Commit a34ef422 authored by MrGVSV's avatar MrGVSV
Browse files

Made some methods pub and added a helper method

Methods made pub as they may be useful in certain scenarios

Added StyleProp::select helper method
parent e7c76a74
No related branches found
No related tags found
No related merge requests found
...@@ -8,7 +8,7 @@ pub enum StyleProp<T: Default + Clone> { ...@@ -8,7 +8,7 @@ pub enum StyleProp<T: Default + Clone> {
/// This prop is unset, meaning its actual value is not determined until style resolution, /// This prop is unset, meaning its actual value is not determined until style resolution,
/// wherein it will be set to the property's default value. /// wherein it will be set to the property's default value.
/// ///
/// When [merging](Style::apply) styles, only style properties of this type may be /// When [applying](Style::apply) styles, only style properties of this type may be
/// overwritten. /// overwritten.
Unset, Unset,
/// Like [StyleProp::Unset], properties of this type wait until style resolution for their /// Like [StyleProp::Unset], properties of this type wait until style resolution for their
...@@ -41,6 +41,19 @@ impl<T> StyleProp<T> ...@@ -41,6 +41,19 @@ impl<T> StyleProp<T>
StyleProp::Inherit => panic!("All styles should be merged before resolving!"), StyleProp::Inherit => panic!("All styles should be merged before resolving!"),
} }
} }
/// Returns the first property to not be [unset](StyleProp::Unset)
///
/// If none found, returns [`StyleProp::Unset`]
pub fn select<'a>(props: &'_ [&'a StyleProp<T>]) -> &'a Self {
for prop in props {
if !matches!(prop, StyleProp::Unset) {
return prop
}
}
&StyleProp::Unset
}
} }
impl<T: Default + Clone> From<T> for StyleProp<T> { impl<T: Default + Clone> From<T> for StyleProp<T> {
...@@ -81,7 +94,7 @@ macro_rules! define_styles { ...@@ -81,7 +94,7 @@ macro_rules! define_styles {
/// ///
/// This should only be used when default properties are required or desired. Otherwise, you /// This should only be used when default properties are required or desired. Otherwise, you
/// may be better off using `Style::default` (which sets all properties to [`StyleProp::Unset`]). /// may be better off using `Style::default` (which sets all properties to [`StyleProp::Unset`]).
pub(crate) fn new_default() -> Self { pub fn new_default() -> Self {
Self { Self {
$($field: StyleProp::Default),* $($field: StyleProp::Default),*
} }
...@@ -158,7 +171,7 @@ impl Style { ...@@ -158,7 +171,7 @@ impl Style {
/// ///
/// This is the actual "default" to apply over any field marked as [`StyleProp::Unset`] before /// This is the actual "default" to apply over any field marked as [`StyleProp::Unset`] before
/// resolving the style. /// resolving the style.
pub(crate) fn initial() -> Self { pub fn initial() -> Self {
Self { Self {
background_color: StyleProp::Default, background_color: StyleProp::Default,
border: StyleProp::Default, border: StyleProp::Default,
...@@ -214,8 +227,8 @@ impl AsRefOption<Style> for Option<Style> { ...@@ -214,8 +227,8 @@ impl AsRefOption<Style> for Option<Style> {
} }
} }
impl AsRefOption<Style> for Option<&Style> { impl AsRefOption<Style> for &Option<Style> {
fn as_ref_option(&self) -> Option<&Style> { fn as_ref_option(&self) -> Option<&Style> {
self.clone() self.as_ref()
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment