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 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 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,
) -> Result<TexturePoll, LoadError>
pub fn load( self, ctx: &Context, texture_options: TextureOptions, size_hint: SizeHint, ) -> Result<TexturePoll, LoadError>
§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 moreSource§impl<'a> Debug for ImageSource<'a>
impl<'a> Debug for ImageSource<'a>
Source§impl<'a> From<&'a String> for ImageSource<'a>
impl<'a> From<&'a String> for ImageSource<'a>
Source§fn from(value: &'a String) -> ImageSource<'a>
fn from(value: &'a String) -> ImageSource<'a>
Source§impl<'a> From<&'a str> for ImageSource<'a>
impl<'a> From<&'a str> for ImageSource<'a>
Source§fn from(value: &'a str) -> ImageSource<'a>
fn from(value: &'a str) -> ImageSource<'a>
Source§impl<T> From<(&'static str, T)> for ImageSource<'static>
impl<T> From<(&'static str, T)> for ImageSource<'static>
Source§fn from(_: (&'static str, T)) -> ImageSource<'static>
fn from(_: (&'static str, T)) -> ImageSource<'static>
Source§impl<T> From<(String, T)> for ImageSource<'static>
impl<T> From<(String, T)> for ImageSource<'static>
Source§fn from(_: (String, T)) -> ImageSource<'static>
fn from(_: (String, T)) -> ImageSource<'static>
Source§impl From<String> for ImageSource<'static>
impl From<String> for ImageSource<'static>
Source§fn from(value: String) -> ImageSource<'static>
fn from(value: String) -> ImageSource<'static>
Source§impl<T> From<T> for ImageSource<'static>where
T: Into<SizedTexture>,
impl<T> From<T> for ImageSource<'static>where
T: Into<SizedTexture>,
Source§fn from(value: T) -> ImageSource<'static>
fn from(value: T) -> ImageSource<'static>
Auto Trait Implementations§
impl<'a> Freeze for ImageSource<'a>
impl<'a> RefUnwindSafe for ImageSource<'a>
impl<'a> Send for ImageSource<'a>
impl<'a> Sync for ImageSource<'a>
impl<'a> Unpin for ImageSource<'a>
impl<'a> UnwindSafe for ImageSource<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.