pub mod border;
pub mod layout;
pub mod padding;
pub mod sizing;
use derive_default_constructor::DefaultConstructor;
use derive_setters::Setters;
use crate::style::layout::Layout;
use crate::style::padding::Padding;
use crate::style::sizing::BoxSizing;
pub trait KaolinColor<Color>
where
Color: Default + Copy + PartialEq,
{
fn default_foreground_color() -> Color {
Color::default()
}
fn default_background_color() -> Color {
Color::default()
}
}
#[derive(DefaultConstructor, Clone, Copy, Setters)]
pub struct FlexStyle<Color>
where
Color: Default + Copy + PartialEq + KaolinColor<Color>,
{
#[setters(strip_option)]
pub color: Option<Color>,
#[setters(strip_option)]
pub background_color: Option<Color>,
pub layout: Layout,
pub sizing: BoxSizing,
pub padding: Padding,
pub corner_radius: f32,
pub border: border::Border<Color>,
}
impl<Color> Default for FlexStyle<Color>
where
Color: Default + Copy + PartialEq + KaolinColor<Color>,
{
fn default() -> Self {
FlexStyle {
color: None,
background_color: None,
layout: Layout::default(),
sizing: BoxSizing::default(),
padding: Padding::default(),
corner_radius: 0.0,
border: border::Border::default(),
}
}
}
impl<Color> FlexStyle<Color>
where
Color: Default + Copy + PartialEq + KaolinColor<Color>,
{
#[inline]
pub fn has_horizontal_layout(&self) -> bool {
self.layout.direction.is_horizontal()
}
#[inline]
pub fn switch_axis<T>(&self, (a, b): (T, T)) -> (T, T) {
if self.has_horizontal_layout() {
(a, b)
} else {
(b, a)
}
}
}
#[derive(DefaultConstructor, Debug, Clone, Copy, PartialEq, Setters)]
pub struct TextStyle<Color>
where
Color: Default + Copy + PartialEq + KaolinColor<Color>,
{
pub font_id: u32,
pub font_size: f32,
#[setters(strip_option)]
pub color: Option<Color>,
}
impl<Color> Default for TextStyle<Color>
where
Color: Default + Copy + PartialEq + KaolinColor<Color>,
{
fn default() -> Self {
TextStyle {
font_id: 0,
font_size: 16.0,
color: None,
}
}
}