pub struct ImageSource {
pub uri: Arc<str>,
pub size: Option<Size<Points>>,
pub scales: ImageScales,
pub data: Option<ImageData>,
}Expand description
An image source.
Fields§
§uri: Arc<str>https://…, asset:/path (bundled file), a file path, a data: URI
or a blob: URL (URL.createObjectURL). A source with Self::data
goes by a short key instead of a data: URI (crate::image).
size: Option<Size<Points>>Natural size in points, when known up front (bundled assets): used as the intrinsic layout size.
scales: ImageScalesThe pixel densities a bundled asset ships in (a.png,
a@2x.png, …): the core mounts the one for the screen’s pixel
ratio. Empty for a single file.
data: Option<ImageData>The image’s bytes when they are in memory (a data: URI’s, the
blob of a blob: URL): the platforms decode these instead of
loading Self::uri, which stays the cache key.
Implementations§
Source§impl ImageSource
impl ImageSource
Sourcepub fn inline(self) -> ImageSource
pub fn inline(self) -> ImageSource
This source with its bytes in hand when its URI holds them: a
data: URI decoded (once, when the source is set) and named by a
short key. Other sources stay as they are. A data: URI that does
not decode becomes an empty one (the platforms then report the
error): left as it is, an app could write another image’s key
(data:<type>;nsh-key=<digest>, which has no comma) and ask the
process-wide caches whether some surface shows those bytes.
Sourcepub fn natural_size(&self) -> Option<Size<Points>>
pub fn natural_size(&self) -> Option<Size<Points>>
Its natural size in points: Self::size, else, for bytes in
hand (a data: URI, a blob), the size their header gives, one
pixel a point. A URL’s size is known only once it loads.
Sourcepub fn with_bytes(self, mime: &str, data: ImageData) -> ImageSource
pub fn with_bytes(self, mime: &str, data: ImageData) -> ImageSource
This source showing data, of media type mime (a blob’s bytes),
named by a digest of the bytes: equal images share their loads and
cache entries, whatever URL named them.
Sourcepub fn at_pixel_ratio(&self, pixel_ratio: f32) -> ImageSource
pub fn at_pixel_ratio(&self, pixel_ratio: f32) -> ImageSource
This source for a screen of pixel_ratio device pixels per point:
the Self::uri_for the core picks for what it mounts, for what
goes around it (a menu item’s icon).
Trait Implementations§
Source§impl Clone for ImageSource
impl Clone for ImageSource
Source§impl Debug for ImageSource
impl Debug for ImageSource
Source§impl Default for ImageSource
impl Default for ImageSource
Source§impl HostValue for ImageSource
"https://…" or a bundled asset { url, size: { width, height }, scales }.
impl HostValue for ImageSource
"https://…" or a bundled asset { url, size: { width, height }, scales }.