use crate::colors::{Color, ColorLayer};
use cotis_utils::math::{Dimensions, Vector2};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
pub mod types;
use types::*;
pub mod sizing;
use sizing::*;
#[cfg(feature = "complex_color")]
pub const TRANSPARENT_BACKGROUND: ColorLayer = ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0));
#[cfg(not(feature = "complex_color"))]
pub const TRANSPARENT_BACKGROUND: Color = Color::rgba(0.0, 0.0, 0.0, 0.0);
#[cfg(feature = "complex_color")]
pub const BLACK_BACKGROUND: ColorLayer = ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 255.0));
#[cfg(not(feature = "complex_color"))]
pub const BLACK_BACKGROUND: Color = Color::rgba(0.0, 0.0, 0.0, 255.0);
#[derive(Debug, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(not(feature = "complex_color"), derive(Copy))]
pub struct CotisStyle<Sizing> {
pub sizing: Sizing,
pub layout: LayoutStyle,
#[cfg(not(feature = "complex_color"))]
pub background_color: Color,
#[cfg(feature = "complex_color")]
pub background_color: ColorLayer,
pub corner_radius: CornerRadiiStyle,
pub floating: Option<FloatingElementStyle>,
pub clip: ClipElementConfig,
pub border: BorderElementStyle,
}
impl Default for CotisStyle<Sizing> {
fn default() -> Self {
Self {
sizing: Sizing::DoubleAxis(DoubleAxisSizing {
width: AxisSizing::Fit(0.0, f32::MAX),
height: AxisSizing::Fit(0.0, f32::MAX),
}),
layout: Default::default(),
#[cfg(not(feature = "complex_color"))]
background_color: Color::rgba(0.0, 0.0, 0.0, 0.0),
#[cfg(feature = "complex_color")]
background_color: ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0)),
corner_radius: CornerRadiiStyle {
top_left: 0.0,
top_right: 0.0,
bottom_left: 0.0,
bottom_right: 0.0,
},
floating: None,
clip: ClipElementConfig {
horizontal: false,
vertical: false,
child_offset: Default::default(),
},
border: BorderElementStyle {
color: Color::rgba(0.0, 0.0, 0.0, 0.0),
width: BorderWidthStyle {
left: 0.0,
right: 0.0,
top: 0.0,
bottom: 0.0,
between_children: 0.0,
},
},
}
}
}
impl Default for CotisStyle<DoubleAxisSizing> {
fn default() -> Self {
Self {
sizing: DoubleAxisSizing {
width: AxisSizing::Fit(0.0, f32::MAX),
height: AxisSizing::Fit(0.0, f32::MAX),
},
layout: Default::default(),
#[cfg(not(feature = "complex_color"))]
background_color: Color::rgba(0.0, 0.0, 0.0, 0.0),
#[cfg(feature = "complex_color")]
background_color: ColorLayer::Solid(Color::rgba(0.0, 0.0, 0.0, 0.0)),
corner_radius: CornerRadiiStyle {
top_left: 0.0,
top_right: 0.0,
bottom_left: 0.0,
bottom_right: 0.0,
},
floating: None,
clip: ClipElementConfig {
horizontal: false,
vertical: false,
child_offset: Default::default(),
},
border: BorderElementStyle {
color: Color::rgba(0.0, 0.0, 0.0, 0.0),
width: BorderWidthStyle {
left: 0.0,
right: 0.0,
top: 0.0,
bottom: 0.0,
between_children: 0.0,
},
},
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct CornerRadiiStyle {
pub top_left: f32,
pub top_right: f32,
pub bottom_left: f32,
pub bottom_right: f32,
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BorderElementStyle {
pub color: Color,
pub width: BorderWidthStyle,
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BorderWidthStyle {
pub left: f32,
pub right: f32,
pub top: f32,
pub bottom: f32,
pub between_children: f32,
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct FloatingElementStyle {
pub offset: Vector2,
pub expand: Dimensions,
pub z_index: i16,
pub attach_point: FloatingAttachPointType,
pub pointer_capture_mode: PointerCaptureMode,
}
#[derive(Debug, Copy, Clone)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct LayoutStyle {
pub padding: Padding,
pub child_gap: f32,
pub child_alignment: Alignment,
pub layout_direction: LayoutDirection,
#[cfg(feature = "child_wrapping")]
pub child_wrapping: bool,
}