Skip to content

Commit

Permalink
Rename Transparency to WithAlpha
Browse files Browse the repository at this point in the history
  • Loading branch information
Ogeon committed Apr 5, 2020
1 parent 9084414 commit b7b45e0
Show file tree
Hide file tree
Showing 16 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions palette/src/alpha/alpha.rs
Expand Up @@ -15,7 +15,7 @@ use crate::encoding::pixel::RawPixel;
use crate::float::Float;
use crate::{
clamp, Blend, Component, ComponentWise, GetHue, Hue, Limited, Mix, Pixel, Saturate, Shade,
Transparency,
WithAlpha,
};

/// An alpha component wrapper for colors.
Expand Down Expand Up @@ -44,7 +44,7 @@ impl<C, T: Component> Alpha<C, T> {
}
}

impl<C1: Transparency<T>, C2, T: Component> FromColorUnclamped<C1> for Alpha<C2, T>
impl<C1: WithAlpha<T>, C2, T: Component> FromColorUnclamped<C1> for Alpha<C2, T>
where
C1::Color: IntoColorUnclamped<C2>,
{
Expand All @@ -58,7 +58,7 @@ where
}
}

impl<C, A: Component> Transparency<A> for Alpha<C, A> {
impl<C, A: Component> WithAlpha<A> for Alpha<C, A> {
type Color = C;
type WithAlpha = Self;

Expand Down
26 changes: 13 additions & 13 deletions palette/src/alpha/mod.rs
@@ -1,15 +1,15 @@
use crate::Component;

#[doc(hidden)]
pub use palette_derive::Transparency;
pub use palette_derive::WithAlpha;

pub use self::alpha::*;

mod alpha;

/// A trait for color types that can have or be given transparency (alpha channel).
///
/// `Transparency` is an interface for adding, removing and setting the alpha
/// `WithAlpha` is an interface for adding, removing and setting the alpha
/// channel of a color type. The color type itself doesn't need to store the
/// transparency value as it can be transformed into or wrapped in a type that
/// has a representation of transparency. This would typically be done by
Expand All @@ -23,9 +23,9 @@ mod alpha;
/// Derived without an internal alpha channel:
///
/// ```
/// use palette::Transparency;
/// use palette::WithAlpha;
///
/// #[derive(Transparency)]
/// #[derive(WithAlpha)]
/// struct CustomColor {
/// redness: f32,
/// glow: f32,
Expand All @@ -45,9 +45,9 @@ mod alpha;
/// Derived with an internal alpha channel:
///
/// ```
/// use palette::Transparency;
/// use palette::WithAlpha;
///
/// #[derive(Transparency)]
/// #[derive(WithAlpha)]
/// struct CustomColor {
/// redness: f32,
/// glow: f32,
Expand All @@ -67,7 +67,7 @@ mod alpha;
///
/// assert_eq!(transparent.alpha, 10);
/// ```
pub trait Transparency<A: Component>: Sized {
pub trait WithAlpha<A: Component>: Sized {
/// The opaque color type, without any transparency.
///
/// This is typically `Self`.
Expand All @@ -76,14 +76,14 @@ pub trait Transparency<A: Component>: Sized {
/// The color type with transparency applied.
///
/// This is typically `Alpha<Self::Color, A>`.
type WithAlpha: Transparency<A, Color = Self::Color, WithAlpha = Self::WithAlpha>;
type WithAlpha: WithAlpha<A, Color = Self::Color, WithAlpha = Self::WithAlpha>;

/// Transforms the color into a transparent color with the provided
/// alpha value. If `Self` already has a transparency, it is
/// overwritten.
///
/// ```
/// use palette::{Srgb, Transparency};
/// use palette::{Srgb, WithAlpha};
///
/// let color = Srgb::new(255u8, 0, 255);
///
Expand All @@ -102,7 +102,7 @@ pub trait Transparency<A: Component>: Sized {
/// `A::max_intensity()` to make it opaque.
///
/// ```
/// use palette::{Srgba, Srgb, Transparency};
/// use palette::{Srgba, Srgb, WithAlpha};
///
/// let transparent = Srgba::new(255u8, 0, 255, 10);
///
Expand All @@ -120,7 +120,7 @@ pub trait Transparency<A: Component>: Sized {
/// `A::max_intensity()` to make it opaque.
///
/// ```
/// use palette::{Srgba, Srgb, Transparency};
/// use palette::{Srgba, Srgb, WithAlpha};
///
/// let transparent = Srgba::new(255u8, 0, 255, 10);
///
Expand All @@ -135,7 +135,7 @@ pub trait Transparency<A: Component>: Sized {
/// field. If `Self` already has a transparency, it is overwritten.
///
/// ```
/// use palette::{Srgb, Srgba, Transparency};
/// use palette::{Srgb, Srgba, WithAlpha};
///
/// let color = Srgb::new(255u8, 0, 255);
///
Expand All @@ -150,7 +150,7 @@ pub trait Transparency<A: Component>: Sized {
/// already has a transparency, it is overwritten.
///
/// ```
/// use palette::{Srgb, Srgba, Transparency};
/// use palette::{Srgb, Srgba, WithAlpha};
///
/// let color = Srgb::new(255u8, 0, 255);
///
Expand Down
10 changes: 5 additions & 5 deletions palette/src/convert.rs
Expand Up @@ -6,7 +6,7 @@
//! The default minimum requirement is to implement `FromColorUnclamped<Xyz>`, but it can
//! also be customized to make use of generics and have other manual implementations.
//!
//! It is also recommended to derive or implement [`Transparency`](../trait.Transparency.html),
//! It is also recommended to derive or implement [`WithAlpha`](../trait.WithAlpha.html),
//! to be able to convert between all `Alpha` wrapped color types.
//!
//! ## Configuration Attributes
Expand Down Expand Up @@ -200,7 +200,7 @@
//! #[macro_use]
//! extern crate approx;
//!
//! use palette::{LinSrgba, Srgb, IntoColor, Transparency};
//! use palette::{LinSrgba, Srgb, IntoColor, WithAlpha};
//! use palette::rgb::{Rgb, RgbSpace, RgbStandard};
//! use palette::encoding::Linear;
//! use palette::white_point::D65;
Expand All @@ -211,7 +211,7 @@
//! skip_derives(Rgb),
//! rgb_space = "palette::encoding::Srgb"
//! )]
//! #[derive(PartialEq, Debug, FromColorUnclamped, Transparency)]
//! #[derive(PartialEq, Debug, FromColorUnclamped, WithAlpha)]
//! struct CssRgb {
//! red: u8,
//! green: u8,
Expand Down Expand Up @@ -532,7 +532,7 @@ mod tests {
palette_internal,
palette_internal_not_base_type
)]
#[derive(FromColorUnclamped, Transparency)]
#[derive(FromColorUnclamped, WithAlpha)]
struct WithXyz<S: RgbSpace>(PhantomData<S>);

impl<S: RgbSpace> Clone for WithXyz<S> {
Expand Down Expand Up @@ -601,7 +601,7 @@ mod tests {
palette_internal,
palette_internal_not_base_type
)]
#[derive(Copy, Clone, FromColorUnclamped, Transparency)]
#[derive(Copy, Clone, FromColorUnclamped, WithAlpha)]
struct WithoutXyz<T: FloatComponent>(PhantomData<T>);

impl<T: FloatComponent> Limited for WithoutXyz<T> {
Expand Down
2 changes: 1 addition & 1 deletion palette/src/hsl.rs
Expand Up @@ -35,7 +35,7 @@ pub type Hsla<S = Srgb, T = f32> = Alpha<Hsl<S, T>, T>;
///
/// See [HSV](struct.Hsv.html) for a very similar color space, with brightness
/// instead of lightness.
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
2 changes: 1 addition & 1 deletion palette/src/hsv.rs
Expand Up @@ -32,7 +32,7 @@ pub type Hsva<S = Srgb, T = f32> = Alpha<Hsv<S, T>, T>;
/// _lightness_. The difference is that, for example, red (100% R, 0% G, 0% B)
/// and white (100% R, 100% G, 100% B) has the same brightness (or value), but
/// not the same lightness.
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
2 changes: 1 addition & 1 deletion palette/src/hwb.rs
Expand Up @@ -33,7 +33,7 @@ pub type Hwba<S = Srgb, T = f32> = Alpha<Hwb<S, T>, T>;
///
/// It is very intuitive for humans to use and many color-pickers are based on
/// the HWB color system
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
2 changes: 1 addition & 1 deletion palette/src/lab.rs
Expand Up @@ -33,7 +33,7 @@ pub type Laba<Wp, T = f32> = Alpha<Lab<Wp, T>, T>;
///
/// The parameters of L\*a\*b\* are quite different, compared to many other
/// color spaces, so manipulating them manually may be unintuitive.
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
2 changes: 1 addition & 1 deletion palette/src/lch.rs
Expand Up @@ -28,7 +28,7 @@ pub type Lcha<Wp, T = f32> = Alpha<Lch<Wp, T>, T>;
/// it's a cylindrical color space, like [HSL](struct.Hsl.html) and
/// [HSV](struct.Hsv.html). This gives it the same ability to directly change
/// the hue and colorfulness of a color, while preserving other visual aspects.
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
2 changes: 1 addition & 1 deletion palette/src/lib.rs
Expand Up @@ -185,7 +185,7 @@ use float::Float;

use luma::Luma;

pub use alpha::{Alpha, Transparency};
pub use alpha::{Alpha, WithAlpha};
pub use blend::Blend;
#[cfg(feature = "std")]
pub use gradient::Gradient;
Expand Down
2 changes: 1 addition & 1 deletion palette/src/luma/luma.rs
Expand Up @@ -33,7 +33,7 @@ pub type Lumaa<S = Srgb, T = f32> = Alpha<Luma<S, T>, T>;
/// perceived to be. It's basically the `Y` component of [CIE
/// XYZ](struct.Xyz.html). The lack of any form of hue representation limits
/// the set of operations that can be performed on it.
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
2 changes: 1 addition & 1 deletion palette/src/rgb/rgb.rs
Expand Up @@ -43,7 +43,7 @@ pub type Rgba<S = Srgb, T = f32> = Alpha<Rgb<S, T>, T>;
/// linear, meaning that gamma correction is required when converting to and
/// from a displayable RGB, such as sRGB. See the [`pixel`](pixel/index.html)
/// module for encoding formats.
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
2 changes: 1 addition & 1 deletion palette/src/xyz.rs
Expand Up @@ -32,7 +32,7 @@ pub type Xyza<Wp = D65, T = f32> = Alpha<Xyz<Wp, T>, T>;
///
/// Conversions and operations on this color space depend on the defined white
/// point
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
2 changes: 1 addition & 1 deletion palette/src/yxy.rs
Expand Up @@ -28,7 +28,7 @@ pub type Yxya<Wp = D65, T = f32> = Alpha<Yxy<Wp, T>, T>;
/// for the color spaces are a plot of this color space's x and y coordiantes.
///
/// Conversions and operations on this color space depend on the white point.
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, Transparency)]
#[derive(Debug, PartialEq, Pixel, FromColorUnclamped, WithAlpha)]
#[cfg_attr(feature = "serializing", derive(Serialize, Deserialize))]
#[palette(
palette_internal,
Expand Down
4 changes: 2 additions & 2 deletions palette_derive/src/alpha/mod.rs
@@ -1,3 +1,3 @@
pub use self::transparency::derive as derive_transparency;
pub use self::with_alpha::derive as derive_with_alpha;

mod transparency;
mod with_alpha;
Expand Up @@ -49,14 +49,14 @@ fn implement_for_internal_alpha(
alpha_type: &Type,
item_meta: &TypeItemAttributes,
) -> TokenStream2 {
let transparency_trait_path = util::path(["Transparency"], item_meta.internal);
let with_alpha_trait_path = util::path(["WithAlpha"], item_meta.internal);
let component_trait_path = util::path(["Component"], item_meta.internal);

let (impl_generics, type_generics, where_clause) = generics.split_for_impl();

quote! {
#[automatically_derived]
impl #impl_generics #transparency_trait_path<#alpha_type> for #ident #type_generics #where_clause {
impl #impl_generics #with_alpha_trait_path<#alpha_type> for #ident #type_generics #where_clause {
type Color = Self;
type WithAlpha = Self;

Expand Down Expand Up @@ -84,7 +84,7 @@ fn implement_for_external_alpha(
generics: &Generics,
item_meta: &TypeItemAttributes,
) -> TokenStream2 {
let transparency_trait_path = util::path(["Transparency"], item_meta.internal);
let with_alpha_trait_path = util::path(["WithAlpha"], item_meta.internal);
let component_trait_path = util::path(["Component"], item_meta.internal);
let alpha_path = util::path(["Alpha"], item_meta.internal);

Expand All @@ -101,7 +101,7 @@ fn implement_for_external_alpha(

quote! {
#[automatically_derived]
impl #impl_generics #transparency_trait_path<#alpha_type> for #ident #type_generics #where_clause {
impl #impl_generics #with_alpha_trait_path<#alpha_type> for #ident #type_generics #where_clause {
type Color = Self;
type WithAlpha = #alpha_path<Self, #alpha_type>;

Expand Down
6 changes: 3 additions & 3 deletions palette_derive/src/lib.rs
Expand Up @@ -52,9 +52,9 @@ const PREFERRED_CONVERSION_SOURCE: &[(&str, &str)] = &[
("Yxy", "Xyz"),
];

#[proc_macro_derive(Transparency, attributes(palette))]
pub fn derive_transparency(tokens: TokenStream) -> TokenStream {
syn_try!(alpha::derive_transparency(tokens))
#[proc_macro_derive(WithAlpha, attributes(palette))]
pub fn derive_with_alpha(tokens: TokenStream) -> TokenStream {
syn_try!(alpha::derive_with_alpha(tokens))
}

#[proc_macro_derive(FromColorUnclamped, attributes(palette))]
Expand Down

0 comments on commit b7b45e0

Please sign in to comment.