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§
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 flood(
size: impl Into<PxSize>,
color: impl Into<Rgba>,
ppi: Option<ImagePpi>,
) -> Self
pub fn flood( size: impl Into<PxSize>, color: impl Into<Rgba>, ppi: Option<ImagePpi>, ) -> Self
New image data from solid color.
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 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<U, N>(render_mode: RenderMode, render: N) -> Self
pub fn render_node<U, N>(render_mode: RenderMode, render: N) -> 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<ReadOnlyVar<Img, ArcVar<Img>>> for ImageSource
impl From<ReadOnlyVar<Img, ArcVar<Img>>> 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
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§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§impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (Arc<Vec<u8>>, F)
impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (Arc<Vec<u8>>, F)
source§impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (Vec<u8>, F)
impl<F: Into<ImageDataFormat>> IntoVar<ImageSource> for (Vec<u8>, F)
source§impl IntoVar<ImageSource> for PathBuf
impl IntoVar<ImageSource> for PathBuf
source§impl IntoVar<ImageSource> for ImageVar
impl IntoVar<ImageSource> for ImageVar
source§impl IntoVar<ImageSource> for String
impl IntoVar<ImageSource> for String
source§impl IntoVar<ImageSource> for Txt
impl IntoVar<ImageSource> for Txt
source§impl IntoVar<ImageSource> for Uri
impl IntoVar<ImageSource> for Uri
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 ImageVar
impl IntoValue<ImageSource> for String
impl IntoValue<ImageSource> for Txt
impl IntoValue<ImageSource> for Uri
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 Twhere
T: VarValue,
impl<T> AnyVarValue for Twhere
T: VarValue,
source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
dyn Any
methods.source§fn clone_boxed(&self) -> Box<dyn AnyVarValue>
fn clone_boxed(&self) -> Box<dyn AnyVarValue>
source§fn clone_boxed_var(&self) -> Box<dyn AnyVar>
fn clone_boxed_var(&self) -> Box<dyn AnyVar>
LocalVar<Self>
.source§fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
fn eq_any(&self, other: &(dyn AnyVarValue + 'static)) -> bool
self
equals other
.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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§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