use std::any::TypeId;
use vello::kurbo::Rect;
use crate::core::{Property, UpdateCtx};
use crate::peniko::color::{AlphaColor, Srgb};
use crate::properties::types::Gradient;
#[expect(missing_docs, reason = "field names are self-descriptive")]
#[derive(Clone, Debug, PartialEq)]
pub enum Background {
Color(AlphaColor<Srgb>),
Gradient(Gradient),
}
#[derive(Clone, Debug, PartialEq)]
pub struct ActiveBackground(pub Background);
#[derive(Clone, Debug, PartialEq)]
pub struct DisabledBackground(pub Background);
impl Property for Background {
fn static_default() -> &'static Self {
static DEFAULT: Background = Background::Color(AlphaColor::TRANSPARENT);
&DEFAULT
}
}
impl Default for Background {
fn default() -> Self {
Self::static_default().clone()
}
}
impl Background {
pub fn prop_changed(ctx: &mut UpdateCtx<'_>, property_type: TypeId) {
if property_type != TypeId::of::<Self>() {
return;
}
ctx.request_paint_only();
}
pub fn get_peniko_brush_for_rect(&self, rect: Rect) -> crate::peniko::Brush {
match self {
Self::Color(color) => (*color).into(),
Self::Gradient(gradient) => gradient.get_peniko_gradient_for_rect(rect).into(),
}
}
}
impl Property for ActiveBackground {
fn static_default() -> &'static Self {
const DEFAULT: ActiveBackground =
ActiveBackground(Background::Color(AlphaColor::TRANSPARENT));
&DEFAULT
}
}
impl Default for ActiveBackground {
fn default() -> Self {
Self::static_default().clone()
}
}
impl ActiveBackground {
pub fn prop_changed(ctx: &mut UpdateCtx<'_>, property_type: TypeId) {
if property_type != TypeId::of::<Self>() {
return;
}
ctx.request_paint_only();
}
}
impl Property for DisabledBackground {
fn static_default() -> &'static Self {
const DEFAULT: DisabledBackground =
DisabledBackground(Background::Color(AlphaColor::TRANSPARENT));
&DEFAULT
}
}
impl Default for DisabledBackground {
fn default() -> Self {
Self::static_default().clone()
}
}
impl DisabledBackground {
pub fn prop_changed(ctx: &mut UpdateCtx<'_>, property_type: TypeId) {
if property_type != TypeId::of::<Self>() {
return;
}
ctx.request_paint_only();
}
}