#[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> + Sync + Send>>, Option<ImageRenderArgs>),
Image(Var<Img>),
}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> + 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(Var<Img>)
Already resolved (loaded or loading) image.
The image is passed-through, not cached.
Implementations§
Source§impl ImageSource
impl ImageSource
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 flood(
size: impl Into<Size2D<Px, Px>>,
color: impl Into<Rgba>,
density: Option<Size2D<PxDensity, PxDensity>>,
) -> ImageSource
pub fn flood( size: impl Into<Size2D<Px, Px>>, color: impl Into<Rgba>, density: Option<Size2D<PxDensity, PxDensity>>, ) -> ImageSource
New image data from solid color.
Sourcepub fn linear_vertical(
size: impl Into<Size2D<Px, Px>>,
stops: impl Into<GradientStops>,
density: Option<Size2D<PxDensity, PxDensity>>,
mask: Option<ImageMaskMode>,
) -> ImageSource
pub fn linear_vertical( size: impl Into<Size2D<Px, Px>>, stops: impl Into<GradientStops>, density: Option<Size2D<PxDensity, PxDensity>>, mask: Option<ImageMaskMode>, ) -> ImageSource
New image data from vertical linear gradient.
Sourcepub fn linear_horizontal(
size: impl Into<Size2D<Px, Px>>,
stops: impl Into<GradientStops>,
density: Option<Size2D<PxDensity, PxDensity>>,
mask: Option<ImageMaskMode>,
) -> ImageSource
pub fn linear_horizontal( size: impl Into<Size2D<Px, Px>>, stops: impl Into<GradientStops>, density: Option<Size2D<PxDensity, PxDensity>>, mask: Option<ImageMaskMode>, ) -> ImageSource
New image data from horizontal linear gradient.
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(
render_mode: RenderMode,
render: impl Fn(&ImageRenderArgs) -> UiNode + Send + Sync + 'static,
) -> ImageSource
pub fn render_node( render_mode: RenderMode, render: impl Fn(&ImageRenderArgs) -> UiNode + Send + Sync + 'static, ) -> 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<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 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> 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) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
From encoded data of known format.
Source§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) -> Var<ImageSource>
fn into_var(self) -> Var<ImageSource>
From encoded data of known format.
Source§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§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> 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) -> 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<WindowIcon> for ImageSource
impl IntoVar<WindowIcon> for ImageSource
fn into_var(self) -> Var<WindowIcon>
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> 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 String
impl IntoValue<ImageSource> for Txt
impl IntoValue<ImageSource> for Uri
impl IntoValue<ImageSource> for Var<Img>
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 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> 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