Skip to main content

Rgba

Struct Rgba 

Source
#[repr(C)]
pub struct Rgba { pub r: u8, pub g: u8, pub b: u8, pub a: u8, }
Expand description

One RGBA8 pixel of the graphics model (straight, not premultiplied, alpha). In the buffer: the bytes r, g, b, a.

Fields§

§r: u8§g: u8§b: u8§a: u8

Implementations§

Source§

impl Rgba

Source

pub const TRANSPARENT: Self

Source

pub const BLACK: Self

Source

pub const WHITE: Self

Source

pub const fn new(r: u8, g: u8, b: u8, a: u8) -> Self

Source

pub const fn rgb(r: u8, g: u8, b: u8) -> Self

Opaque.

Source

pub const fn hex(rgb: u32) -> Self

0xRRGGBB, opaque (the form crate::view::Theme reports).

Examples found in repository?
examples/shapes_stage.rs (line 32)
24    fn frame(&mut self, frame: &Frame) {
25        let (w, h) = self.stage.size();
26        if w == 0 || h == 0 {
27            // No pixel geometry yet: a resize will follow.
28            return;
29        }
30        let theme = view::theme();
31        let (fg, bg, accent) = (
32            Rgba::hex(theme.fg),
33            Rgba::hex(theme.bg),
34            Rgba::hex(theme.accent),
35        );
36        let t = (frame.now_ms() % 4000) as f32 / 4000.0;
37
38        // A full repaint: nothing is carried forward from the last frame.
39        self.stage.clear(bg);
40        let panel = Area::new(8, 8, w.saturating_sub(16), h.saturating_sub(16));
41        self.stage
42            .fill_rounded_rect(panel, 12, Rgba::hex(theme.recede_bg));
43        self.stage
44            .rounded_rect(panel, 12, Rgba::hex(theme.recede_fg));
45
46        let (cx, cy) = (w as f32 / 2.0, h as f32 / 2.0);
47        let radius = (w.min(h) / 4) as f32;
48        let angle = t * core::f32::consts::TAU;
49        // `no_std` has no `f32::sin`: the SDK re-exports `libm`. The dot
50        // moves between pixels; the shapes antialias it there.
51        let dot = (
52            cx + radius * libm::cosf(angle),
53            cy + radius * libm::sinf(angle),
54        );
55        self.stage
56            .circle((cx, cy), radius, Rgba::hex(theme.recede_fg));
57        self.stage
58            .line((cx as i32, cy as i32), (dot.0 as i32, dot.1 as i32), accent);
59        self.stage.fill_circle(dot, 6.0, accent);
60
61        let bar = Area::new(24, h as i32 - 40, w.saturating_sub(48), 8);
62        self.stage
63            .bar(bar, t, accent, Rgba::hex(theme.recede_fg).with_alpha(96));
64        self.stage.label(24, 24, "shapes", fg);
65        let _ = self.stage.commit();
66
67        match frame.power() {
68            Power::Mains => frame.request_frame(),
69            Power::SavePower => frame.wake_after(1000),
70        }
71    }
Source

pub const fn with_alpha(self, a: u8) -> Self

Examples found in repository?
examples/shapes_stage.rs (line 63)
24    fn frame(&mut self, frame: &Frame) {
25        let (w, h) = self.stage.size();
26        if w == 0 || h == 0 {
27            // No pixel geometry yet: a resize will follow.
28            return;
29        }
30        let theme = view::theme();
31        let (fg, bg, accent) = (
32            Rgba::hex(theme.fg),
33            Rgba::hex(theme.bg),
34            Rgba::hex(theme.accent),
35        );
36        let t = (frame.now_ms() % 4000) as f32 / 4000.0;
37
38        // A full repaint: nothing is carried forward from the last frame.
39        self.stage.clear(bg);
40        let panel = Area::new(8, 8, w.saturating_sub(16), h.saturating_sub(16));
41        self.stage
42            .fill_rounded_rect(panel, 12, Rgba::hex(theme.recede_bg));
43        self.stage
44            .rounded_rect(panel, 12, Rgba::hex(theme.recede_fg));
45
46        let (cx, cy) = (w as f32 / 2.0, h as f32 / 2.0);
47        let radius = (w.min(h) / 4) as f32;
48        let angle = t * core::f32::consts::TAU;
49        // `no_std` has no `f32::sin`: the SDK re-exports `libm`. The dot
50        // moves between pixels; the shapes antialias it there.
51        let dot = (
52            cx + radius * libm::cosf(angle),
53            cy + radius * libm::sinf(angle),
54        );
55        self.stage
56            .circle((cx, cy), radius, Rgba::hex(theme.recede_fg));
57        self.stage
58            .line((cx as i32, cy as i32), (dot.0 as i32, dot.1 as i32), accent);
59        self.stage.fill_circle(dot, 6.0, accent);
60
61        let bar = Area::new(24, h as i32 - 40, w.saturating_sub(48), 8);
62        self.stage
63            .bar(bar, t, accent, Rgba::hex(theme.recede_fg).with_alpha(96));
64        self.stage.label(24, 24, "shapes", fg);
65        let _ = self.stage.commit();
66
67        match frame.power() {
68            Power::Mains => frame.request_frame(),
69            Power::SavePower => frame.wake_after(1000),
70        }
71    }
Source

pub const fn to_word(self) -> u32

The little-endian word the buffer stores.

Source

pub const fn from_word(word: u32) -> Self

Source

pub fn over(self, below: Self, coverage: u8) -> Self

self drawn over below with extra coverage (0 to 255), straight alpha “source over”.

Trait Implementations§

Source§

impl Clone for Rgba

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Rgba

Source§

impl Debug for Rgba

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Rgba

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Rgba

Source§

impl Hash for Rgba

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Rgba

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Rgba

Auto Trait Implementations§

§

impl Freeze for Rgba

§

impl RefUnwindSafe for Rgba

§

impl Send for Rgba

§

impl Sync for Rgba

§

impl Unpin for Rgba

§

impl UnsafeUnpin for Rgba

§

impl UnwindSafe for Rgba

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Resource for T
where T: 'static,

Source§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.