#[repr(C)]pub struct Hsla {
pub h: f32,
pub s: f32,
pub l: f32,
pub a: f32,
}Expand description
An HSLA color
Fields§
§h: f32Hue, in a range from 0 to 1
s: f32Saturation, in a range from 0 to 1
l: f32Lightness, in a range from 0 to 1
a: f32Alpha, in a range from 0 to 1
Implementations§
Source§impl Hsla
impl Hsla
Sourcepub const fn transparent_black() -> Self
pub const fn transparent_black() -> Self
The color transparent black
Sourcepub fn is_transparent(&self) -> bool
pub fn is_transparent(&self) -> bool
Returns true if the HSLA color is fully transparent, false otherwise.
Sourcepub fn is_opaque(&self) -> bool
pub fn is_opaque(&self) -> bool
Returns true if the HSLA color is fully opaque, false otherwise.
Sourcepub fn blend(self, other: Hsla) -> Hsla
pub fn blend(self, other: Hsla) -> Hsla
Blends other on top of self based on other’s alpha value. The resulting color is a combination of self’s and other’s colors.
If other’s alpha value is 1.0 or greater, other color is fully opaque, thus other is returned as the output color.
If other’s alpha value is 0.0 or less, other color is fully transparent, thus self is returned as the output color.
Else, the output color is calculated as a blend of self and other based on their weighted alpha values.
Assumptions:
- Alpha values are contained in the range [0, 1], with 1 as fully opaque and 0 as fully transparent.
- The relative contributions of
selfandotheris based onself’s alpha value (self.a) andother’s alpha value (other.a),selfcontributingself.a * (1.0 - other.a)andothercontributing its own alpha value. - RGB color components are contained in the range [0, 1].
- If
selfandothercolors are out of the valid range, the blend operation’s output and behavior is undefined.
Sourcepub fn grayscale(&self) -> Self
pub fn grayscale(&self) -> Self
Returns a new HSLA color with the same hue, and lightness, but with no saturation.
Sourcepub fn fade_out(&mut self, factor: f32)
pub fn fade_out(&mut self, factor: f32)
Fade out the color by a given factor. This factor should be between 0.0 and 1.0. Where 0.0 will leave the color unchanged, and 1.0 will completely fade out the color.
Sourcepub fn opacity(&self, factor: f32) -> Self
pub fn opacity(&self, factor: f32) -> Self
Multiplies the alpha value of the color by a given factor and returns a new HSLA color.
Useful for transforming colors with dynamic opacity, like a color from an external source.
Example:
let color = gpui::red();
let faded_color = color.opacity(0.5);
assert_eq!(faded_color.a, 0.5);This will return a red color with half the opacity.
Example:
use gpui::hsla;
let color = hsla(0.7, 1.0, 0.5, 0.7); // A saturated blue
let faded_color = color.opacity(0.16);
assert!((faded_color.a - 0.112).abs() < 1e-6);This will return a blue color with around ~10% opacity, suitable for an element’s hover or selected state.
Sourcepub fn alpha(&self, a: f32) -> Self
pub fn alpha(&self, a: f32) -> Self
Returns a new HSLA color with the same hue, saturation, and lightness, but with a new alpha value.
Example:
let color = gpui::red();
let red_color = color.alpha(0.25);
assert_eq!(red_color.a, 0.25);This will return a red color with half the opacity.
Example:
use gpui::hsla;
let color = hsla(0.7, 1.0, 0.5, 0.7); // A saturated blue
let faded_color = color.alpha(0.25);
assert_eq!(faded_color.a, 0.25);This will return a blue color with 25% opacity.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Hsla
impl<'de> Deserialize<'de> for Hsla
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl From<Hsla> for Background
impl From<Hsla> for Background
Source§impl From<Hsla> for HighlightStyle
impl From<Hsla> for HighlightStyle
Source§impl JsonSchema for Hsla
impl JsonSchema for Hsla
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read moreSource§impl Ord for Hsla
impl Ord for Hsla
Source§impl PartialOrd for Hsla
impl PartialOrd for Hsla
impl Copy for Hsla
impl Eq for Hsla
Auto Trait Implementations§
impl Freeze for Hsla
impl RefUnwindSafe for Hsla
impl Send for Hsla
impl Sync for Hsla
impl Unpin for Hsla
impl UnwindSafe for Hsla
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<K> MapSeekTarget<K> for Kwhere
K: Ord,
impl<K> MapSeekTarget<K> for Kwhere
K: Ord,
fn cmp_cursor(&self, cursor_location: &K) -> Ordering
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().