This commit is contained in:
Ashley Wulber 2026-02-03 16:45:44 -05:00
parent a489a6b790
commit e2918e0de9
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
19 changed files with 9291 additions and 60 deletions

View file

@ -22,6 +22,7 @@ a11y = ["iced_accessibility"]
wayland = ["cctk"]
[dependencies]
palette = "0.7"
bitflags.workspace = true
bytes.workspace = true
glam.workspace = true

View file

@ -24,6 +24,18 @@ impl Background {
}
}
impl From<palette::Srgba<f32>> for Background {
fn from(color: palette::Srgba<f32>) -> Self {
Background::Color(Color::from(color))
}
}
impl From<palette::Srgba<u8>> for Background {
fn from(color: palette::Srgba<u8>) -> Self {
Background::Color(Color::from(color))
}
}
impl From<Color> for Background {
fn from(color: Color) -> Self {
Background::Color(color)

View file

@ -269,6 +269,47 @@ impl std::fmt::Display for Color {
}
}
impl From<palette::Srgb<u8>> for Color {
fn from(srgb: palette::Srgb<u8>) -> Self {
Color::from_rgb8(srgb.red, srgb.green, srgb.blue)
}
}
impl From<palette::Srgba<u8>> for Color {
fn from(srgba: palette::Srgba<u8>) -> Self {
Color::from_rgba8(
srgba.red,
srgba.green,
srgba.blue,
srgba.alpha as f32 / 255.0,
)
}
}
impl From<palette::Srgb<f32>> for Color {
fn from(srgb: palette::Srgb<f32>) -> Self {
Color::from_rgb(srgb.red, srgb.green, srgb.blue)
}
}
impl From<palette::Srgba<f32>> for Color {
fn from(srgba: palette::Srgba<f32>) -> Self {
Color::from_rgba(srgba.red, srgba.green, srgba.blue, srgba.alpha)
}
}
impl From<Color> for palette::Srgb<f32> {
fn from(color: Color) -> Self {
palette::Srgb::new(color.r, color.g, color.b)
}
}
impl From<Color> for palette::Srgba<f32> {
fn from(color: Color) -> Self {
palette::Srgba::new(color.r, color.g, color.b, color.a)
}
}
/// Creates a [`Color`] with shorter and cleaner syntax.
///
/// # Examples

View file

@ -78,6 +78,12 @@ impl From<f32> for Length {
}
}
impl From<u16> for Length {
fn from(amount: u16) -> Self {
Length::Fixed(amount as f32)
}
}
impl From<u32> for Length {
fn from(units: u32) -> Self {
Length::Fixed(units as f32)

View file

@ -26,6 +26,18 @@ impl From<u32> for Pixels {
}
}
impl From<u16> for Pixels {
fn from(amount: u16) -> Self {
Self(amount as f32)
}
}
impl From<i32> for Pixels {
fn from(amount: i32) -> Self {
Self(amount as f32)
}
}
impl From<Pixels> for f32 {
fn from(pixels: Pixels) -> Self {
pixels.0