Skip to main content

WidgetApp

Struct WidgetApp 

Source
pub struct WidgetApp {
    pub width: u32,
    pub height: u32,
    pub font: FontCache,
    pub theme: ThemeData,
    /* private fields */
}
Expand description

Off-screen widget renderer — renders a widget tree to a SkiaCanvas or PNG bytes.

Use this for golden / snapshot tests: render a widget to PNG, save it, and compare future runs byte-for-byte to catch visual regressions.

For a real windowed app, use rosace::App from the umbrella crate instead.

// Render to PNG bytes (dark theme by default):
let png = WidgetApp::new(800, 600).render_png(&root);

// Light theme:
let png = WidgetApp::new(800, 600).light().render_png(&root);

// Custom theme:
let png = WidgetApp::new(800, 600).theme(my_theme).render_png(&root);

Fields§

§width: u32§height: u32§font: FontCache§theme: ThemeData

Implementations§

Source§

impl WidgetApp

Source

pub fn new(width: u32, height: u32) -> Self

Create a new app with the default dark theme.

Source

pub fn background(self, c: Color) -> Self

Override the background color explicitly (ignores theme background).

Source

pub fn with_font(self, f: FontCache) -> Self

Replace the font.

Source

pub fn theme(self, t: ThemeData) -> Self

Set a fully custom theme.

Source

pub fn dark(self) -> Self

Use the built-in dark theme (this is already the default).

Source

pub fn light(self) -> Self

Use the built-in light theme.

Source

pub fn render(&self, root: &dyn Widget) -> SkiaCanvas

Render the widget tree to a SkiaCanvas.

Source

pub fn render_into(&self, canvas: &mut SkiaCanvas, root: &dyn Widget)

Paint the widget tree onto an existing canvas (for windowed apps).

Source

pub fn render_png(&self, root: &dyn Widget) -> Vec<u8>

Render and encode to PNG bytes (convenience).

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.