Use Color in more places
This commit is contained in:
parent
4edca946ea
commit
3ece9236b3
9 changed files with 84 additions and 53 deletions
28
src/attrs.rs
28
src/attrs.rs
|
|
@ -6,10 +6,14 @@ pub use fontdb::{Family, Stretch, Style, Weight};
|
|||
pub struct Color(pub u32);
|
||||
|
||||
impl Color {
|
||||
/// Create new color with red, green, and blue components
|
||||
#[inline]
|
||||
pub const fn rgb(r: u8, g: u8, b: u8) -> Self {
|
||||
Self::rgba(r, g, b, 0xFF)
|
||||
}
|
||||
|
||||
/// Create new color with red, green, blue, and alpha components
|
||||
#[inline]
|
||||
pub const fn rgba(r: u8, g: u8, b: u8, a: u8) -> Self {
|
||||
Self(
|
||||
((a as u32) << 24) |
|
||||
|
|
@ -18,6 +22,30 @@ impl Color {
|
|||
(b as u32)
|
||||
)
|
||||
}
|
||||
|
||||
/// Get the red component
|
||||
#[inline]
|
||||
pub fn r(&self) -> u8 {
|
||||
((self.0 & 0x00FF0000) >> 16) as u8
|
||||
}
|
||||
|
||||
/// Get the green component
|
||||
#[inline]
|
||||
pub fn g(&self) -> u8 {
|
||||
((self.0 & 0x0000FF00) >> 8) as u8
|
||||
}
|
||||
|
||||
/// Get the blue component
|
||||
#[inline]
|
||||
pub fn b(&self) -> u8 {
|
||||
(self.0 & 0x000000FF) as u8
|
||||
}
|
||||
|
||||
/// Get the alpha component
|
||||
#[inline]
|
||||
pub fn a(&self) -> u8 {
|
||||
((self.0 & 0xFF000000) >> 24) as u8
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue