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::{image::mask, prelude::*};
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::{image, prelude::*};
image::IMAGES.limits().modify(|l| {
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
- Mask image properties.
Structs§
- IMAGES
- Image loading, cache and render service.
- IMAGE_
RENDER - Controls properties of the render window used by
IMAGES.render. - Image
WImage presenter.- Image
Hash - A 256-bit hash for image entries.
- Image
Hasher - Hasher that computes a
ImageHash. - Image
Limits - Limits for image loading and decoding.
- Image
Render Args - Arguments for the
ImageSource::Renderclosure. - Img
- State of an
ImageVar. - ImgError
Args - Arguments for
on_errorandimg_error_fn. - ImgLoad
Args - Arguments for
on_load. - ImgLoading
Args - Arguments for
img_loading_fn.
Enums§
- Image
Cache Mode - Cache mode of
IMAGES. - Image
Data Format - Format of the image bytes.
- Image
Downscale - Defines how an image is downscaled after decoding.
- Image
Fit - Image layout mode.
- Image
Repeat - Image repeat mode.
- Image
Source - The different sources of an image resource.
- Image
Source Filter - Represents a
PathFilterandUriFilter.
Functions§
- img_
align PSets theAlignof all inner images within each image widget area.- img_
cache PSets the cache mode of all inner images.- img_
crop PSets aRectthat is a clip applied to all inner images before their layout.- img_
downscale PCustom pixel resize applied during image load/decode.- img_
error_ fn PSets thewgt_fn!that is used to create a content for the error message.- img_fit
PSets theImageFitof all inner images.- img_
limits PSets custom image load and decode limits.- img_
loading_ fn PSets thewgt_fn!that is used to create a content for the loading message.- img_
offset PSets aPointthat is an offset applied to all inner images within each image widget area.- img_
rendering PSets theImageRenderingof all inner images.- img_
repeat PSets theImageRepeatof all inner images.- img_
repeat_ spacing PSets the spacing between copies of the image if it is repeated.- img_
scale PSets the scale applied to all inner images.- img_
scale_ density PSets if the image desired size is scaled considering the image and monitor pixel density.- img_
scale_ factor PSets if the image desired size is scaled by the screen scale factor.- is_
error PIf theCONTEXT_IMAGE_VARis an error.- is_
loaded PIf theCONTEXT_IMAGE_VARhas successfully loaded.- on_
error PImage load or decode error event.- on_load
PImage loaded event.- render_
retain PIf the render task is kept alive after a frame is produced, this isfalseby default meaning the image only renders once, if set totruethe image will automatically update when the render widget requests a new frame.
Type Aliases§
- Image
Var - Represents an
Imgtracked by theIMAGEScache. - Path
Filter - Represents a
ImageSource::Readpath request filter. - UriFilter
- Represents a
ImageSource::Downloadpath request filter.