pub enum ImageSource<'a> {
Uri(Cow<'a, str>),
Texture(SizedTexture),
Bytes {
uri: Cow<'static, str>,
bytes: Bytes,
},
}
Expand description
This type tells the Ui
how to load an image.
This is used by Image::new
and Ui::image
.
Variants§
Uri(Cow<'a, str>)
Load the image from a URI, e.g. https://example.com/image.png
.
This could be a file://
path, https://
url, bytes://
identifier, or some other scheme.
How the URI will be turned into a texture for rendering purposes is up to the registered loaders to handle.
See crate::load
for more information.
Texture(SizedTexture)
Load the image from an existing texture.
The user is responsible for loading the texture, determining its size,
and allocating a crate::TextureId
for it.
Bytes
Load the image from some raw bytes.
The Bytes
may be:
'static
, obtained frominclude_bytes!
or similar- Anything that can be converted to
Arc<[u8]>
This instructs the Ui
to cache the raw bytes, which are then further processed by any registered loaders.
See also crate::include_image
for an easy way to load and display static images.
See crate::load
for more information.
Implementations§
Source§impl<'a> ImageSource<'a>
impl<'a> ImageSource<'a>
Sourcepub fn texture_size(&self) -> Option<Vec2>
pub fn texture_size(&self) -> Option<Vec2>
Size of the texture, if known.
Sourcepub fn load(
self,
ctx: &Context,
texture_options: TextureOptions,
size_hint: SizeHint,
) -> TextureLoadResult
pub fn load( self, ctx: &Context, texture_options: TextureOptions, size_hint: SizeHint, ) -> TextureLoadResult
§Errors
Failure to load the texture.
Sourcepub fn uri(&self) -> Option<&str>
pub fn uri(&self) -> Option<&str>
Get the uri
that this image was constructed from.
This will return None
for Self::Texture
.
Trait Implementations§
Source§impl<'a> Clone for ImageSource<'a>
impl<'a> Clone for ImageSource<'a>
Source§fn clone(&self) -> ImageSource<'a>
fn clone(&self) -> ImageSource<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more