use masonry::core::HasProperty;
use masonry::properties::{ContentColor, DisabledContentColor, LineBreaking};
use vello::peniko::Color;
pub use masonry::properties::types::{Gradient, GradientShape};
pub use masonry::properties::{
ActiveBackground, Background, BorderColor, BorderWidth, BoxShadow, CornerRadius,
DisabledBackground, HoveredBorderColor, Padding,
};
use crate::WidgetView;
use crate::view::Prop;
pub trait Style<State: 'static, Action: 'static>: WidgetView<State, Action> + Sized {
fn color(self, color: Color) -> Prop<ContentColor, Self, State, Action>
where
Self::Widget: HasProperty<ContentColor>,
{
self.prop(ContentColor { color })
}
fn disabled_color(self, color: Color) -> Prop<DisabledContentColor, Self, State, Action>
where
Self::Widget: HasProperty<DisabledContentColor>,
{
self.prop(DisabledContentColor(ContentColor { color }))
}
fn background(self, background: Background) -> Prop<Background, Self, State, Action>
where
Self::Widget: HasProperty<Background>,
{
self.prop(background)
}
fn background_color(self, color: Color) -> Prop<Background, Self, State, Action>
where
Self::Widget: HasProperty<Background>,
{
self.prop(Background::Color(color))
}
fn background_gradient(self, gradient: Gradient) -> Prop<Background, Self, State, Action>
where
Self::Widget: HasProperty<Background>,
{
self.prop(Background::Gradient(gradient))
}
fn active_background(
self,
background: Background,
) -> Prop<ActiveBackground, Self, State, Action>
where
Self::Widget: HasProperty<ActiveBackground>,
{
self.prop(ActiveBackground(background))
}
fn active_background_color(self, color: Color) -> Prop<ActiveBackground, Self, State, Action>
where
Self::Widget: HasProperty<ActiveBackground>,
{
self.prop(ActiveBackground(Background::Color(color)))
}
fn active_background_gradient(
self,
gradient: Gradient,
) -> Prop<ActiveBackground, Self, State, Action>
where
Self::Widget: HasProperty<ActiveBackground>,
{
self.prop(ActiveBackground(Background::Gradient(gradient)))
}
fn disabled_background(
self,
background: Background,
) -> Prop<DisabledBackground, Self, State, Action>
where
Self::Widget: HasProperty<DisabledBackground>,
{
self.prop(DisabledBackground(background))
}
fn disabled_background_color(
self,
color: Color,
) -> Prop<DisabledBackground, Self, State, Action>
where
Self::Widget: HasProperty<DisabledBackground>,
{
self.prop(DisabledBackground(Background::Color(color)))
}
fn disabled_background_gradient(
self,
gradient: Gradient,
) -> Prop<DisabledBackground, Self, State, Action>
where
Self::Widget: HasProperty<DisabledBackground>,
{
self.prop(DisabledBackground(Background::Gradient(gradient)))
}
fn border(
self,
color: Color,
width: f64,
) -> Prop<BorderWidth, Prop<BorderColor, Self, State, Action>, State, Action>
where
Self::Widget: HasProperty<BorderColor> + HasProperty<BorderWidth>,
{
self.prop(BorderColor { color }).prop(BorderWidth { width })
}
fn border_color(self, color: Color) -> Prop<BorderColor, Self, State, Action>
where
Self::Widget: HasProperty<BorderColor>,
{
self.prop(BorderColor { color })
}
fn hovered_border_color(self, color: Color) -> Prop<HoveredBorderColor, Self, State, Action>
where
Self::Widget: HasProperty<HoveredBorderColor>,
{
self.prop(HoveredBorderColor(BorderColor { color }))
}
fn border_width(self, width: f64) -> Prop<BorderWidth, Self, State, Action>
where
Self::Widget: HasProperty<BorderWidth>,
{
self.prop(BorderWidth { width })
}
fn box_shadow(self, box_shadow: BoxShadow) -> Prop<BoxShadow, Self, State, Action>
where
Self::Widget: HasProperty<BoxShadow>,
{
self.prop(box_shadow)
}
fn corner_radius(self, radius: f64) -> Prop<CornerRadius, Self, State, Action>
where
Self::Widget: HasProperty<CornerRadius>,
{
self.prop(CornerRadius { radius })
}
fn padding(self, padding: impl Into<Padding>) -> Prop<Padding, Self, State, Action>
where
Self::Widget: HasProperty<Padding>,
{
self.prop(padding.into())
}
fn line_break_mode(
self,
line_break_mode: LineBreaking,
) -> Prop<LineBreaking, Self, State, Action>
where
Self::Widget: HasProperty<LineBreaking>,
{
self.prop(line_break_mode)
}
}
impl<State, Action, V> Style<State, Action> for V
where
State: 'static,
Action: 'static,
V: WidgetView<State, Action> + Sized,
{
}