use fission::prelude::*;
let avatar = Image::asset("assets/avatar.png")
.size(48.0, 48.0)
.semantic_label("Sam's profile photo")
.into();
let product = Image::network(product.thumbnail.clone())
.size(220.0, 160.0)
.fit(ir_op::ImageFit::Contain)
.semantic_label(format!("{} product image", product.title))
.into();
Fit | What it does | Good use cases | Tradeoff |
|---|---|---|---|
ImageFit::Contain | Scales the whole image until it fits inside the box. | Product photos, diagrams, document previews, screenshots, anything where losing edges would be misleading. | May leave empty space on one axis. |
ImageFit::Cover | Scales the image until the whole box is covered. | Hero images, card backgrounds, decorative thumbnails where cropping is acceptable. | Crops whichever axis overflows. The renderer clips the image to the widget bounds. |
ImageFit::Fill | Stretches width and height independently. | Rare cases where distortion is acceptable, such as generated textures or placeholders. | Changes the image aspect ratio. |
ImageFit::None | Paints at the decoded image's natural pixel size. | Low-level rendering experiments or already-sized memory images. | Usually wrong in responsive UI because it ignores the layout box size. |
let banner = Image::network(view.state().banner_url.clone())
.size(640.0, 240.0)
.fit(ir_op::ImageFit::Cover)
.alignment(ImageAlignment::TopCenter)
.semantic_label("Spring campaign banner")
.into();
let protected = Image::network(view.state().signed_url.clone())
.header("Accept", "image/webp,image/png")
.cache_size(440, 320)
.cache_policy(ImageCachePolicy::MemoryOnly)
.size(220.0, 160.0)
.fit(ir_op::ImageFit::Contain)
.semantic_label("Invoice preview")
.into();
Field | Type | Meaning | Notes / default behavior |
|---|---|---|---|
id | Option<WidgetId> | Stable widget identity. | Defaults to None. Most images do not need an explicit id. |
request | ImageRequest | Typed image request containing an asset, file, network URL, memory buffer, or inline SVG source. | Prefer Image::asset, Image::file, Image::network, Image::memory, or Image::svg_text. |
width | Option<f32> | Fixed layout width in logical points. | Defaults to None. Give images explicit dimensions or place them inside a parent that constrains them. |
height | Option<f32> | Fixed layout height in logical points. | Defaults to None. Lists and grids should usually give thumbnails both width and height. |
fit | ImageFit | How the image scales inside its box. | Defaults to Contain. |
alignment | ImageAlignment | Where fitted content sits when there is empty space or cropping. | Defaults to Center. |
Method | Purpose | Notes |
|---|---|---|
Image::asset(path) | Load an app asset. | Use for images packaged with the app. |
Image::file(path) | Load a local file path. | Use only when the app intentionally works with local files. |
Image::network(url) | Load a remote image. | Loaded asynchronously by the shell. |
Image::memory(bytes) | Decode bytes already held by the app. | Good for capability results or generated previews. |
Image::svg_text(content) | Render inline SVG text. | Lowers to SVG drawing instead of raster image loading. |
.size(width, height) | Set both layout dimensions. | Preferred for thumbnails and cards. |
.width(width) / .height(height) | Set one layout dimension. | Use when the other axis comes from parent layout. |
.fit(fit) | Set scaling behavior. | Contain preserves full content; Cover fills and crops. |
.alignment(alignment) | Set crop or empty-space alignment. | Useful with Cover hero images. |
.semantic_label(label) | Add accessibility meaning. | Omit only for decorative images. |
.cache_size(width, height) | Request a decode/cache target size. | Helps thumbnail-heavy screens avoid wasting memory. |
.header(name, value) | Add a network header. | Applies only to network images. |
.cache_policy(policy) | Set network cache intent. | Applies only to network images. |
let thumbnail = Image::network(product.thumbnail.clone())
.size(220.0, 160.0)
.fit(ir_op::ImageFit::Contain)
.semantic_label(format!("Photo of {}", product.title))
.into();
let hero = Image::network(view.state().hero_url.clone())
.size(720.0, 320.0)
.fit(ir_op::ImageFit::Cover)
.alignment(ImageAlignment::Center)
.semantic_label("Featured destination")
.into();