Struct lay_rs::engine::LayersEngine

source ·
pub struct LayersEngine { /* private fields */ }
Expand description

Public API for the Layers Engine

§Usage: Setup a basic scene with a root layer

use lay_rs::prelude::*;

let engine = LayersEngine::new(800.0, 600.0);
let layer = engine.new_layer();
let engine = LayersEngine::new(1024.0, 768.0);
let root_layer = engine.new_layer();
root_layer.set_position(Point { x: 0.0, y: 0.0 }, None);
root_layer.set_background_color(
    PaintColor::Solid {
        color: Color::new_rgba255(180, 180, 180, 255),
    },
   None,
);
root_layer.set_border_corner_radius(10.0, None);
root_layer.set_layout_style(taffy::Style {
    position: taffy::Position::Absolute,
    display: taffy::Display::Flex,
    flex_direction: taffy::FlexDirection::Column,
    justify_content: Some(taffy::JustifyContent::Center),
    align_items: Some(taffy::AlignItems::Center),
    ..Default::default()
});
engine.scene_add_layer(root_layer.clone());

§Usage: Update the engine

use lay_rs::prelude::*;

let engine = LayersEngine::new(800.0, 600.0);
// setup the scene...
engine.update(0.016);

Implementations§

source§

impl LayersEngine

source

pub fn new(width: f32, height: f32) -> Self

Create a new engine with a scene initialized with the given width and height

source

pub fn set_scene_size(&self, width: f32, height: f32)

Set the size of the scene

source

pub fn new_layer(&self) -> Layer

Create a new layer associated with the engine

source

pub fn new_animation( &self, transition: Transition, autostart: bool, ) -> AnimationRef

Create a new animation from the given transition

§Arguments
  • autostart: If autostart is true, the animation start time will be the current engine time
source

pub fn attach_animation( &self, transaction: TransactionRef, animation: AnimationRef, )

Attach an existing transaction to an exiting animation

source

pub fn start_animation(&self, animation: AnimationRef, delay: f32)

Start an animation with a delay

§Arguments
  • animation: The animation to start
  • delay: The delay before the animation starts in seconds
source

pub fn add_animated_changes( &self, animated_changes: &[AnimatedNodeChange], animation: impl Into<Option<AnimationRef>>, ) -> Vec<TransactionRef>

Add a new set of changes to the engine If an animation is provided, the changes will be animated using the same animation

source

pub fn update(&self, dt: f32) -> bool

Tick the engine by the given delta time Returns true if the engine has changes that needs to be rendered

§Arguments
  • dt: The delta time in seconds
source

pub fn update_nodes(&self) -> Rect

Update the nodes in the scene and returns the bounding box of the changes

source

pub fn scene_add_layer(&self, layer: impl Into<Layer>) -> NodeRef

Add a new layer to the scene The layer will be added to the root of the scene

source

pub fn scene_add_layer_to( &self, layer: impl Into<Layer>, parent: impl Into<Option<NodeRef>>, ) -> NodeRef

Add a new layer to the scene, attached to the given parent

If the parent is None, the layer will be attached to the root of the scene

source

pub fn scene_add_layer_to_positioned( &self, layer: impl Into<Layer>, parent: impl Into<Option<NodeRef>>, ) -> NodeRef

Add a new layer to the scene, attached to the given parent, maintaining the given position.

If the parent is None, the layer will be attached to the root of the scene

source

pub fn scene_remove_layer(&self, node: impl Into<Option<NodeRef>>)

Remove a layer from the scene

Note: The layer is immediatly hidden, will be removed from the scene at the next update

source

pub fn scene_set_root(&self, layer: impl Into<Layer>) -> NodeRef

Set the root layer of the scene

source

pub fn scene_get_node(&self, node: &NodeRef) -> Option<Node<SceneNode>>

Get a node from the scene if it exists

source

pub fn scene_get_node_parent(&self, node: &NodeRef) -> Option<NodeRef>

Get the parent of a node if it exists

source

pub fn scene(&self) -> &Arc<Scene>

Return reference to the scene

source

pub fn scene_root(&self) -> Option<NodeRef>

Return reference to the root node of the scene

source

pub fn scene_root_layer(&self) -> Option<SceneNode>

Return the root layer of the scene

source

pub fn scene_layer_at(&self, point: Point) -> Option<NodeRef>

Get the topmost layer under a given point

source

pub fn damage(&self) -> Rect

Get the current damage rect of the scene

source

pub fn clear_damage(&self)

Clear the damage rect of the scene

source

pub fn pointer_move( &self, point: impl Into<Point>, root_id: impl Into<Option<NodeId>>, )

Sends a pointer move event to the engine

If root_id is provided, the event will be sent to the given root layer and propagated to its children

source

pub fn pointer_button_down(&self)

Sends a pointer button down event to the engine

source

pub fn pointer_button_up(&self)

Sends a pointer button up event to the engine

source

pub fn current_hover(&self) -> Option<NodeRef>

Returns the current hover node

source

pub fn get_pointer_position(&self) -> Point

Returns the current pointer position

source

pub fn get_transaction( &self, transaction: TransactionRef, ) -> Option<AnimatedNodeChange>

Returns the transaction for the given reference if it exists

source

pub fn get_transaction_for_value( &self, value_id: usize, ) -> Option<AnimatedNodeChange>

Returns the transaction for the given value_id if it exists

source

pub fn get_animation(&self, animation: AnimationRef) -> Option<AnimationState>

Returns the animation for the given reference if it exists

source

pub fn on_finish<F: Into<TransactionCallback>>( &self, transaction: TransactionRef, handler: F, once: bool, )

source

pub fn on_update<F: Into<TransactionCallback>>( &self, transaction: TransactionRef, handler: F, once: bool, )

source

pub fn on_start<F: Into<TransactionCallback>>( &self, transaction: TransactionRef, handler: F, once: bool, )

source

pub fn on_update_value<F: Into<TransactionCallback>>( &self, value_id: usize, handler: F, once: bool, )

source

pub fn on_start_value<F: Into<TransactionCallback>>( &self, value_id: usize, handler: F, once: bool, )

source

pub fn cancel_animation(&self, animation: AnimationRef)

source

pub fn layer_as_content(&self, layer: &Layer) -> ContentDrawFunction

Trait Implementations§

source§

impl Clone for LayersEngine

source§

fn clone(&self) -> LayersEngine

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for LayersEngine

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.