Expand description
Images service, widget and other types.
§Image
The Image!
widget is the primary way of presenting images, the example below defines
a repeating pattern image as the window background, the image source is embedded in this case, see ImageSource
for other supported sources.
use zng::prelude::*;
Window! {
widget::background = Image! {
source = include_bytes!("../res/image/pattern.png");
img_fit = zng::image::ImageFit::None;
img_repeat = true;
}
}
§Mask
Mask images are loaded just like normal images, the mask::mask_image
property
can be set on any widget to apply a mask to it. The example below applies a mask to a button, by
default the mask uses the alpha channel, see mask
for more details.
use zng::{prelude::*, image::mask};
Button! {
mask::mask_image = include_bytes!("../res/image/star.png");
}
§Service
The IMAGES
service manages image loading, the image cache and image rendering. Image decoding is
implemented by the view-process, for this reason to get image with actual pixels the service must be
used in a headed app or headless app with renderer, in a headless app without renderer all images are
a placeholder dummy.
The images service also define security limits, the IMAGES.limits
variable to configure these limits. See ImageLimits::default
for the defaults.
use zng::{prelude::*, image};
image::IMAGES.limits().modify(|l| {
let l = l.to_mut();
l.allow_uri = image::UriFilter::allow_host("httpbin.org");
l.max_encoded_len = 1.megabytes();
l.max_decoded_len = 10.megabytes();
});
The example above changes the global limits to allow image downloads only from an specific host and only allow images with sizes less or equal to 1 megabyte and that only expands to up to 10 megabytes after decoding.
§Full API
See zng_ext_image
for the full image API and zng_wgt_image
for the full widget API.
Modules§
- Mask image properties.
Structs§
- Image loading, cache and render service.
- Controls properties of the render window used by
IMAGES.render
. W
Image presenter.- A 256-bit hash for image entries.
- Hasher that computes a
ImageHash
. - Limits for image loading and decoding.
- Pixels-per-inch of each dimension of an image.
- Arguments for the
ImageSource::Render
closure. - State of an
ImageVar
. - Arguments for
on_error
andimg_error_fn
. - Arguments for
on_load
. - Arguments for
img_loading_fn
.
Enums§
- Cache mode of
IMAGES
. - Format of the image bytes.
- Defines how an image is downscaled after decoding.
- Image layout mode.
- Image repeat mode.
- The different sources of an image resource.
- Represents a
PathFilter
andUriFilter
.
Functions§
P
Sets theAlign
of all inner images within each image widget area.P
Sets the cache mode of all inner images.P
Sets aRect
that is a clip applied to all inner images before their layout.P
Custom pixel resize applied during image load/decode.P
Sets thewgt_fn!
that is used to create a content for the error message.P
Sets theImageFit
of all inner images.P
Sets custom image load and decode limits.P
Sets thewgt_fn!
that is used to create a content for the loading message.P
Sets aPoint
that is an offset applied to all inner images within each image widget area.P
Sets theImageRendering
of all inner images.P
Sets theImageRepeat
of all inner images.P
Sets the spacing between copies of the image if it is repeated.P
Sets the scale applied to all inner images.P
If the image desired size is scaled by the screen scale factor.P
Sets if the image desired size is scaled considering the image and monitor PPI.P
If theCONTEXT_IMAGE_VAR
is an error.P
If theCONTEXT_IMAGE_VAR
has successfully loaded.P
Image load or decode error event.P
Image loaded event.P
If the render task is kept alive after a frame is produced, this isfalse
by default meaning the image only renders once, if set totrue
the image will automatically update when the render widget requests a new frame.
Type Aliases§
- Represents a
ImageSource::Read
path request filter. - Represents a
ImageSource::Download
path request filter.