2020-01-01 14:16:10 +01:00
|
|
|
//! Decorate content and apply alignment.
|
|
|
|
|
use iced_core::{Background, Color};
|
|
|
|
|
|
|
|
|
|
/// The appearance of a container.
|
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
|
pub struct Style {
|
|
|
|
|
pub text_color: Option<Color>,
|
|
|
|
|
pub background: Option<Background>,
|
2020-11-23 00:31:50 +01:00
|
|
|
pub border_radius: f32,
|
|
|
|
|
pub border_width: f32,
|
2020-01-05 18:38:03 +01:00
|
|
|
pub border_color: Color,
|
2020-01-01 14:16:10 +01:00
|
|
|
}
|
|
|
|
|
|
2020-01-05 19:34:38 +01:00
|
|
|
impl std::default::Default for Style {
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
text_color: None,
|
|
|
|
|
background: None,
|
2020-11-23 00:31:50 +01:00
|
|
|
border_radius: 0.0,
|
|
|
|
|
border_width: 0.0,
|
2020-01-05 19:34:38 +01:00
|
|
|
border_color: Color::TRANSPARENT,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-01 14:16:10 +01:00
|
|
|
/// A set of rules that dictate the style of a container.
|
|
|
|
|
pub trait StyleSheet {
|
|
|
|
|
/// Produces the style of a container.
|
2020-01-01 18:26:49 +01:00
|
|
|
fn style(&self) -> Style;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Default;
|
|
|
|
|
|
|
|
|
|
impl StyleSheet for Default {
|
2020-01-01 14:16:10 +01:00
|
|
|
fn style(&self) -> Style {
|
|
|
|
|
Style {
|
|
|
|
|
text_color: None,
|
|
|
|
|
background: None,
|
2020-11-23 00:31:50 +01:00
|
|
|
border_radius: 0.0,
|
|
|
|
|
border_width: 0.0,
|
2020-01-05 18:38:03 +01:00
|
|
|
border_color: Color::TRANSPARENT,
|
2020-01-01 14:16:10 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-02 16:02:05 +07:00
|
|
|
impl<'a> std::default::Default for Box<dyn StyleSheet + 'a> {
|
2020-01-01 14:16:10 +01:00
|
|
|
fn default() -> Self {
|
2021-10-31 17:02:59 +07:00
|
|
|
Box::new(Default)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, T> From<T> for Box<dyn StyleSheet + 'a>
|
|
|
|
|
where
|
|
|
|
|
T: StyleSheet + 'a,
|
|
|
|
|
{
|
|
|
|
|
fn from(style_sheet: T) -> Self {
|
|
|
|
|
Box::new(style_sheet)
|
2020-01-01 14:16:10 +01:00
|
|
|
}
|
|
|
|
|
}
|