Skip to main content

Layer

Trait Layer 

Source
pub trait Layer: Sized + 'static {
    const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable> = None;

    // Required methods
    fn layer_data(self: Handle<Self>, app: &App) -> &LayerData;
    fn layer_data_mut(self: Handle<Self>, app: &mut App) -> &mut LayerData;
    fn add_to_scene(
        self: Handle<Self>,
        app: &mut App,
        builder: &mut SceneBuilder,
    );

    // Provided methods
    fn supports_rasterization(self: Handle<Self>, app: &App) -> bool { ... }
    fn describe_clip_bounds(self: Handle<Self>, app: &App) -> Option<Rect> { ... }
    fn always_needs_add_to_scene(self: Handle<Self>, app: &App) -> bool { ... }
    fn dispose(self: Handle<Self>, app: &mut App) { ... }
    fn attach(self: Handle<Self>, app: &mut App, owner: HandleId) { ... }
    fn detach(self: Handle<Self>, app: &mut App) { ... }
    fn redepth_children(self: Handle<Self>, app: &mut App) { ... }
    fn find_annotations(
        self: Handle<Self>,
        app: &App,
        result: &mut AnnotationSearch,
        local_position: Offset,
        only_first: bool,
    ) -> bool { ... }
    fn fire_composition_callbacks(
        self: Handle<Self>,
        app: &mut App,
        include_children: bool,
    ) { ... }
}
Expand description

A composited layer.

During painting, the render tree generates a tree of composited layers that are uploaded into the engine and displayed by the compositor. This class is the base class for all composited layers.

Most layers can have their properties mutated, and layers can be moved to different parents. The scene must be explicitly recomposited after such changes are made; the layer tree does not maintain its own dirty state.

To composite the tree, create a SceneBuilder object, pass it to the root layer’s AnyContainerLayer::build_scene and give the Scene to the view.

§Memory

Layers retain resources between frames to speed up rendering. A layer will retain these resources until all LayerHandles referring to the layer have nulled out their references.

Layers must not be used after disposal. If a RenderObject needs to maintain a layer for later usage, it must create a handle to that layer. This is handled automatically for the RenderObject.layer property, but additional layers must use their own LayerHandle.

Flutter’s abstract Layer: the shared bodies are on LayerBase. A leaf implements this trait; where Dart runs the inherited body it calls it by name, LayerBase::attach(self, app, owner).

Provided Associated Constants§

Source

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable> = None

The container table when this type extends ContainerLayer; layer_accessors!(container) sets it. Dart’s layer is ContainerLayer.

Required Methods§

Source

fn layer_data(self: Handle<Self>, app: &App) -> &LayerData

Dart’s base-class fields, held under the field layer ([layer_accessors!]).

Source

fn layer_data_mut(self: Handle<Self>, app: &mut App) -> &mut LayerData

Source

fn add_to_scene(self: Handle<Self>, app: &mut App, builder: &mut SceneBuilder)

Override this method to upload this layer to the engine.

Provided Methods§

Source

fn supports_rasterization(self: Handle<Self>, app: &App) -> bool

Whether or not this layer, or any child layers, can be rasterized with Scene.toImage.

If false, calling the above methods may yield an image which is incomplete.

This value may change throughout the lifetime of the object, as the child layers themselves are added or removed.

Source

fn describe_clip_bounds(self: Handle<Self>, app: &App) -> Option<Rect>

Describes the clip that would be applied to contents of this layer, if any.

Source

fn always_needs_add_to_scene(self: Handle<Self>, app: &App) -> bool

Subclasses may override this to true to disable retained rendering.

Source

fn dispose(self: Handle<Self>, app: &mut App)

Clears any retained resources that this layer holds.

This method must dispose resources such as Picture objects. The layer is still usable after this call, but any graphics related resources it holds will need to be recreated.

This method only disposes resources for this layer. For example, if it is a ContainerLayer, it does not dispose resources of any children. However, ContainerLayers do remove any children they have when this method is called, and if this layer was the last holder of a removed child handle, the child may recursively clean up its resources.

This method automatically gets called when all outstanding LayerHandles are disposed. LayerHandle objects are typically held by the parent layer of this layer and any RenderObjects that participated in creating it.

After calling this method, the object is unusable: the base body destroys the arena entry. An override ends with LayerBase::dispose(self, app).

Source

fn attach(self: Handle<Self>, app: &mut App, owner: HandleId)

Mark this layer as attached to the given owner.

Typically called only from the parent’s attach method, and by the owner to mark the root of a tree as attached.

Subclasses with children should override this method to attach all their children to the same owner after calling the inherited method, LayerBase::attach(self, app, owner).

Source

fn detach(self: Handle<Self>, app: &mut App)

Mark this layer as detached from its owner.

Typically called only from the parent’s detach, and by the owner to mark the root of a tree as detached.

Subclasses with children should override this method to detach all their children after calling the inherited method, LayerBase::detach(self, app).

Source

fn redepth_children(self: Handle<Self>, app: &mut App)

Adjust the depth of this node’s children, if any.

Override this method in subclasses with child nodes to call AnyContainerLayer::redepth_child for each child. Do not call this method directly.

Source

fn find_annotations( self: Handle<Self>, app: &App, result: &mut AnnotationSearch, local_position: Offset, only_first: bool, ) -> bool

Search this layer and its subtree for annotations of the searched type at the location described by local_position.

This method is called by the default implementation of AnyLayer::find and AnyLayer::find_all_annotations. Override this method to customize how the layer should search for annotations, or if the layer has its own annotations to add.

The default implementation always returns false, which means neither the layer nor its children has annotations, and the annotation search is not absorbed either.

The annotations are searched by first visiting each child recursively, then this layer, resulting in an order from visually front to back. New annotations found during the walk are added to the tail of result.

The only_first parameter indicates that, if true, the search will stop when it finds the first qualified annotation; otherwise, it will walk the entire subtree.

The return value indicates the opacity of this layer and its subtree at this position. If it returns true, then this layer’s parent should skip the children behind this layer. The return value does not affect whether the parent adds its own annotations.

Source

fn fire_composition_callbacks( self: Handle<Self>, app: &mut App, include_children: bool, )

Dart’s _fireCompositionCallbacks; ContainerLayer recurses into its children.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Layer for AnnotatedRegionLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for BackdropFilterLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for ClipPathLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for ClipRRectLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for ClipRectLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for EmbeddedLayer

Source§

impl Layer for FollowerLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for LeaderLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for OffsetLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for OpacityLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for PictureLayer

Source§

impl Layer for TransformLayer

Source§

const AS_CONTAINER: Option<fn() -> &'static ContainerLayerVTable>

Source§

impl Layer for VideoLayer