Skip to main content

Frame

Struct Frame 

Source
pub struct Frame {
    pub size_px: SizePx,
    pub clear_color: Rgba,
    pub layers: [Layer; 3],
    pub invalidation: Invalidation,
    pub pools: FramePools,
    pub styles: Vec<SeriesStyle>,
}
Expand description

The draw description of one frame.

§Examples

use ferrochart_core::frame::{DrawCmd, Frame, LayerId, RectInst};
use ferrochart_core::geom::{RectPx, Rgba};

let mut frame = Frame::default();
let r = RectInst { rect: RectPx { x: 0.0, y: 0.0, w: 2.0, h: 2.0 }, color: Rgba::hex(0) };
frame.push_rect(LayerId::Main, r);
frame.push_rect(LayerId::Main, r); // merged into the same command
assert_eq!(frame.layers[1].cmds.len(), 1);
assert!(matches!(frame.layers[1].cmds[0], DrawCmd::Rects(s) if s.len == 2));

Fields§

§size_px: SizePx

Size of the target in physical pixels.

§clear_color: Rgba

Background color the target is cleared to.

§layers: [Layer; 3]

Background, main and overlay layers.

§invalidation: Invalidation

What changed since the previous frame.

§pools: FramePools

Primitive pools.

§styles: Vec<SeriesStyle>

Resolved series styles, referenced by SeriesStyleRef.

Implementations§

Source§

impl Frame

Source

pub fn begin(&mut self, size: SizePx, clear: Rgba, invalidation: Invalidation)

Starts a new frame: clears all pools and commands, keeping their capacity, and sets the target size, clear color and invalidation.

use ferrochart_core::frame::{Frame, LayerId, RectInst};
use ferrochart_core::geom::{RectPx, Rgba, SizePx};
use ferrochart_core::frame::Invalidation;

let mut frame = Frame::default();
frame.reserve();
let r = RectInst { rect: RectPx { x: 0.0, y: 0.0, w: 2.0, h: 2.0 }, color: Rgba::hex(0) };
frame.push_rect(LayerId::Main, r);
frame.begin(SizePx { w: 100.0, h: 50.0 }, Rgba::hex(0xFF), Invalidation::Full);
assert!(frame.pools.rects.is_empty() && frame.layers[1].cmds.is_empty());
Source

pub fn reserve(&mut self)

Pre-allocates pools so that typical frames do not allocate.

Source

pub fn push_cmd(&mut self, layer: LayerId, cmd: DrawCmd)

Appends a command to a layer.

Source

pub fn push_style(&mut self, style: SeriesStyle) -> SeriesStyleRef

Adds a resolved style and returns its reference.

Source

pub fn push_rect(&mut self, layer: LayerId, rect: RectInst)

Adds a rectangle, extending the layer’s last Rects command if it ends at the end of the pool.

Source

pub fn push_line(&mut self, layer: LayerId, line: LineInst)

Adds a line, merging with the layer’s last Lines command when possible.

Source

pub fn push_text(&mut self, layer: LayerId, run: TextRun)

Adds a text run whose characters are pools.text[text] (already written), merging with the layer’s last Text command when possible.

Source

pub fn push_icon(&mut self, layer: LayerId, icon: IconInst)

Adds an icon, merging with the layer’s last Icon command when possible.

Source

pub fn push_str(&mut self, s: &str) -> Span

Writes s into the text pool and returns its span.

§Examples
use ferrochart_core::frame::Frame;

let mut frame = Frame::default();
let span = frame.push_str("2025");
assert_eq!(frame.pools.text_of(span), "2025");

Trait Implementations§

Source§

impl Clone for Frame

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 Debug for Frame

Source§

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

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

impl Default for Frame

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl Forget for Frame

§

impl Freeze for Frame

§

impl Move for Frame

§

impl RefUnwindSafe for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnsafeUnpin for Frame

§

impl UnwindSafe for Frame

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> 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.