# ElementCompositionPreview

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-controls/hosting/struct-elementcompositionpreview/

**struct** · [`ferroui-controls`](/docs/0.5.0/api/ferroui-controls/) · v0.5.0

```rust
struct ElementCompositionPreview
```

Access to the composition visuals of elements and to the composition-driven behaviours of
elements (`Microsoft.UI.Xaml.Hosting.ElementCompositionPreview`).

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L29)

## Members

- [`get_element_visual`](#function-get_element_visual)
- [`get_element_child_visual`](#function-get_element_child_visual)
- [`set_element_child_visual`](#function-set_element_child_visual)
- [`set_implicit_show_animation`](#function-set_implicit_show_animation)
- [`set_implicit_hide_animation`](#function-set_implicit_hide_animation)
- [`set_is_translation_enabled`](#function-set_is_translation_enabled)
- [`get_scroll_viewer_manipulation_property_set`](#function-get_scroll_viewer_manipulation_property_set)
- [`get_pointer_position_property_set`](#function-get_pointer_position_property_set)

<a id="function-get_element_visual"></a>

### get_element_visual

```rust
fn get_element_visual(element: &Visual) -> Option<Rc<CompositionVisual>>
```

`GetElementVisual`: the composition visual of `element` (WinUI's handoff visual). The
same visual is returned while the element stays in the tree; `None` while the element is
not in a tree rendered by a compositor.

The renderer writes the `Offset`, `Size`, `Opacity`, `IsVisible`, clip and
`TransformMatrix` of this visual when the element is rendered again, as WinUI's layout
writes the handoff visual; `Translation`, `Scale`, `CenterPoint`, `RotationAngle`,
`Orientation` and `AnchorPoint` belong to the application.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L40)

<a id="function-get_element_child_visual"></a>

### get_element_child_visual

```rust
fn get_element_child_visual(element: &Visual) -> Option<Rc<CompositionVisual>>
```

`GetElementChildVisual`: the visual set with
`set_element_child_visual` (WinUI's hand-in visual).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L46)

<a id="function-set_element_child_visual"></a>

### set_element_child_visual

```rust
fn set_element_child_visual(element: &Visual, visual: Option<Rc<CompositionVisual>>)
```

`SetElementChildVisual`: shows `visual` as the last child of the composition visual of
`element`, above the element's content and children. `None` removes it.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L52)

<a id="function-set_implicit_show_animation"></a>

### set_implicit_show_animation

```rust
fn set_implicit_show_animation(element: &Visual, animation: Option<Rc<dyn ICompositionAnimationBase>>)
```

`SetImplicitShowAnimation`: the animation (or animation group) started on the visual of
`element` when the element is added to the tree or its `IsVisible` becomes `true`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L58)

<a id="function-set_implicit_hide_animation"></a>

### set_implicit_hide_animation

```rust
fn set_implicit_hide_animation(element: &Visual, animation: Option<Rc<dyn ICompositionAnimationBase>>)
```

`SetImplicitHideAnimation`: the animation (or animation group) started on the visual of
`element` when the element is removed from the tree or its `IsVisible` becomes `false`.
The element stays visible until the animation completes.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L65)

<a id="function-set_is_translation_enabled"></a>

### set_is_translation_enabled

```rust
fn set_is_translation_enabled(element: &Visual, value: bool)
```

`SetIsTranslationEnabled`.

In WinUI the handoff visual gains a `Translation` entry in its property set, which the
framework then folds into the transform of the element. Here every composition visual has
a `Translation` property, applied after its other transforms, so translation is always
enabled; the call records the request and changes nothing else.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L75)

<a id="function-get_scroll_viewer_manipulation_property_set"></a>

### get_scroll_viewer_manipulation_property_set

```rust
fn get_scroll_viewer_manipulation_property_set(scroll_viewer: &ScrollViewer) -> Option<Rc<CompositionPropertySet>>
```

`GetScrollViewerManipulationPropertySet`: a property set that follows the scrolling and the
zoom of `scroll_viewer`, with the entries of WinUI's manipulation transform
(`ManipulationTransform.cpp`): `Translation` (the translation of the content: the negated
offset, in zoomed units, as a `Vector3`), `Pan` (the same: the zoom is about the origin of
the content), `Scale` (`(ZoomFactor, ZoomFactor, 1)`), `CenterPoint` (the centre of that
scale, the origin) and `Matrix` (the scale followed by the translation, a `Matrix4x4`).
The same set is returned for the same scroll viewer.

Typical uses: an expression animation of a header's `Offset` or `Translation` that reads
`scroller.Translation.Y` for a parallax effect, or `scroller.Scale.X` to keep an overlay
at the same size while the content zooms.

Deviation (winui-composition.md): in WinUI the compositor updates the set during a
manipulation without the UI thread; here the set is written when the offset or the zoom
of the scroll viewer changes, on the UI thread, in the batch of the frame in which the
content moves (FerroUI scrolls on the UI thread, and its compositor runs there too).
`None` when no compositor is available.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L96)

<a id="function-get_pointer_position_property_set"></a>

### get_pointer_position_property_set

```rust
fn get_pointer_position_property_set(element: &Visual) -> Option<Rc<CompositionPropertySet>>
```

`GetPointerPositionPropertySet`: a property set with a `Position` entry (a `Vector3`)
that follows the pointer over the window of `element`, in the coordinates of `element`.
A new set is returned on each call, as in WinUI.

WinUI drives the set from the compositor's hover input; here it is updated by the moves
of the pointer that the window of the element receives, handled or not, on the UI thread.
The set follows the element into another window. `None` when no compositor is
available.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.Controls/hosting/element_composition_preview.rs#L144)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`ClassDefaults`](/docs/0.5.0/api/ferroui-base/trait-classdefaults/)
- `ErasedDestructor`
- `IntoEither`

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
