Skip to main content

FrameBuffer

Struct FrameBuffer 

Source
pub struct FrameBuffer<M: PixelMap, const N: usize> { /* private fields */ }
Available on crate feature framebuffer only.
Expand description

Frame buffer in the native GRAM layout M, drawn in the logical orientation rotation.

Pixel coordinates and rows are logical, the bytes (Self::as_bytes) are always native and are sent to the panel as they are. Changing the rotation does not move the existing pixels: redraw the frame after Self::set_rotation.

Implementations§

Source§

impl<M: PixelMap, const N: usize> FrameBuffer<M, N>

Source

pub const fn new() -> Self

Empty (all pixels off) buffer in Rotation::Deg0. N must equal M::BUFFER_LEN (checked at compile time).

Source

pub const fn with_rotation(self, rotation: Rotation) -> Self

Same buffer with another orientation, see Self::set_rotation.

Source

pub const fn rotation(&self) -> Rotation

Current orientation.

Source

pub fn set_rotation(&mut self, rotation: Rotation)

Changes the orientation of the coordinates. The buffer content is not touched, so the image turns into noise until it is redrawn.

Source

pub const fn logical_size(&self) -> (u32, u32)

Logical (width, height) for the current rotation.

Source

pub fn set_pixel(&mut self, x: u32, y: u32, on: bool)

Sets the logical pixel (x, y); coordinates outside the logical size are ignored.

Source

pub fn get_pixel(&self, x: u32, y: u32) -> Option<bool>

Reads the logical pixel (x, y), None outside the logical size.

Source

pub fn fill(&mut self, on: bool)

Sets every pixel on or off. Same as DrawTarget::clear with BinaryColor.

Source

pub fn as_bytes(&self) -> &[u8]

Native bytes, ready to be sent to the panel (write_ram_data).

Source

pub fn window(&self, area: Rectangle) -> Option<Window>

The GRAM window that covers the logical rectangle area (clipped to the logical size), None if nothing of area is on the panel. Takes the rotation into account; see Window::covering for the native version.

Source

pub fn copy_window<'a>(&self, window: &Window, out: &'a mut [u8]) -> &'a [u8]

The bytes of window taken from the frame into out, ready for RAMWR after set_address_window; returns &out[..window.byte_len()]. The window must come from Self::window or Window::covering for the same M.

§Panics

If out is shorter than window.byte_len().

Source

pub fn as_bytes_mut(&mut self) -> &mut [u8] ⓘ

Mutable native bytes. The layout is that of M, independent of the rotation.

Source

pub fn fill_with(&mut self, f: impl FnMut() -> u8)

Fills the native bytes with values from f, in buffer order.

Source

pub fn read_row(&self, y: u32, out: &mut [bool]) -> bool

Reads a logical row y into out (out.len() == logical width). Returns true if at least one pixel in the row is on.

A logical row is a native row (Deg0, Deg180) or a native column (Deg90, Deg270), possibly in the reverse order, so every orientation uses a whole-line path.

Source

pub fn write_row(&mut self, y: u32, row: &[bool])

Writes a logical row y from row (row.len() == logical width). Only sets pixels, never clears them: the row must be cleared beforehand (see PixelMap::write_row).

Trait Implementations§

Source§

impl<M: PixelMap, const N: usize> Debug for FrameBuffer<M, N>

Prints the geometry and the rotation, not the bytes.

Source§

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

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

impl<M: PixelMap, const N: usize> Default for FrameBuffer<M, N>

Source§

fn default() -> Self

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

impl<M: PixelMap, const N: usize> DrawTarget for FrameBuffer<M, N>

Source§

fn clear(&mut self, color: Self::Color) -> Result<(), Self::Error>

Fills the whole buffer at once instead of pixel by pixel.

Source§

type Color = BinaryColor

The pixel color type the targetted display supports.
Source§

type Error = !

Error type to return when a drawing operation fails. Read more
Source§

fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
where I: IntoIterator<Item = Pixel<Self::Color>>,

Draw individual pixels to the display without a defined order. Read more
Source§

fn fill_contiguous<I>( &mut self, area: &Rectangle, colors: I, ) -> Result<(), Self::Error>
where I: IntoIterator<Item = Self::Color>,

Fill a given area with an iterator providing a contiguous stream of pixel colors. Read more
Source§

fn fill_solid( &mut self, area: &Rectangle, color: Self::Color, ) -> Result<(), Self::Error>

Fill a given area with a solid color. Read more
Source§

impl<M: PixelMap, const N: usize> OriginDimensions for FrameBuffer<M, N>

Source§

fn size(&self) -> Size

Returns the size of the bounding box.

Auto Trait Implementations§

§

impl<M, const N: usize> Freeze for FrameBuffer<M, N>
where [u8; N]: Freeze, PhantomData<M>: Freeze,

§

impl<M, const N: usize> RefUnwindSafe for FrameBuffer<M, N>

§

impl<M, const N: usize> Send for FrameBuffer<M, N>
where [u8; N]: Send, PhantomData<M>: Send,

§

impl<M, const N: usize> Sync for FrameBuffer<M, N>
where [u8; N]: Sync, PhantomData<M>: Sync,

§

impl<M, const N: usize> Unpin for FrameBuffer<M, N>
where [u8; N]: Unpin, PhantomData<M>: Unpin,

§

impl<M, const N: usize> UnsafeUnpin for FrameBuffer<M, N>

§

impl<M, const N: usize> UnwindSafe for FrameBuffer<M, N>

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> Az for T

Source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
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<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

Source§

fn cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> CheckedAs for T

Source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

Source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
Source§

impl<T> Dimensions for T

Source§

fn bounding_box(&self) -> Rectangle

Returns the bounding box.
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> OverflowingAs for T

Source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

Source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
Source§

impl<T> SaturatingAs for T

Source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

Source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
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.
Source§

impl<T> UnwrappedAs for T

Source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

Source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
Source§

impl<T> WrappingAs for T

Source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
Source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

Source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.