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§
sourcefn clamp_assign(&mut self)
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));