egui::widgets

Enum ImageSource

Source
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 from include_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.

Fields

§uri: Cow<'static, str>

The unique identifier for this image, e.g. bytes://my_logo.png.

You should use a proper extension (.jpg, .png, .svg, etc) for the image to load properly.

Use the bytes:// scheme for the URI for better error messages.

§bytes: Bytes

Implementations§

Source§

impl<'a> ImageSource<'a>

Source

pub fn texture_size(&self) -> Option<Vec2>

Size of the texture, if known.

Source

pub fn load( self, ctx: &Context, texture_options: TextureOptions, size_hint: SizeHint, ) -> TextureLoadResult

§Errors

Failure to load the texture.

Source

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>

Source§

fn clone(&self) -> ImageSource<'a>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ImageSource<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> From<&'a Cow<'a, str>> for ImageSource<'a>

Source§

fn from(value: &'a Cow<'a, str>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a String> for ImageSource<'a>

Source§

fn from(value: &'a String) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a str> for ImageSource<'a>

Source§

fn from(value: &'a str) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Bytes>> From<(&'static str, T)> for ImageSource<'static>

Source§

fn from((uri, bytes): (&'static str, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Bytes>> From<(Cow<'static, str>, T)> for ImageSource<'static>

Source§

fn from((uri, bytes): (Cow<'static, str>, T)) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<Bytes>> From<(String, T)> for ImageSource<'static>

Source§

fn from((uri, bytes): (String, T)) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Cow<'a, str>> for ImageSource<'a>

Source§

fn from(value: Cow<'a, str>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for ImageSource<'static>

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
Source§

impl<T: Into<SizedTexture>> From<T> for ImageSource<'static>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,