EffectHostContext
struct · ferroui-base · v0.5.0
struct EffectHostContext<'a>
The element an interactive effect is the effect of, as the effect's input handler sees it
(Effector's SkiaEffectHostContext): its bounds, the pointer position in its coordinates,
normalized to its bounds and in the coordinates of the effect's program, the capture of the
pointer, and the invalidation of the effect.
Three coordinate spaces meet here:
- the host's own coordinates (
get_position), device independent pixels from the top left corner of the host, through every render transform up to the root; - the normalized coordinates (
get_normalized_position), 0 to 1 across the input bounds, which is what the interactive effects of the library pass as uniforms: independent of the scale, they need no conversion on the render thread; - the coordinates of the program (
get_effect_position): device pixels from the top left corner of the area of the effect, atlayer_scale(section 3.4 of the plan, thecoorda program is given).
The area of the effect is the rectangle the renderer draws the effect over (#580): the bounds
of the content of the host's subtree, with the padding of the effect, as the compositor last
drew them (render_bounds), so that a normalized position of 0.5 is the
middle of what the program draws, also when the content does not fill the host or reaches
beyond it. Before the host was drawn (or without a compositor), the area is the host's own
bounds with the padding.
Members
effecthostvisualboundssizeinput_boundsinput_sizerender_boundspaddingeffect_boundslayer_scaleget_positionget_normalized_positionnormalizeget_effect_positionto_effect_spacecapture_pointerrelease_pointer_capturehas_pointer_captureinvalidaterequest_animation_frame
effect
fn effect(self: &Self) -> &'a Effect
The effect.
host
fn host(self: &Self) -> &'a InputElement
The host: the input element the effect is the effect of.
visual
fn visual(self: &Self) -> &'a Visual
The host as a visual.
bounds
fn bounds(self: &Self) -> Rect
The bounds of the host, in the coordinates of its parent.
size
fn size(self: &Self) -> Size
The size of the host.
input_bounds
fn input_bounds(self: &Self) -> Rect
The bounds the pointer is normalized to, in the host's coordinates: the area the renderer drew the effect over without the padding of the effect, so that the input and the program agree (#580; Effector normalizes to the content of the host within its bounds and draws over the same rectangle); the host's own size, from its top left corner, before the host was drawn.
input_size
fn input_size(self: &Self) -> Size
The input size: the size of the input bounds.
render_bounds
fn render_bounds(self: &Self) -> Option<Rect>
The rectangle the renderer drew the effect over in the last frame, in the host's
coordinates (#580): the bounds of the subtree of the host, the padding of the effect
included, as the compositor read them back. None before the host was drawn, for a host
that is not shown, and without a compositor.
padding
fn padding(self: &Self) -> Thickness
The padding of the effect: how far its area reaches beyond the host's bounds.
effect_bounds
fn effect_bounds(self: &Self) -> Rect
The area of the effect in the host's coordinates: the input bounds inflated by the padding of the effect (the rectangle the renderer drew the effect over, once the host was drawn).
layer_scale
fn layer_scale(self: &Self) -> f64
Device pixels per device independent pixel of the host, as the render thread computes the
layer_scale of the effect: the render scaling of the host's presentation source times
the mean of the lengths of the axes of the transform from the host to the root. 1 for a
host that is not in a visual tree.
get_position
fn get_position(self: &Self, e: &PointerEventArgs) -> Point
The position of the pointer of e in the host's coordinates.
get_normalized_position
fn get_normalized_position(self: &Self, e: &PointerEventArgs, clamp: bool) -> Point
The position of the pointer of e normalized to the input bounds: 0 to 1 from the left
to the right and from the top to the bottom of the area the effect is drawn over, clamped
to 0..1 when clamp is set (Effector's GetNormalizedPosition).
normalize
fn normalize(self: &Self, position: Point, clamp: bool) -> Point
position, in the host's coordinates, normalized to the input bounds; an empty side
counts as one pixel.
get_effect_position
fn get_effect_position(self: &Self, e: &PointerEventArgs) -> Point
The position of the pointer of e in the coordinates of the effect's program: device
pixels from the top left corner of the area of the effect.
to_effect_space
fn to_effect_space(self: &Self, position: Point) -> Point
position, in the host's coordinates, in the coordinates of the effect's program.
capture_pointer
fn capture_pointer(self: &Self, e: &PointerEventArgs)
Captures the pointer of e to the host, so that the host and the effect receive its
input wherever it is until it is released.
release_pointer_capture
fn release_pointer_capture(self: &Self, e: &PointerEventArgs)
Releases the capture of the pointer of e when the host has it.
has_pointer_capture
fn has_pointer_capture(self: &Self, e: &PointerEventArgs) -> bool
Whether the host captures the pointer of e.
invalidate
fn invalidate(self: &Self)
Asks for a new snapshot of the effect: raises its
invalidated notification (Effector's Invalidate).
request_animation_frame
fn request_animation_frame(self: &Self, action: impl FnOnce(&EffectHostContext<'_>, SignedDuration) -> () + 'static)
Runs action on the next frame of the animation clock with the frame time, while the
effect is still the effect of the host: an effect that animates its uniforms (a ripple
that spreads) asks for one frame at a time. Nothing runs when the effect was detached
before the frame, or the host or the effect is gone.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyErasedDestructorIntoEither
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.