Skip to main content

ImageWidget

Struct ImageWidget 

Source
pub struct ImageWidget {
    pub source: ImageSource,
    pub fit: ImageFit,
    pub width: f32,
    pub height: f32,
    pub placeholder_color: Color,
    pub alt: Option<String>,
}
Expand description

A widget that renders an image from a file path or raw bytes.

Falls back to a colored placeholder when the image cannot be decoded.

Fields§

§source: ImageSource§fit: ImageFit§width: f32§height: f32§placeholder_color: Color§alt: Option<String>

Accessible/SEO alt text (D107/Phase 25) — None produces no semantics entry at all (an image with no .alt(...) call is decorative, matching HTML’s own convention of an empty/absent alt attribute), not an empty-string placeholder.

Implementations§

Source§

impl ImageWidget

Source

pub fn new() -> Self

Create a new ImageWidget with placeholder defaults.

Source

pub fn alt(self, alt: impl Into<String>) -> Self

Sets the accessible/SEO alt text.

Source

pub fn file(self, path: impl Into<PathBuf>) -> Self

Set the image source to a file path.

Source

pub fn asset(self, name: impl AssetRef) -> Self

Load the image from a bundled asset by logical name — resolved per-platform via rosace_core::asset (dev: assets/<name>; mobile: the app bundle). Prefer this over file for shipped images: it’s portable across platforms and hot-reloads under rsc dev.

ImageWidget::new().asset("logo.png").fit(ImageFit::Contain)
Source

pub fn bytes(self, data: Vec<u8>) -> Self

Set the image source to raw PNG bytes.

Source

pub fn fit(self, f: ImageFit) -> Self

Set the fit mode.

Source

pub fn width(self, w: f32) -> Self

Set the widget width in pixels.

Source

pub fn height(self, h: f32) -> Self

Set the widget height in pixels.

Source

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

Set the placeholder background color shown when no image is available.

Source

pub fn render( &self, canvas: &mut SkiaCanvas, font: &FontCache, x: f32, y: f32, _theme: &ThemeData, )

Render the image at (x, y).

Falls back to a colored placeholder with a simple icon if the image cannot be loaded or decoded.

Trait Implementations§

Source§

impl Default for ImageWidget

Source§

fn default() -> Self

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

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.