Skip to content

Commit 7c3eba9

Browse files
committed
Make alpha component private
1 parent b70ce60 commit 7c3eba9

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

src/pixel.rs

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@
2828
/// assert_eq!(red.r, 255);
2929
/// assert_eq!(red.g, 128);
3030
/// assert_eq!(red.b, 0);
31-
/// assert_eq!(red.a, 0xff);
32-
///
33-
/// let from_struct_literal = Pixel { r: 255, g: 0x80, b: 0, a: 0xff };
34-
/// assert_eq!(red, from_struct_literal);
3531
/// ```
3632
///
3733
/// Convert a pixel to an array of `u8`s.
@@ -63,15 +59,15 @@
6359
///
6460
/// if cfg!(any(target_family = "wasm", target_os = "android")) {
6561
/// // RGBX
66-
/// assert_eq!(red, u32::from_ne_bytes([0xff, 0x00, 0x00, 0xff]));
62+
/// assert_eq!(red, u32::from_ne_bytes([0xff, 0x00, 0x00, 0x00]));
6763
/// } else {
6864
/// // BGRX
69-
/// assert_eq!(red, u32::from_ne_bytes([0x00, 0x00, 0xff, 0xff]));
65+
/// assert_eq!(red, u32::from_ne_bytes([0x00, 0x00, 0xff, 0x00]));
7066
/// }
7167
/// ```
7268
#[repr(C)]
7369
#[repr(align(4))] // May help the compiler to see that this is a u32
74-
#[derive(Copy, Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)]
70+
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
7571
pub struct Pixel {
7672
#[cfg(any(target_family = "wasm", target_os = "android"))]
7773
/// The red component.
@@ -97,17 +93,28 @@ pub struct Pixel {
9793
///
9894
/// `0xff` here means opaque, whereas `0` means transparent.
9995
///
100-
/// NOTE: Transparency is yet poorly supported, see [#17], until that is resolved, you will
101-
/// probably want to set this to `0xff`.
96+
/// NOTE: Transparency is not yet supported, see [#17], so this doesn't actually do anything.
10297
///
10398
/// [#17]: https://github.com/rust-windowing/softbuffer/issues/17
104-
pub a: u8,
99+
pub(crate) a: u8,
100+
}
101+
102+
impl Default for Pixel {
103+
/// A black opaque pixel.
104+
fn default() -> Self {
105+
Self {
106+
r: 0,
107+
g: 0,
108+
b: 0,
109+
a: 0xff,
110+
}
111+
}
105112
}
106113

107114
impl Pixel {
108115
/// Creates a new pixel from a red, a green and a blue component.
109116
///
110-
/// The alpha component is set to opaque.
117+
/// The pixel is opaque.
111118
///
112119
/// # Example
113120
///
@@ -123,7 +130,7 @@ impl Pixel {
123130

124131
/// Creates a new pixel from a blue, a green and a red component.
125132
///
126-
/// The alpha component is set to opaque.
133+
/// The pixel is opaque.
127134
///
128135
/// # Example
129136
///

0 commit comments

Comments
 (0)