Trait cosmic::cosmic_theme::palette::ClampAssign

source ·
pub trait ClampAssign {
    // Required method
    fn clamp_assign(&mut self);
}
Expand description

An assigning operator for restricting a color’s components to their expected ranges.

IsWithinBounds can be used to check if the components are within their range bounds.

See also Clamp.

use palette::{Srgb, IsWithinBounds, ClampAssign};

let mut color = Srgb::new(1.3f32, 0.5, -3.0);
assert!(!color.is_within_bounds());

color.clamp_assign();
assert!(color.is_within_bounds());
assert_eq!(color, Srgb::new(1.0, 0.5, 0.0));

ClampAssign is also implemented for [T]:

use palette::{Srgb, ClampAssign};

let mut my_vec = vec![Srgb::new(0.4, 0.3, 0.8), Srgb::new(1.3, 0.5, -3.0)];
let mut my_array = [Srgb::new(0.4, 0.3, 0.8), Srgb::new(1.3, 0.5, -3.0)];
let mut my_slice = &mut [Srgb::new(0.4, 0.3, 0.8), Srgb::new(1.2, 0.3, 0.8)];

my_vec.clamp_assign();
my_array.clamp_assign();
my_slice.clamp_assign();

Required Methods§

source

fn clamp_assign(&mut self)

Changes out-of-bounds components to the nearest valid values.

use palette::{Srgb, ClampAssign};

let mut color = Srgb::new(1.3, 0.5, -3.0);
color.clamp_assign();
assert_eq!(color, Srgb::new(1.0, 0.5, 0.0));

Implementations on Foreign Types§

source§

impl<T> ClampAssign for [T]
where T: ClampAssign,

source§

fn clamp_assign(&mut self)

Implementors§

source§

impl<C, T> ClampAssign for Alpha<C, T>

source§

impl<S, T> ClampAssign for Luma<S, T>
where T: ClampAssign + Stimulus,

source§

impl<S, T> ClampAssign for Rgb<S, T>
where T: ClampAssign + Stimulus,

source§

impl<S, T> ClampAssign for Hsl<S, T>
where T: ClampAssign + Stimulus,

source§

impl<S, T> ClampAssign for Hsv<S, T>
where T: ClampAssign + Stimulus,

source§

impl<S, T> ClampAssign for Hwb<S, T>
where T: One + ClampAssign + PartialCmp + Add<Output = T> + DivAssign + Clone + Stimulus, <T as HasBoolMask>::Mask: Select<T>,

source§

impl<T> ClampAssign for Cam16Jch<T>
where T: ClampAssign + Zero,

source§

impl<T> ClampAssign for Cam16Jmh<T>
where T: ClampAssign + Zero,

source§

impl<T> ClampAssign for Cam16Jsh<T>
where T: ClampAssign + Zero,

source§

impl<T> ClampAssign for Cam16Qch<T>
where T: ClampAssign + Zero,

source§

impl<T> ClampAssign for Cam16Qmh<T>
where T: ClampAssign + Zero,

source§

impl<T> ClampAssign for Cam16Qsh<T>
where T: ClampAssign + Zero,

source§

impl<T> ClampAssign for Cam16<T>
where T: ClampAssign + Zero,

source§

impl<T> ClampAssign for Cam16UcsJab<T>
where T: ClampAssign + Real + Zero,

source§

impl<T> ClampAssign for Cam16UcsJmh<T>
where T: ClampAssign + Zero + Real,

source§

impl<T> ClampAssign for Okhsl<T>
where T: ClampAssign + Stimulus,

source§

impl<T> ClampAssign for Okhsv<T>

source§

impl<T> ClampAssign for Okhwb<T>
where T: One + ClampAssign + PartialCmp + Add<Output = T> + DivAssign + Clone + Stimulus, <T as HasBoolMask>::Mask: Select<T>,

source§

impl<T> ClampAssign for Oklab<T>
where T: ClampAssign + Zero + One,

source§

impl<T> ClampAssign for Oklch<T>
where T: ClampAssign + Zero + One,

source§

impl<Wp, T> ClampAssign for Hsluv<Wp, T>
where T: ClampAssign + Real + Zero,

source§

impl<Wp, T> ClampAssign for Lab<Wp, T>
where T: ClampAssign + Real + Zero,

source§

impl<Wp, T> ClampAssign for Lch<Wp, T>
where T: ClampAssign + Real + Zero,

source§

impl<Wp, T> ClampAssign for Lchuv<Wp, T>
where T: ClampAssign + Real + Zero,

source§

impl<Wp, T> ClampAssign for Luv<Wp, T>
where T: ClampAssign + Real + Zero,

source§

impl<Wp, T> ClampAssign for Xyz<Wp, T>
where T: ClampAssign + Zero, Wp: WhitePoint<T>,

source§

impl<Wp, T> ClampAssign for Yxy<Wp, T>
where T: ClampAssign + Zero + One,