11use crate :: transform:: Footprint ;
2+ use glam:: DVec2 ;
23pub use no_std_types:: context:: { ArcCtx , Ctx } ;
34use std:: any:: Any ;
45use std:: borrow:: Borrow ;
@@ -26,6 +27,10 @@ pub trait ExtractAnimationTime {
2627 fn try_animation_time ( & self ) -> Option < f64 > ;
2728}
2829
30+ pub trait ExtractPointer {
31+ fn try_pointer ( & self ) -> Option < DVec2 > ;
32+ }
33+
2934pub trait ExtractIndex {
3035 fn try_index ( & self ) -> Option < impl Iterator < Item = usize > > ;
3136}
@@ -47,30 +52,34 @@ pub trait CloneVarArgs: ExtractVarArgs {
4752pub trait InjectFootprint { }
4853pub trait InjectRealTime { }
4954pub trait InjectAnimationTime { }
55+ pub trait InjectPointer { }
5056pub trait InjectIndex { }
5157pub trait InjectVarArgs { }
5258
5359// Modify* marker traits for context-transparent nodes
5460pub trait ModifyFootprint : ExtractFootprint + InjectFootprint { }
5561pub trait ModifyRealTime : ExtractRealTime + InjectRealTime { }
5662pub trait ModifyAnimationTime : ExtractAnimationTime + InjectAnimationTime { }
63+ pub trait ModifyPointer : ExtractPointer + InjectPointer { }
5764pub trait ModifyIndex : ExtractIndex + InjectIndex { }
5865pub trait ModifyVarArgs : ExtractVarArgs + InjectVarArgs { }
5966
60- pub trait ExtractAll : ExtractFootprint + ExtractIndex + ExtractRealTime + ExtractAnimationTime + ExtractVarArgs { }
67+ pub trait ExtractAll : ExtractFootprint + ExtractIndex + ExtractRealTime + ExtractAnimationTime + ExtractPointer + ExtractVarArgs { }
6168
62- impl < T : ?Sized + ExtractFootprint + ExtractIndex + ExtractRealTime + ExtractAnimationTime + ExtractVarArgs > ExtractAll for T { }
69+ impl < T : ?Sized + ExtractFootprint + ExtractIndex + ExtractRealTime + ExtractAnimationTime + ExtractPointer + ExtractVarArgs > ExtractAll for T { }
6370
6471impl < T : Ctx > InjectFootprint for T { }
6572impl < T : Ctx > InjectRealTime for T { }
6673impl < T : Ctx > InjectIndex for T { }
6774impl < T : Ctx > InjectAnimationTime for T { }
75+ impl < T : Ctx > InjectPointer for T { }
6876impl < T : Ctx > InjectVarArgs for T { }
6977
7078impl < T : Ctx + InjectFootprint + ExtractFootprint > ModifyFootprint for T { }
7179impl < T : Ctx + InjectRealTime + ExtractRealTime > ModifyRealTime for T { }
7280impl < T : Ctx + InjectIndex + ExtractIndex > ModifyIndex for T { }
7381impl < T : Ctx + InjectAnimationTime + ExtractAnimationTime > ModifyAnimationTime for T { }
82+ impl < T : Ctx + InjectPointer + ExtractPointer > ModifyPointer for T { }
7483impl < T : Ctx + InjectVarArgs + ExtractVarArgs > ModifyVarArgs for T { }
7584
7685// Public enum for flexible node macro codegen
@@ -79,11 +88,13 @@ pub enum ContextFeature {
7988 ExtractFootprint ,
8089 ExtractRealTime ,
8190 ExtractAnimationTime ,
91+ ExtractPointer ,
8292 ExtractIndex ,
8393 ExtractVarArgs ,
8494 InjectFootprint ,
8595 InjectRealTime ,
8696 InjectAnimationTime ,
97+ InjectPointer ,
8798 InjectIndex ,
8899 InjectVarArgs ,
89100}
@@ -96,8 +107,9 @@ bitflags! {
96107 const FOOTPRINT = 1 << 0 ;
97108 const REAL_TIME = 1 << 1 ;
98109 const ANIMATION_TIME = 1 << 2 ;
99- const INDEX = 1 << 3 ;
100- const VARARGS = 1 << 4 ;
110+ const POINTER = 1 << 3 ;
111+ const INDEX = 1 << 4 ;
112+ const VARARGS = 1 << 5 ;
101113 }
102114}
103115
@@ -116,6 +128,7 @@ impl From<&[ContextFeature]> for ContextDependencies {
116128 ContextFeature :: ExtractFootprint => ContextFeatures :: FOOTPRINT ,
117129 ContextFeature :: ExtractRealTime => ContextFeatures :: REAL_TIME ,
118130 ContextFeature :: ExtractAnimationTime => ContextFeatures :: ANIMATION_TIME ,
131+ ContextFeature :: ExtractPointer => ContextFeatures :: POINTER ,
119132 ContextFeature :: ExtractIndex => ContextFeatures :: INDEX ,
120133 ContextFeature :: ExtractVarArgs => ContextFeatures :: VARARGS ,
121134 _ => ContextFeatures :: empty ( ) ,
@@ -124,6 +137,7 @@ impl From<&[ContextFeature]> for ContextDependencies {
124137 ContextFeature :: InjectFootprint => ContextFeatures :: FOOTPRINT ,
125138 ContextFeature :: InjectRealTime => ContextFeatures :: REAL_TIME ,
126139 ContextFeature :: InjectAnimationTime => ContextFeatures :: ANIMATION_TIME ,
140+ ContextFeature :: InjectPointer => ContextFeatures :: POINTER ,
127141 ContextFeature :: InjectIndex => ContextFeatures :: INDEX ,
128142 ContextFeature :: InjectVarArgs => ContextFeatures :: VARARGS ,
129143 _ => ContextFeatures :: empty ( ) ,
@@ -174,6 +188,11 @@ impl<T: ExtractAnimationTime + Sync> ExtractAnimationTime for Option<T> {
174188 self . as_ref ( ) . and_then ( |x| x. try_animation_time ( ) )
175189 }
176190}
191+ impl < T : ExtractPointer + Sync > ExtractPointer for Option < T > {
192+ fn try_pointer ( & self ) -> Option < DVec2 > {
193+ self . as_ref ( ) . and_then ( |x| x. try_pointer ( ) )
194+ }
195+ }
177196impl < T : ExtractIndex > ExtractIndex for Option < T > {
178197 fn try_index ( & self ) -> Option < impl Iterator < Item = usize > > {
179198 self . as_ref ( ) . and_then ( |x| x. try_index ( ) )
@@ -211,6 +230,11 @@ impl<T: ExtractAnimationTime + Sync> ExtractAnimationTime for Arc<T> {
211230 ( * * self ) . try_animation_time ( )
212231 }
213232}
233+ impl < T : ExtractPointer + Sync > ExtractPointer for Arc < T > {
234+ fn try_pointer ( & self ) -> Option < DVec2 > {
235+ ( * * self ) . try_pointer ( )
236+ }
237+ }
214238impl < T : ExtractIndex > ExtractIndex for Arc < T > {
215239 fn try_index ( & self ) -> Option < impl Iterator < Item = usize > > {
216240 ( * * self ) . try_index ( )
@@ -303,6 +327,11 @@ impl ExtractAnimationTime for OwnedContextImpl {
303327 self . animation_time
304328 }
305329}
330+ impl ExtractPointer for OwnedContextImpl {
331+ fn try_pointer ( & self ) -> Option < DVec2 > {
332+ self . pointer
333+ }
334+ }
306335impl ExtractIndex for OwnedContextImpl {
307336 fn try_index ( & self ) -> Option < impl Iterator < Item = usize > > {
308337 self . index . clone ( ) . map ( |x| x. into_iter ( ) . rev ( ) )
@@ -363,6 +392,7 @@ pub struct OwnedContextImpl {
363392 index : Option < Vec < usize > > ,
364393 real_time : Option < f64 > ,
365394 animation_time : Option < f64 > ,
395+ pointer : Option < DVec2 > ,
366396}
367397
368398impl std:: fmt:: Debug for OwnedContextImpl {
@@ -374,6 +404,7 @@ impl std::fmt::Debug for OwnedContextImpl {
374404 . field ( "index" , & self . index )
375405 . field ( "real_time" , & self . real_time )
376406 . field ( "animation_time" , & self . animation_time )
407+ . field ( "pointer" , & self . pointer )
377408 . finish ( )
378409 }
379410}
@@ -392,6 +423,7 @@ impl Hash for OwnedContextImpl {
392423 self . index . hash ( state) ;
393424 self . real_time . map ( |x| x. to_bits ( ) ) . hash ( state) ;
394425 self . animation_time . map ( |x| x. to_bits ( ) ) . hash ( state) ;
426+ self . pointer . map ( |v| ( v. x . to_bits ( ) , v. y . to_bits ( ) ) ) . hash ( state) ;
395427 }
396428}
397429
@@ -400,12 +432,14 @@ impl OwnedContextImpl {
400432 pub fn from < T : ExtractAll + CloneVarArgs > ( value : T ) -> Self {
401433 OwnedContextImpl :: from_flags ( value, ContextFeatures :: all ( ) )
402434 }
435+
403436 #[ track_caller]
404437 pub fn from_flags < T : ExtractAll + CloneVarArgs > ( value : T , bitflags : ContextFeatures ) -> Self {
405438 let footprint = bitflags. contains ( ContextFeatures :: FOOTPRINT ) . then ( || value. try_footprint ( ) . copied ( ) ) . flatten ( ) ;
406439 let index = bitflags. contains ( ContextFeatures :: INDEX ) . then ( || value. try_index ( ) ) . flatten ( ) ;
407440 let real_time = bitflags. contains ( ContextFeatures :: REAL_TIME ) . then ( || value. try_real_time ( ) ) . flatten ( ) ;
408441 let animation_time = bitflags. contains ( ContextFeatures :: ANIMATION_TIME ) . then ( || value. try_animation_time ( ) ) . flatten ( ) ;
442+ let pointer = bitflags. contains ( ContextFeatures :: POINTER ) . then ( || value. try_pointer ( ) ) . flatten ( ) ;
409443 let parent = bitflags
410444 . contains ( ContextFeatures :: VARARGS )
411445 . then ( || match value. varargs_len ( ) {
@@ -421,8 +455,10 @@ impl OwnedContextImpl {
421455 index : index. map ( |x| x. collect ( ) ) ,
422456 real_time,
423457 animation_time,
458+ pointer,
424459 }
425460 }
461+
426462 pub const fn empty ( ) -> Self {
427463 OwnedContextImpl {
428464 footprint : None ,
@@ -431,6 +467,7 @@ impl OwnedContextImpl {
431467 index : None ,
432468 real_time : None ,
433469 animation_time : None ,
470+ pointer : None ,
434471 }
435472 }
436473}
@@ -475,6 +512,10 @@ impl OwnedContextImpl {
475512 self . animation_time = Some ( animation_time) ;
476513 self
477514 }
515+ pub fn with_pointer ( mut self , pointer : DVec2 ) -> Self {
516+ self . pointer = Some ( pointer) ;
517+ self
518+ }
478519 pub fn with_vararg ( mut self , value : Box < dyn AnyHash + Send + Sync > ) -> Self {
479520 assert ! ( self . varargs. is_none_or( |value| value. is_empty( ) ) ) ;
480521 self . varargs = Some ( Arc :: new ( [ value] ) ) ;
0 commit comments