pub struct ImageAsset {
pub id: String,
pub path: String,
pub hash: DocumentId,
pub format: ImageFormat,
pub size: u64,
pub width: Option<u32>,
pub height: Option<u32>,
pub alt: Option<String>,
pub title: Option<String>,
pub attribution: Option<String>,
pub variants: Vec<ImageVariant>,
}Expand description
An image asset embedded in a Codex document.
Fields§
§id: StringUnique identifier for the image.
path: StringPath within the archive (e.g., “assets/images/logo.png”).
hash: DocumentIdContent hash for verification.
format: ImageFormatImage format.
size: u64File size in bytes.
width: Option<u32>Image width in pixels (for raster images).
height: Option<u32>Image height in pixels (for raster images).
alt: Option<String>Alternative text for accessibility.
title: Option<String>Optional title/caption.
attribution: Option<String>Source attribution or copyright.
variants: Vec<ImageVariant>Resolution variants for responsive images.
Each variant represents the same image at a different resolution, typically for different screen densities (1x, 2x, 3x).
Implementations§
Source§impl ImageAsset
impl ImageAsset
Sourcepub fn new(id: impl Into<String>, format: ImageFormat) -> Self
pub fn new(id: impl Into<String>, format: ImageFormat) -> Self
Create a new image asset.
Sourcepub fn with_hash(self, hash: DocumentId) -> Self
pub fn with_hash(self, hash: DocumentId) -> Self
Set the content hash.
Sourcepub fn with_dimensions(self, width: u32, height: u32) -> Self
pub fn with_dimensions(self, width: u32, height: u32) -> Self
Set the dimensions.
Sourcepub fn with_title(self, title: impl Into<String>) -> Self
pub fn with_title(self, title: impl Into<String>) -> Self
Set the title.
Sourcepub fn with_attribution(self, attribution: impl Into<String>) -> Self
pub fn with_attribution(self, attribution: impl Into<String>) -> Self
Set the attribution.
Sourcepub fn with_variant(self, variant: ImageVariant) -> Self
pub fn with_variant(self, variant: ImageVariant) -> Self
Add a resolution variant.
Sourcepub fn with_variants(self, variants: Vec<ImageVariant>) -> Self
pub fn with_variants(self, variants: Vec<ImageVariant>) -> Self
Add multiple resolution variants.
Sourcepub fn has_variants(&self) -> bool
pub fn has_variants(&self) -> bool
Check if this image has resolution variants.
Sourcepub fn variant_for_scale(&self, scale: f32) -> Option<&ImageVariant>
pub fn variant_for_scale(&self, scale: f32) -> Option<&ImageVariant>
Get the variant for a specific scale, if available.
Sourcepub fn best_variant_for_width(&self, target_width: u32) -> Option<&ImageVariant>
pub fn best_variant_for_width(&self, target_width: u32) -> Option<&ImageVariant>
Get the best variant for a given target width.
Returns the smallest variant that is at least as wide as the target, or the largest available variant if none are wide enough.
Trait Implementations§
Source§impl Asset for ImageAsset
impl Asset for ImageAsset
Source§fn hash(&self) -> &DocumentId
fn hash(&self) -> &DocumentId
Source§impl Clone for ImageAsset
impl Clone for ImageAsset
Source§fn clone(&self) -> ImageAsset
fn clone(&self) -> ImageAsset
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more