use crate::geometry::Color;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ShadowSpec {
pub offset_x: f32,
pub offset_y: f32,
pub blur: f32,
pub spread: f32,
pub color: Color,
}
#[derive(Debug, Clone, Default, PartialEq)]
pub struct PaintStyle {
pub background_color: Option<Color>,
pub hover_background: Option<Color>,
pub pressed_background: Option<Color>,
pub border_radius: f32,
pub border_color: Option<Color>,
pub border_width: f32,
pub clip_content: bool,
pub opacity: f32,
pub shadow: Option<ShadowSpec>,
}
impl PaintStyle {
pub fn new() -> Self {
Self {
opacity: 1.0,
..Default::default()
}
}
pub fn background(mut self, c: Color) -> Self {
self.background_color = Some(c);
self
}
pub fn hover_background(mut self, c: Color) -> Self {
self.hover_background = Some(c);
self
}
pub fn pressed_background(mut self, c: Color) -> Self {
self.pressed_background = Some(c);
self
}
pub fn radius(mut self, r: f32) -> Self {
self.border_radius = r;
self
}
pub fn border(mut self, width: f32, color: Color) -> Self {
self.border_width = width;
self.border_color = Some(color);
self
}
pub fn opacity(mut self, o: f32) -> Self {
self.opacity = o.clamp(0.0, 1.0);
self
}
pub fn clip(mut self, v: bool) -> Self {
self.clip_content = v;
self
}
pub fn shadow(mut self, s: ShadowSpec) -> Self {
self.shadow = Some(s);
self
}
}
#[derive(Debug, Clone, Default, PartialEq)]
pub enum FontWeight {
#[default]
Normal,
Medium,
Bold,
Weight(u16),
}
impl From<u16> for FontWeight {
fn from(value: u16) -> Self {
Self::Weight(value)
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub enum TextAlign {
#[default]
Start,
Center,
End,
Justify,
}
#[derive(Debug, Clone, Copy, Default, PartialEq)]
pub enum ImageFit {
#[default]
Fill,
Contain,
Cover,
None,
}
#[derive(Debug, Clone, PartialEq)]
pub struct TextStyle {
pub font_size: f64,
pub color: Color,
pub hover_color: Option<Color>,
pub pressed_color: Option<Color>,
pub font_family: String,
pub font_weight: FontWeight,
pub line_height: Option<f64>,
pub max_width: Option<f64>,
pub text_align: TextAlign,
pub wrap: bool,
}
impl Default for TextStyle {
fn default() -> Self {
Self {
font_size: 14.0,
color: Color::BLACK,
hover_color: None,
pressed_color: None,
font_family: "sans-serif".to_string(),
font_weight: FontWeight::Normal,
line_height: None,
max_width: None,
text_align: TextAlign::Start,
wrap: true,
}
}
}
impl TextStyle {
pub fn new() -> Self {
Self::default()
}
pub fn font_size(mut self, s: f64) -> Self {
self.font_size = s;
self
}
pub fn color(mut self, c: Color) -> Self {
self.color = c;
self
}
pub fn hover_color(mut self, c: Color) -> Self {
self.hover_color = Some(c);
self
}
pub fn pressed_color(mut self, c: Color) -> Self {
self.pressed_color = Some(c);
self
}
pub fn font_family(mut self, f: impl Into<String>) -> Self {
self.font_family = f.into();
self
}
pub fn font_weight(mut self, w: impl Into<FontWeight>) -> Self {
self.font_weight = w.into();
self
}
pub fn line_height(mut self, h: f64) -> Self {
self.line_height = Some(h);
self
}
pub fn max_width(mut self, w: f64) -> Self {
self.max_width = Some(w);
self
}
pub fn text_align(mut self, a: TextAlign) -> Self {
self.text_align = a;
self
}
pub fn wrap(mut self, v: bool) -> Self {
self.wrap = v;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ImageStyle {
pub width: u32,
pub height: u32,
pub opacity: f32,
pub fit: ImageFit,
pub border_radius: f32,
}
impl Default for ImageStyle {
fn default() -> Self {
Self {
width: 0,
height: 0,
opacity: 1.0,
fit: ImageFit::Fill,
border_radius: 0.0,
}
}
}
impl ImageStyle {
pub fn new() -> Self {
Self::default()
}
pub fn size(mut self, w: u32, h: u32) -> Self {
self.width = w;
self.height = h;
self
}
pub fn opacity(mut self, o: f32) -> Self {
self.opacity = o.clamp(0.0, 1.0);
self
}
pub fn fit(mut self, f: ImageFit) -> Self {
self.fit = f;
self
}
pub fn radius(mut self, r: f32) -> Self {
self.border_radius = r;
self
}
}