pub struct Engine {
pub id: usize,
/* private fields */
}Expand description
Public API for the Layers Engine
§Usage: Setup a basic scene with a root layer
use layers::prelude::*;
let engine = Engine::create(800.0, 600.0);
let layer = engine.new_layer();
let engine = Engine::create(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.add_layer(&root_layer);§Usage: Update the engine
use layers::prelude::*;
let engine = Engine::create(800.0, 600.0);
// setup the scene...
engine.update(0.016);Fields§
§id: usizeImplementations§
Source§impl Engine
impl Engine
pub fn create(width: f32, height: f32) -> Arc<Self>
Sourcepub fn scene_set_root(&self, layer: impl Into<Layer>) -> NodeRef
pub fn scene_set_root(&self, layer: impl Into<Layer>) -> NodeRef
set the layer as the root of the scene and root of the layout tree
Sourcepub fn scene_set_size(&self, width: f32, height: f32)
pub fn scene_set_size(&self, width: f32, height: f32)
Set the size of the scene
pub fn get_layer<'a>(&self, node: impl Into<&'a NodeRef>) -> Option<Layer>
Sourcepub fn is_layer_alive(&self, node: &NodeRef) -> bool
pub fn is_layer_alive(&self, node: &NodeRef) -> bool
Returns true if the layer’s scene node still exists and has not been removed. Use this to detect stale layer handles before performing scene operations.
pub fn with_layers(&self, f: impl Fn(&HashMap<NodeRef, Layer>))
Sourcepub fn find_layer_by_key(&self, key: &str) -> Option<Layer>
pub fn find_layer_by_key(&self, key: &str) -> Option<Layer>
Find a layer by its key string. Returns the first matching layer,
or None if no layer with that key exists.
Sourcepub fn append_layer<'a>(
&self,
layer_id: impl Into<&'a NodeRef>,
parent: impl Into<Option<NodeRef>>,
) -> Result<(), LayerError>
pub fn append_layer<'a>( &self, layer_id: impl Into<&'a NodeRef>, parent: impl Into<Option<NodeRef>>, ) -> Result<(), LayerError>
Append the layer’s node to the scene tree and layout tree the layer is appended to the parent node if it is provided otherwise it is appended to the root of the scene
Returns Err(LayerError::StaleNode) if the layer handle is stale.
Sourcepub fn add_layer<'a>(
&self,
layer: impl Into<&'a NodeRef>,
) -> Result<(), LayerError>
pub fn add_layer<'a>( &self, layer: impl Into<&'a NodeRef>, ) -> Result<(), LayerError>
Append the layer to the root of the scene alias for append_layer, without a parent
Sourcepub fn prepend_layer(
&self,
layer: impl Into<Layer>,
parent: impl Into<Option<NodeRef>>,
) -> Result<(), LayerError>
pub fn prepend_layer( &self, layer: impl Into<Layer>, parent: impl Into<Option<NodeRef>>, ) -> Result<(), LayerError>
Prepend the layer to the root of the scene or to a parent node if the parent is provided
Returns Err(LayerError::StaleNode) if the layer handle is stale.
Sourcepub fn add_layer_to_positioned(
&self,
layer: impl Into<Layer>,
parent: Option<NodeRef>,
) -> Result<(), LayerError>
pub fn add_layer_to_positioned( &self, layer: impl Into<Layer>, parent: Option<NodeRef>, ) -> Result<(), LayerError>
Append the layer to the parent, adjusting its position to preserve its current global position relative to the new parent.
Returns Err(LayerError::StaleNode) if the layer handle is stale.
pub fn mark_for_delete(&self, layer: NodeRef)
pub fn scene(&self) -> Arc<Scene>
pub fn scene_root(&self) -> Option<NodeRef>
pub fn node_children(&self, node_ref: &NodeRef) -> Vec<NodeRef>
pub fn node_descendants(&self, node_ref: &NodeRef) -> Vec<NodeRef>
pub fn render_layer<'a>( &self, node_ref: impl Into<&'a NodeRef>, ) -> Option<RenderLayer>
pub fn renderable<'a>( &self, node_ref: impl Into<&'a NodeRef>, ) -> Option<SceneNodeRenderable>
pub fn node_render_size<'a>( &self, node_ref: impl Into<&'a NodeRef>, ) -> (f32, f32)
Sourcepub fn scene_get_node(
&self,
node_ref: impl Into<NodeRef>,
) -> Option<Node<SceneNode>>
pub fn scene_get_node( &self, node_ref: impl Into<NodeRef>, ) -> Option<Node<SceneNode>>
Get a copy of the node
pub fn scene_get_node_parent(&self, node_ref: NodeRef) -> Option<NodeRef>
pub fn now(&self) -> f32
Sourcepub fn pending_transactions_count(&self) -> usize
pub fn pending_transactions_count(&self) -> usize
Returns the number of transactions currently scheduled to be executed.
Use this to determine whether another call to update is needed.
pub fn add_animation_from_transition( &self, transition: &Transition, autostart: bool, ) -> AnimationRef
pub fn add_animation( &self, animation: Animation, autostart: bool, ) -> AnimationRef
pub fn start_animation(&self, animation: AnimationRef, delay: f32)
pub fn get_transaction( &self, tref: TransactionRef, ) -> Option<AnimatedNodeChange>
pub fn get_transaction_for_value( &self, value_id: usize, ) -> Option<AnimatedNodeChange>
pub fn get_animation(&self, animation: AnimationRef) -> Option<AnimationState>
pub fn schedule_change( &self, target_id: NodeRef, change: Arc<dyn SyncCommand>, animation_id: Option<AnimationRef>, ) -> TransactionRef
pub fn schedule_changes( &self, animated_changes: &[AnimatedNodeChange], animation: impl Into<Option<AnimationRef>>, ) -> Vec<TransactionRef>
pub fn attach_animation( &self, transaction: TransactionRef, animation: AnimationRef, )
pub fn cancel_animation(&self, animation: AnimationRef)
pub fn cancel_transaction(&self, transaction: TransactionRef)
pub fn step_time(&self, dt: f32)
Sourcepub fn update(&self, dt: f32) -> bool
pub fn update(&self, dt: f32) -> bool
Update the engine state by dt seconds Returns true if a redraw is needed
pub fn update_nodes(&self) -> Rect
pub fn get_node_layout_style(&self, node: NodeId) -> Style
pub fn set_node_layout_style(&self, node: NodeId, style: Style)
pub fn set_node_layout_size(&self, node: NodeId, size: Size) -> bool
pub fn scene_layer_at(&self, point: Point) -> Option<NodeRef>
Sourcepub fn debug_print_transaction_handlers(&self)
pub fn debug_print_transaction_handlers(&self)
Prints the current transaction handlers, grouped by transaction id, to help debug leaks.
Sourcepub fn debug_print_value_handlers(&self)
pub fn debug_print_value_handlers(&self)
Prints the current value handlers, grouped by value id, to help debug leaks.
Sourcepub fn debug_print_pointer_handlers(&self)
pub fn debug_print_pointer_handlers(&self)
Prints the current pointer handlers, grouped by node id, to help debug leaks.
pub fn clear_value_handlers(&self, value_id: usize)
pub fn on_start<F: Into<TransactionCallback>>( &self, transaction: TransactionRef, handler: F, once: bool, )
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_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 on_finish_value<F: Into<TransactionCallback>>( &self, value_id: usize, handler: F, once: bool, )
pub fn on_animation_start<F: Into<AnimationCallback>>( &self, animation: AnimationRef, handler: F, once: bool, )
pub fn on_animation_update<F: Into<AnimationCallback>>( &self, animation: AnimationRef, handler: F, once: bool, )
pub fn on_animation_finish<F: Into<AnimationCallback>>( &self, animation: AnimationRef, handler: F, once: bool, )
pub fn remove_pointer_handler(&self, layer_node: NodeRef, handler_id: usize)
pub fn remove_all_pointer_handlers(&self, layer_node: NodeRef)
Sourcepub fn pointer_move(
&self,
p: &Point,
root_id: impl Into<Option<NodeId>>,
) -> bool
pub fn pointer_move( &self, p: &Point, root_id: impl Into<Option<NodeId>>, ) -> bool
Sends pointer move event to the engine
pub fn current_hover(&self) -> Option<NodeRef>
pub fn get_pointer_position(&self) -> Point
pub fn layer_as_content(&self, layer: &Layer) -> ContentDrawFunction
pub fn damage(&self) -> Rect
pub fn clear_damage(&self)
Sourcepub fn compute_occlusion(&self, root: NodeRef)
pub fn compute_occlusion(&self, root: NodeRef)
Compute occlusion culling for the given root node.
Traverses the subtree front-to-back and marks nodes that are fully
hidden behind opaque layers. Results are stored on the Scene and
used by render_node_tree to skip occluded nodes.
Call this after update() for each root node you intend to draw.
Sourcepub fn clear_occlusion(&self)
pub fn clear_occlusion(&self)
Clear all cached occlusion data.
Call this before recomputing occlusion for a new frame to avoid stale entries from previous roots.
pub fn add_damage(&self, rect: Rect)
Sourcepub fn invalidate_hit_test_node_list(&self)
pub fn invalidate_hit_test_node_list(&self)
Mark the hit test node list as dirty, requiring rebuild on next update. Called when visibility or tree structure changes.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Engine
impl RefUnwindSafe for Engine
impl Send for Engine
impl Sync for Engine
impl Unpin for Engine
impl UnwindSafe for Engine
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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