#[non_exhaustive]pub enum ImageSource {
Read(PathBuf),
Download(Uri, Option<Txt>),
Static(ImageHash, &'static [u8], ImageDataFormat),
Data(ImageHash, Arc<Vec<u8>>, ImageDataFormat),
Render(Arc<Box<dyn Fn(&ImageRenderArgs) -> Box<dyn ImageRenderWindowRoot> + Send + Sync>>, Option<ImageRenderArgs>),
Image(ImageVar),
}Expand description
The different sources of an image resource.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Read(PathBuf)
A path to an image file in the file system.
Image equality is defined by the path, a copy of the image in another path is a different image.
Download(Uri, Option<Txt>)
A uri to an image resource downloaded using HTTP GET with an optional HTTP ACCEPT string.
If the ACCEPT line is not given, all image formats supported by the view-process backend are accepted.
Image equality is defined by the URI and ACCEPT string.
Static(ImageHash, &'static [u8], ImageDataFormat)
Static bytes for an encoded or decoded image.
Image equality is defined by the hash, it is usually the hash of the bytes but it does not need to be.
Data(ImageHash, Arc<Vec<u8>>, ImageDataFormat)
Shared reference to bytes for an encoded or decoded image.
Image equality is defined by the hash, it is usually the hash of the bytes but it does not need to be.
Inside IMAGES the reference to the bytes is held only until the image finishes decoding.
Render(Arc<Box<dyn Fn(&ImageRenderArgs) -> Box<dyn ImageRenderWindowRoot> + Send + Sync>>, Option<ImageRenderArgs>)
A boxed closure that instantiates a WindowRoot that draws the image.
Use the render or render_node functions to construct this variant.
The closure is set by the image widget user, the args is set by the image widget.
Image(ImageVar)
Already resolved (loaded or loading) image.
The image is passed-through, not cached.
Implementations§
Source§impl ImageSource
impl ImageSource
Sourcepub fn from_static(data: &'static [u8], format: ImageDataFormat) -> Self
pub fn from_static(data: &'static [u8], format: ImageDataFormat) -> Self
New source from static data.
Sourcepub fn hash128(
&self,
downscale: Option<ImageDownscale>,
mask: Option<ImageMaskMode>,
) -> Option<ImageHash>
pub fn hash128( &self, downscale: Option<ImageDownscale>, mask: Option<ImageMaskMode>, ) -> Option<ImageHash>
Returns the image hash, unless the source is Img.
Sourcepub fn hash128_data(
data_hash: ImageHash,
downscale: Option<ImageDownscale>,
mask: Option<ImageMaskMode>,
) -> ImageHash
pub fn hash128_data( data_hash: ImageHash, downscale: Option<ImageDownscale>, mask: Option<ImageMaskMode>, ) -> ImageHash
Sourcepub fn hash128_read(
path: &Path,
downscale: Option<ImageDownscale>,
mask: Option<ImageMaskMode>,
) -> ImageHash
pub fn hash128_read( path: &Path, downscale: Option<ImageDownscale>, mask: Option<ImageMaskMode>, ) -> ImageHash
Compute hash for a borrowed Read path.
Sourcepub fn hash128_download(
uri: &Uri,
accept: &Option<Txt>,
downscale: Option<ImageDownscale>,
mask: Option<ImageMaskMode>,
) -> ImageHash
pub fn hash128_download( uri: &Uri, accept: &Option<Txt>, downscale: Option<ImageDownscale>, mask: Option<ImageMaskMode>, ) -> ImageHash
Compute hash for a borrowed Download URI and HTTP-ACCEPT.
Sourcepub fn hash128_render(
rfn: &Arc<Box<dyn Fn(&ImageRenderArgs) -> Box<dyn ImageRenderWindowRoot> + Send + Sync>>,
args: &Option<ImageRenderArgs>,
downscale: Option<ImageDownscale>,
mask: Option<ImageMaskMode>,
) -> ImageHash
pub fn hash128_render( rfn: &Arc<Box<dyn Fn(&ImageRenderArgs) -> Box<dyn ImageRenderWindowRoot> + Send + Sync>>, args: &Option<ImageRenderArgs>, downscale: Option<ImageDownscale>, mask: Option<ImageMaskMode>, ) -> ImageHash
Compute hash for a borrowed Render source.
Pointer equality is used to identify the node closure.
Source§impl ImageSource
impl ImageSource
Sourcepub fn flood(
size: impl Into<PxSize>,
color: impl Into<Rgba>,
density: Option<PxDensity2d>,
) -> Self
pub fn flood( size: impl Into<PxSize>, color: impl Into<Rgba>, density: Option<PxDensity2d>, ) -> Self
New image data from solid color.
Sourcepub fn linear_vertical(
size: impl Into<PxSize>,
stops: impl Into<GradientStops>,
density: Option<PxDensity2d>,
mask: Option<ImageMaskMode>,
) -> Self
pub fn linear_vertical( size: impl Into<PxSize>, stops: impl Into<GradientStops>, density: Option<PxDensity2d>, mask: Option<ImageMaskMode>, ) -> Self
New image data from vertical linear gradient.
Sourcepub fn linear_horizontal(
size: impl Into<PxSize>,
stops: impl Into<GradientStops>,
density: Option<PxDensity2d>,
mask: Option<ImageMaskMode>,
) -> Self
pub fn linear_horizontal( size: impl Into<PxSize>, stops: impl Into<GradientStops>, density: Option<PxDensity2d>, mask: Option<ImageMaskMode>, ) -> Self
New image data from horizontal linear gradient.
Source§impl ImageSource
impl ImageSource
Sourcepub fn render<F, R>(new_img: F) -> Self
pub fn render<F, R>(new_img: F) -> Self
New image from a function that generates a headless window.
The function is called every time the image source is resolved and it is not found in the cache.
§Examples
|args| Window! {
size = (500, 400);
parent = args.parent;
background_color = colors::GREEN;
child = Text!("Rendered!");
}
)Sourcepub fn render_node(
render_mode: RenderMode,
render: impl Fn(&ImageRenderArgs) -> UiNode + Send + Sync + 'static,
) -> Self
pub fn render_node( render_mode: RenderMode, render: impl Fn(&ImageRenderArgs) -> UiNode + Send + Sync + 'static, ) -> Self
New image from a function that generates a new UiNode.
The function is called every time the image source is resolved and it is not found in the cache.
Note that the generated UiNode is not a child of the widget that renders the image, it is the root widget of a headless
surface, not a part of the context where it is rendered. See IMAGES.render for more information.
§Examples
ImageSource::render_node(RenderMode::Software, |_args| {
Container! {
size = (500, 400);
background_color = colors::GREEN;
child = Text!("Rendered!");
}
})Trait Implementations§
Source§impl Clone for ImageSource
impl Clone for ImageSource
Source§fn clone(&self) -> ImageSource
fn clone(&self) -> ImageSource
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ImageSource
impl Debug for ImageSource
Source§impl From<&'static [u8]> for ImageSource
impl From<&'static [u8]> for ImageSource
Source§impl From<&Path> for ImageSource
impl From<&Path> for ImageSource
Source§impl From<&str> for ImageSource
impl From<&str> for ImageSource
Source§impl<F: Into<ImageDataFormat>> From<(&'static [u8], F)> for ImageSource
impl<F: Into<ImageDataFormat>> From<(&'static [u8], F)> for ImageSource
Source§impl<F: Into<ImageDataFormat>, const N: usize> From<(&'static [u8; N], F)> for ImageSource
impl<F: Into<ImageDataFormat>, const N: usize> From<(&'static [u8; N], F)> for ImageSource
Source§impl<F: Into<ImageDataFormat>> From<(Arc<Vec<u8>>, F)> for ImageSource
impl<F: Into<ImageDataFormat>> From<(Arc<Vec<u8>>, F)> for ImageSource
Source§impl<F: Into<ImageDataFormat>> From<(Vec<u8>, F)> for ImageSource
impl<F: Into<ImageDataFormat>> From<(Vec<u8>, F)> for ImageSource
Source§impl From<PathBuf> for ImageSource
impl From<PathBuf> for ImageSource
Source§impl From<String> for ImageSource
impl From<String> for ImageSource
Source§impl From<Uri> for ImageSource
impl From<Uri> for ImageSource
Source§impl IntoVar<ImageSource> for &'static [u8]
impl IntoVar<ImageSource> for &'static [u8]
Source§impl IntoVar<ImageSource> for &Path
impl IntoVar<ImageSource> for &Path
fn into_var(self) -> Var<ImageSource>
Source§impl IntoVar<ImageSource> for &str
impl IntoVar<ImageSource> for &str
Source§impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (&'static [u8], F)
impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (&'static [u8], F)
Source§fn into_var(self) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
From encoded data of known format.
Source§impl<F: Into<ImageDataFormat>, const N: usize> IntoVar<ImageSource> for (&'static [u8; N], F)
impl<F: Into<ImageDataFormat>, const N: usize> IntoVar<ImageSource> for (&'static [u8; N], F)
Source§fn into_var(self) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
From encoded data of known format.
Source§impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (Arc<Vec<u8>>, F)
impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (Arc<Vec<u8>>, F)
Source§fn into_var(self) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
From encoded data of known format.
Source§impl IntoVar<ImageSource> for (Uri, &'static str)
impl IntoVar<ImageSource> for (Uri, &'static str)
Source§fn into_var(self) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
From (URI, HTTP-ACCEPT).
Source§impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (Vec<u8>, F)
impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (Vec<u8>, F)
Source§fn into_var(self) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
From encoded data of known format.
Source§impl IntoVar<ImageSource> for PathBuf
impl IntoVar<ImageSource> for PathBuf
fn into_var(self) -> Var<ImageSource>
Source§impl IntoVar<ImageSource> for String
impl IntoVar<ImageSource> for String
Source§fn into_var(self) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
Same as conversion from &str.
Source§impl IntoVar<ImageSource> for Txt
impl IntoVar<ImageSource> for Txt
Source§fn into_var(self) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
Same as conversion from &str.
Source§impl IntoVar<ImageSource> for Uri
impl IntoVar<ImageSource> for Uri
fn into_var(self) -> Var<ImageSource>
Source§impl IntoVar<ImageSource> for ImageVar
impl IntoVar<ImageSource> for ImageVar
fn into_var(self) -> Var<ImageSource>
Source§impl PartialEq for ImageSource
impl PartialEq for ImageSource
impl IntoValue<ImageSource> for &'static [u8]
impl<const N: usize> IntoValue<ImageSource> for &'static [u8; N]
impl IntoValue<ImageSource> for &Path
impl IntoValue<ImageSource> for &str
impl<F: Into<ImageDataFormat>> IntoValue<ImageSource> for (&'static [u8], F)
impl<F: Into<ImageDataFormat>, const N: usize> IntoValue<ImageSource> for (&'static [u8; N], F)
impl<F: Into<ImageDataFormat>> IntoValue<ImageSource> for (Arc<Vec<u8>>, F)
impl IntoValue<ImageSource> for (Uri, &'static str)
impl<F: Into<ImageDataFormat>> IntoValue<ImageSource> for (Vec<u8>, F)
impl IntoValue<ImageSource> for Arc<Vec<u8>>
impl IntoValue<ImageSource> for PathBuf
impl IntoValue<ImageSource> for String
impl IntoValue<ImageSource> for Txt
impl IntoValue<ImageSource> for Uri
impl IntoValue<ImageSource> for ImageVar
impl IntoValue<ImageSource> for Vec<u8>
Auto Trait Implementations§
impl !Freeze for ImageSource
impl !RefUnwindSafe for ImageSource
impl Send for ImageSource
impl Sync for ImageSource
impl !Unpin for ImageSource
impl !UnwindSafe for ImageSource
Blanket Implementations§
Source§impl<T> AnyVarValue for T
impl<T> AnyVarValue for T
Source§fn clone_boxed(&self) -> BoxAnyVarValue
fn clone_boxed(&self) -> BoxAnyVarValue
Source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self and other are equal.Source§fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
fn try_swap(&mut self, other: &mut (dyn AnyVarValue + 'static)) -> bool
other if both are of the same type.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,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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 more