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
impl LayersEngine
sourcepub fn new(width: f32, height: f32) -> Self
pub fn new(width: f32, height: f32) -> Self
Create a new engine with a scene initialized with the given width and height
sourcepub fn set_scene_size(&self, width: f32, height: f32)
pub fn set_scene_size(&self, width: f32, height: f32)
Set the size of the scene
sourcepub fn new_animation(
&self,
transition: Transition,
autostart: bool,
) -> AnimationRef
pub fn new_animation( &self, transition: Transition, autostart: bool, ) -> AnimationRef
Create a new animation from the given transition
§Arguments
autostart
: Ifautostart
is true, the animation start time will be the current engine time
sourcepub fn attach_animation(
&self,
transaction: TransactionRef,
animation: AnimationRef,
)
pub fn attach_animation( &self, transaction: TransactionRef, animation: AnimationRef, )
Attach an existing transaction to an exiting animation
sourcepub fn start_animation(&self, animation: AnimationRef, delay: f32)
pub fn start_animation(&self, animation: AnimationRef, delay: f32)
Start an animation with a delay
§Arguments
animation
: The animation to startdelay
: The delay before the animation starts in seconds
sourcepub fn add_animated_changes(
&self,
animated_changes: &[AnimatedNodeChange],
animation: impl Into<Option<AnimationRef>>,
) -> Vec<TransactionRef>
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
sourcepub fn update(&self, dt: f32) -> bool
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
sourcepub fn update_nodes(&self) -> Rect
pub fn update_nodes(&self) -> Rect
Update the nodes in the scene and returns the bounding box of the changes
sourcepub fn scene_add_layer(&self, layer: impl Into<Layer>) -> NodeRef
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
sourcepub fn scene_add_layer_to(
&self,
layer: impl Into<Layer>,
parent: impl Into<Option<NodeRef>>,
) -> NodeRef
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
sourcepub fn scene_add_layer_to_positioned(
&self,
layer: impl Into<Layer>,
parent: impl Into<Option<NodeRef>>,
) -> NodeRef
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
sourcepub fn scene_remove_layer(&self, node: impl Into<Option<NodeRef>>)
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
sourcepub fn scene_set_root(&self, layer: impl Into<Layer>) -> NodeRef
pub fn scene_set_root(&self, layer: impl Into<Layer>) -> NodeRef
Set the root layer of the scene
sourcepub fn scene_get_node(&self, node: &NodeRef) -> Option<Node<SceneNode>>
pub fn scene_get_node(&self, node: &NodeRef) -> Option<Node<SceneNode>>
Get a node from the scene if it exists
sourcepub fn scene_get_node_parent(&self, node: &NodeRef) -> Option<NodeRef>
pub fn scene_get_node_parent(&self, node: &NodeRef) -> Option<NodeRef>
Get the parent of a node if it exists
sourcepub fn scene_root(&self) -> Option<NodeRef>
pub fn scene_root(&self) -> Option<NodeRef>
Return reference to the root node of the scene
sourcepub fn scene_root_layer(&self) -> Option<SceneNode>
pub fn scene_root_layer(&self) -> Option<SceneNode>
Return the root layer of the scene
sourcepub fn scene_layer_at(&self, point: Point) -> Option<NodeRef>
pub fn scene_layer_at(&self, point: Point) -> Option<NodeRef>
Get the topmost layer under a given point
sourcepub fn clear_damage(&self)
pub fn clear_damage(&self)
Clear the damage rect of the scene
sourcepub fn pointer_move(
&self,
point: impl Into<Point>,
root_id: impl Into<Option<NodeId>>,
)
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
Sends a pointer button down event to the engine
Sends a pointer button up event to the engine
sourcepub fn current_hover(&self) -> Option<NodeRef>
pub fn current_hover(&self) -> Option<NodeRef>
Returns the current hover node
sourcepub fn get_pointer_position(&self) -> Point
pub fn get_pointer_position(&self) -> Point
Returns the current pointer position
sourcepub fn get_transaction(
&self,
transaction: TransactionRef,
) -> Option<AnimatedNodeChange>
pub fn get_transaction( &self, transaction: TransactionRef, ) -> Option<AnimatedNodeChange>
Returns the transaction for the given reference if it exists
sourcepub fn get_transaction_for_value(
&self,
value_id: usize,
) -> Option<AnimatedNodeChange>
pub fn get_transaction_for_value( &self, value_id: usize, ) -> Option<AnimatedNodeChange>
Returns the transaction for the given value_id if it exists
sourcepub fn get_animation(&self, animation: AnimationRef) -> Option<AnimationState>
pub fn get_animation(&self, animation: AnimationRef) -> Option<AnimationState>
Returns the animation for the given reference if it exists
pub fn on_finish<F: Into<TransactionCallback>>( &self, transaction: TransactionRef, handler: F, once: bool, )
pub fn on_update<F: Into<TransactionCallback>>( &self, transaction: TransactionRef, handler: F, once: bool, )
pub fn on_start<F: Into<TransactionCallback>>( &self, transaction: TransactionRef, handler: F, once: bool, )
pub fn on_update_value<F: Into<TransactionCallback>>( &self, value_id: usize, handler: F, once: bool, )
pub fn on_start_value<F: Into<TransactionCallback>>( &self, value_id: usize, handler: F, once: bool, )
pub fn cancel_animation(&self, animation: AnimationRef)
pub fn layer_as_content(&self, layer: &Layer) -> ContentDrawFunction
Trait Implementations§
source§impl Clone for LayersEngine
impl Clone for LayersEngine
source§fn clone(&self) -> LayersEngine
fn clone(&self) -> LayersEngine
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for LayersEngine
impl !RefUnwindSafe for LayersEngine
impl Send for LayersEngine
impl Sync for LayersEngine
impl Unpin for LayersEngine
impl !UnwindSafe for LayersEngine
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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