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> + Sync + Send>>, Option<ImageRenderArgs>),
Image(ReadOnlyVar<Img, ArcVar<Img>>),
}
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> + Sync + Send>>, 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(ReadOnlyVar<Img, ArcVar<Img>>)
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<Size2D<Px, Px>>,
color: impl Into<Rgba>,
ppi: Option<ImagePpi>,
) -> ImageSource
pub fn flood( size: impl Into<Size2D<Px, Px>>, color: impl Into<Rgba>, ppi: Option<ImagePpi>, ) -> ImageSource
New image data from solid color.
sourcepub fn from_data(data: Arc<Vec<u8>>, format: ImageDataFormat) -> ImageSource
pub fn from_data(data: Arc<Vec<u8>>, format: ImageDataFormat) -> ImageSource
New source from data.
sourcepub fn from_static(data: &'static [u8], format: ImageDataFormat) -> ImageSource
pub fn from_static(data: &'static [u8], format: ImageDataFormat) -> ImageSource
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> + Sync + Send>>,
args: &Option<ImageRenderArgs>,
downscale: Option<ImageDownscale>,
mask: Option<ImageMaskMode>,
) -> ImageHash
pub fn hash128_render( rfn: &Arc<Box<dyn Fn(&ImageRenderArgs) -> Box<dyn ImageRenderWindowRoot> + Sync + Send>>, 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) -> ImageSource
pub fn render<F, R>(new_img: F) -> ImageSource
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) -> ImageSource
pub fn render_node<U, N>(render_mode: RenderMode, render: N) -> ImageSource
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§fn from(path: &Path) -> ImageSource
fn from(path: &Path) -> ImageSource
source§impl From<&str> for ImageSource
impl From<&str> for ImageSource
source§impl<F> From<(&'static [u8], F)> for ImageSourcewhere
F: Into<ImageDataFormat>,
impl<F> From<(&'static [u8], F)> for ImageSourcewhere
F: Into<ImageDataFormat>,
source§fn from(_: (&'static [u8], F)) -> ImageSource
fn from(_: (&'static [u8], F)) -> ImageSource
From encoded data of known format.
source§impl<F, const N: usize> From<(&'static [u8; N], F)> for ImageSourcewhere
F: Into<ImageDataFormat>,
impl<F, const N: usize> From<(&'static [u8; N], F)> for ImageSourcewhere
F: Into<ImageDataFormat>,
source§impl<F> From<(Arc<Vec<u8>>, F)> for ImageSourcewhere
F: Into<ImageDataFormat>,
impl<F> From<(Arc<Vec<u8>>, F)> for ImageSourcewhere
F: Into<ImageDataFormat>,
source§impl<F> From<(Vec<u8>, F)> for ImageSourcewhere
F: Into<ImageDataFormat>,
impl<F> From<(Vec<u8>, F)> for ImageSourcewhere
F: Into<ImageDataFormat>,
source§impl From<ImageSource> for WindowIcon
impl From<ImageSource> for WindowIcon
source§fn from(source: ImageSource) -> WindowIcon
fn from(source: ImageSource) -> WindowIcon
source§impl From<PathBuf> for ImageSource
impl From<PathBuf> for ImageSource
source§fn from(path: PathBuf) -> ImageSource
fn from(path: PathBuf) -> ImageSource
source§impl From<ReadOnlyVar<Img, ArcVar<Img>>> for ImageSource
impl From<ReadOnlyVar<Img, ArcVar<Img>>> for ImageSource
source§fn from(image: ReadOnlyVar<Img, ArcVar<Img>>) -> ImageSource
fn from(image: ReadOnlyVar<Img, ArcVar<Img>>) -> ImageSource
source§impl From<String> for ImageSource
impl From<String> for ImageSource
source§fn from(s: String) -> ImageSource
fn from(s: String) -> ImageSource
Same as conversion from &str
.
source§impl From<Txt> for ImageSource
impl From<Txt> for ImageSource
source§fn from(s: Txt) -> ImageSource
fn from(s: Txt) -> ImageSource
Same as conversion from &str
.
source§impl From<Uri> for ImageSource
impl From<Uri> for ImageSource
source§fn from(uri: Uri) -> ImageSource
fn from(uri: Uri) -> ImageSource
source§impl IntoVar<ImageSource> for &'static [u8]
impl IntoVar<ImageSource> for &'static [u8]
source§impl<const N: usize> IntoVar<ImageSource> for &'static [u8; N]
impl<const N: usize> IntoVar<ImageSource> for &'static [u8; N]
source§impl IntoVar<ImageSource> for &Path
impl IntoVar<ImageSource> for &Path
source§fn into_var(self) -> <&Path as IntoVar<ImageSource>>::Var
fn into_var(self) -> <&Path as IntoVar<ImageSource>>::Var
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<ImageSource> for &str
impl IntoVar<ImageSource> for &str
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl<F> IntoVar<ImageSource> for (&'static [u8], F)where
F: Into<ImageDataFormat>,
impl<F> IntoVar<ImageSource> for (&'static [u8], F)where
F: Into<ImageDataFormat>,
source§fn into_var(self) -> <(&'static [u8], F) as IntoVar<ImageSource>>::Var
fn into_var(self) -> <(&'static [u8], F) as IntoVar<ImageSource>>::Var
From encoded data of known format.
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl<F, const N: usize> IntoVar<ImageSource> for (&'static [u8; N], F)where
F: Into<ImageDataFormat>,
impl<F, const N: usize> IntoVar<ImageSource> for (&'static [u8; N], F)where
F: Into<ImageDataFormat>,
source§fn into_var(self) -> <(&'static [u8; N], F) as IntoVar<ImageSource>>::Var
fn into_var(self) -> <(&'static [u8; N], F) as IntoVar<ImageSource>>::Var
From encoded data of known format.
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl<F> IntoVar<ImageSource> for (Arc<Vec<u8>>, F)where
F: Into<ImageDataFormat>,
impl<F> IntoVar<ImageSource> for (Arc<Vec<u8>>, F)where
F: Into<ImageDataFormat>,
source§impl IntoVar<ImageSource> for (Uri, &'static str)
impl IntoVar<ImageSource> for (Uri, &'static str)
source§fn into_var(self) -> <(Uri, &'static str) as IntoVar<ImageSource>>::Var
fn into_var(self) -> <(Uri, &'static str) as IntoVar<ImageSource>>::Var
From (URI, HTTP-ACCEPT).
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl<F> IntoVar<ImageSource> for (Vec<u8>, F)where
F: Into<ImageDataFormat>,
impl<F> IntoVar<ImageSource> for (Vec<u8>, F)where
F: Into<ImageDataFormat>,
source§fn into_var(self) -> <(Vec<u8>, F) as IntoVar<ImageSource>>::Var
fn into_var(self) -> <(Vec<u8>, F) as IntoVar<ImageSource>>::Var
From encoded data of known format.
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<ImageSource> for Arc<Vec<u8>>
impl IntoVar<ImageSource> for Arc<Vec<u8>>
source§impl IntoVar<ImageSource> for PathBuf
impl IntoVar<ImageSource> for PathBuf
source§fn into_var(self) -> <PathBuf as IntoVar<ImageSource>>::Var
fn into_var(self) -> <PathBuf as IntoVar<ImageSource>>::Var
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<ImageSource> for ReadOnlyVar<Img, ArcVar<Img>>
impl IntoVar<ImageSource> for ReadOnlyVar<Img, ArcVar<Img>>
source§fn into_var(
self,
) -> <ReadOnlyVar<Img, ArcVar<Img>> as IntoVar<ImageSource>>::Var
fn into_var( self, ) -> <ReadOnlyVar<Img, ArcVar<Img>> as IntoVar<ImageSource>>::Var
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<ImageSource> for String
impl IntoVar<ImageSource> for String
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<ImageSource> for Txt
impl IntoVar<ImageSource> for Txt
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<ImageSource> for Uri
impl IntoVar<ImageSource> for Uri
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§impl IntoVar<ImageSource> for Vec<u8>
impl IntoVar<ImageSource> for Vec<u8>
source§impl IntoVar<WindowIcon> for ImageSource
impl IntoVar<WindowIcon> for ImageSource
source§fn into_var(self) -> <ImageSource as IntoVar<WindowIcon>>::Var
fn into_var(self) -> <ImageSource as IntoVar<WindowIcon>>::Var
source§fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
fn into_boxed_var(self) -> Box<dyn VarBoxed<T>>where
Self: Sized,
BoxedVar<T>
. Read moresource§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> IntoValue<ImageSource> for (&'static [u8], F)where
F: Into<ImageDataFormat>,
impl<F, const N: usize> IntoValue<ImageSource> for (&'static [u8; N], F)where
F: Into<ImageDataFormat>,
impl<F> IntoValue<ImageSource> for (Arc<Vec<u8>>, F)where
F: Into<ImageDataFormat>,
impl IntoValue<ImageSource> for (Uri, &'static str)
impl<F> IntoValue<ImageSource> for (Vec<u8>, F)where
F: Into<ImageDataFormat>,
impl IntoValue<ImageSource> for Arc<Vec<u8>>
impl IntoValue<ImageSource> for PathBuf
impl IntoValue<ImageSource> for ReadOnlyVar<Img, ArcVar<Img>>
impl IntoValue<ImageSource> for String
impl IntoValue<ImageSource> for Txt
impl IntoValue<ImageSource> for Uri
impl IntoValue<ImageSource> for Vec<u8>
impl IntoValue<WindowIcon> for ImageSource
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§
§impl<T> AnyEq for T
impl<T> AnyEq for T
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> FsChangeNote for T
impl<T> FsChangeNote for T
§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