Struct zng::image::Image

source ·
pub struct Image(/* private fields */);
Expand description

W Image presenter.

This widget loads a still image from a variety of sources and presents it.

Implementations§

source§

impl Image

source

pub fn img_fit(&self, fit: impl IntoVar<ImageFit>)

P Sets the ImageFit of all inner images.

This property sets the IMAGE_FIT_VAR.

source§

impl Image

source

pub fn img_scale(&self, scale: impl IntoVar<Factor2d>)

P Sets the scale applied to all inner images.

The scaling is applied after img_scale_ppi if active.

By default not scaling is done.

source§

impl Image

source

pub fn img_scale_factor(&self, enabled: impl IntoVar<bool>)

P If the image desired size is scaled by the screen scale factor.

The image desired size is its original size after img_crop, it is a pixel value, but widgets are layout using device independent pixels that automatically scale in higher definition displays, when this property is enabled the image size is also scaled so that the image will take the same screen space in all devices, the image can end

This is enabled by default.

source§

impl Image

source

pub fn img_scale_ppi(&self, enabled: impl IntoVar<bool>)

P Sets if the image desired size is scaled considering the image and monitor PPI.

If the image desired size is scaled by PPI.

The image desired size is its original size, after img_crop, and it can be in pixels or scaled considering the image PPI, monitor PPI and scale factor.

By default this is false, if true the image is scaled in a attempt to recreate the original physical dimensions, but it only works if the image and monitor PPI are set correctly. The monitor PPI can be set using the MONITORS service.

source§

impl Image

source

pub fn img_align(&self, fit: impl IntoVar<Align>)

P Sets the Align of all inner images within each image widget area.

If the image is smaller then the widget area it is aligned like normal, if it is larger the “viewport” it is aligned to clip, for example, alignment BOTTOM_RIGHT makes a smaller image sit at the bottom-right of the widget and makes a larger image bottom-right fill the widget, clipping the rest.

By default the alignment is CENTER. The BASELINE alignment is treaded the same as BOTTOM.

source§

impl Image

source

pub fn img_offset(&self, offset: impl IntoVar<Vector>)

P Sets a Point that is an offset applied to all inner images within each image widget area.

Relative values are calculated from the widget final size. Note that this is different the applying the offset property on the widget itself, the widget is not moved just the image within the widget area.

This property sets the IMAGE_OFFSET_VAR. By default no offset is applied.

source§

impl Image

source

pub fn img_crop(&self, crop: impl IntoVar<Rect>)

P Sets a Rect that is a clip applied to all inner images before their layout.

Relative values are calculated from the image pixel size, the img_scale_ppi is only considered after. Note that more complex clipping can be applied after to the full widget, this property exists primarily to render selections of a texture atlas.

By default no cropping is done.

source§

impl Image

source

pub fn img_repeat(&self, repeat: impl IntoVar<ImageRepeat>)

P Sets the ImageRepeat of all inner images.

Note that repeat converts from bool so you can set this property to img_repeat = true; to enable repeat in all inner images.

See also img_repeat_spacing to control the space between repeated tiles.

This property sets the IMAGE_REPEAT_VAR.

source§

impl Image

source

pub fn img_repeat_spacing(&self, spacing: impl IntoVar<Size>)

P Sets the spacing between copies of the image if it is repeated.

Relative lengths are computed on the size of a single repeated tile image, so 100.pct() is skips an entire image of space. The leftover size is set to the space taken by tile images that do not fully fit inside the clip area, 1.lft() will insert space to cause only fully visible tiles to remain on screen.

This property sets the IMAGE_REPEAT_SPACING_VAR.

source§

impl Image

source

pub fn img_rendering(&self, rendering: impl IntoVar<ImageRendering>)

P Sets the ImageRendering of all inner images.

If the image layout size is not the same as the source pixel size the image must be re-scaled during rendering, this property selects what algorithm is used to do this re-scaling.

Note that the algorithms used in the renderer value performance over quality and do a good enough job for small or temporary changes in scale only. If the image stays at a very different scale after a short time a CPU re-scale task is automatically started to generate a better quality re-scaling.

If the image is an app resource known during build time you should consider pre-scaling it to match the screen size at different DPIs using mipmaps.

This is ImageRendering::Auto by default.

source§

impl Image

source

pub fn img_cache(&self, enabled: impl IntoVar<bool>)

P Sets the cache mode of all inner images.

Sets if the source is cached.

By default this is true, meaning the image is loaded from cache and if not present it is inserted into the cache, the cache lives for the app in the IMAGES service, the image can be manually removed from cache.

If set to false the image is always loaded and decoded on init or when source updates and is dropped when the widget is deinited or dropped.

source§

impl Image

source

pub fn img_limits(&self, limits: impl IntoVar<Option<ImageLimits>>)

P Sets custom image load and decode limits.

If not set or set to None the IMAGES.limits is used.

See also img_downscale for a way to still display unexpected large images.

source§

impl Image

source

pub fn img_downscale(&self, downscale: impl IntoVar<Option<ImageDownscale>>)

P Custom pixel resize applied during image load/decode.

Note that this resize affects the image actual pixel size directly when it is loading to force the image pixels to be within an expected size. This property primary use is as error recover before the img_limits error happens, you set the limits to the size that should not even be processed and set this property to the maximum size expected.

Changing this value after an image is already loaded or loading will cause the image to reload, image cache allocates different entries for different downscale values, this means that this property should never be used for responsive resize,use the widget size and other properties to efficiently resize an image on screen.

source§

impl Image

source

pub fn is_error(&self, state: impl IntoVar<bool>)

P If the CONTEXT_IMAGE_VAR is an error.

source§

impl Image

source

pub fn is_loaded(&self, state: impl IntoVar<bool>)

P If the CONTEXT_IMAGE_VAR has successfully loaded.

source§

impl Image

source

pub fn get_img(&self, state: impl IntoVar<Option<Img>>)

P Gets the CONTEXT_IMAGE_VAR.

source§

impl Image

source

pub fn get_img_layout_size(&self, state: impl IntoVar<Size2D<Px, Px>>)

P Gets the CONTEXT_IMAGE_VAR ideal size.

source§

impl Image

source

pub fn img_error_fn(&self, wgt_fn: impl IntoVar<WidgetFn<ImgErrorArgs>>)

P Sets the wgt_fn! that is used to create a content for the error message.

source§

impl Image

source

pub fn img_loading_fn(&self, wgt_fn: impl IntoVar<WidgetFn<ImgLoadingArgs>>)

P Sets the wgt_fn! that is used to create a content for the loading message.

source§

impl Image

source

pub fn on_error(&self, handler: impl WidgetHandler<ImgErrorArgs>)

P Image load or decode error event.

This property calls handler every time the CONTEXT_IMAGE_VAR updates with a different error or on the first update after init if the image is already in error on init.

§Handlers

This property accepts any WidgetHandler, including the async handlers. Use one of the handler macros, hn!, hn_once!, async_hn! or async_hn_once!, to declare a handler closure.

§Route

This property is not routed, it works only inside a widget that loads images. There is also no preview event.

source§

impl Image

source

pub fn on_load(&self, handler: impl WidgetHandler<ImgLoadArgs>)

P Image loaded event.

This property calls handler every time the CONTEXT_IMAGE_VAR updates with a successfully loaded image or on the first update after init if the image is already loaded on init.

§Handlers

This property accepts any WidgetHandler, including the async handlers. Use one of the handler macros, hn!, hn_once!, async_hn! or async_hn_once!, to declare a handler closure.

§Route

This property is not routed, it works only inside a widget that loads images. There is also no preview event.

source§

impl Image

source

pub fn img_block_window_load(&self, enabled: impl IntoValue<BlockWindowLoad>)

P Block window load until image is loaded.

If the image widget is in the initial window content a WindowLoadingHandle is used to delay the window visually opening until the source loads, fails to load or a timeout elapses. By default true sets the timeout to 1 second.

source§

impl Image

source

pub fn widget_new() -> Image

Start building a new instance.

source

pub fn widget_type() -> WidgetType

Gets the widget type info.

source§

impl Image

source

pub fn source(&self, source: impl IntoVar<ImageSource>)

c The image source.

Can be a file path, an URI, binary included in the app and more.

Methods from Deref<Target = WidgetBase>§

source

pub fn widget_builder(&mut self) -> &mut WidgetBuilder

Returns a mutable reference to the widget builder.

source

pub fn widget_when(&mut self) -> Option<&mut WhenInfo>

Returns a mutable reference to the when block if called inside a when block.

source

pub fn widget_take(&mut self) -> WidgetBuilder

Takes the widget builder, finishing the widget macro build.

After this call trying to set a property using self will panic, the returned builder can still be manipulated directly.

source

pub fn widget_build(&mut self) -> impl UiNode

Build the widget.

After this call trying to set a property will panic.

source

pub fn widget_importance(&mut self) -> &mut Importance

Returns a mutable reference to the importance of the next property assigns, unsets or when blocks.

Note that during the widget_intrinsic call this is Importance::WIDGET and after it is Importance::INSTANCE.

source

pub fn start_when_block( &mut self, inputs: Box<[WhenInput]>, state: Box<dyn VarBoxed<bool>>, expr: &'static str, location: SourceLocation, )

Start building a when block, all properties set after this call are pushed in the when block.

source

pub fn end_when_block(&mut self)

End the current when block, all properties set after this call are pushed in the widget.

source

pub fn id(&self, id: impl IntoValue<WidgetId>)

c Unique ID of the widget instance.

Note that the id can convert from a &'static str unique name.

Trait Implementations§

source§

impl Deref for Image

source§

type Target = WidgetBase

The resulting type after dereferencing.
source§

fn deref(&self) -> &<Image as Deref>::Target

Dereferences the value.
source§

impl DerefMut for Image

source§

fn deref_mut(&mut self) -> &mut <Image as Deref>::Target

Mutably dereferences the value.

Auto Trait Implementations§

§

impl !Freeze for Image

§

impl !RefUnwindSafe for Image

§

impl Send for Image

§

impl !Sync for Image

§

impl Unpin for Image

§

impl !UnwindSafe for Image

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T