fix: new apis

This commit is contained in:
Nova
2024-05-28 01:24:49 -04:00
parent 89fcc55cca
commit d7fba79be9
5 changed files with 445 additions and 426 deletions

809
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
use super::{ use super::{
input_method_client, InputDataTrait, InputDataType, InputHandler, InputMethodAspect, input_method_client, InputDataTrait, InputDataType, InputHandler, InputMethodAspect,
INPUT_HANDLER_REGISTRY, INPUT_METHOD_REGISTRY, InputMethodRefAspect, INPUT_HANDLER_REGISTRY, INPUT_METHOD_REGISTRY,
}; };
use crate::{ use crate::{
core::{client::Client, node_collections::LifeLinkedNodeMap, registry::Registry}, core::{client::Client, node_collections::LifeLinkedNodeMap, registry::Registry},
@@ -51,6 +51,7 @@ impl InputMethod {
method.make_alias(&handler); method.make_alias(&handler);
} }
let method = INPUT_METHOD_REGISTRY.add(method); let method = INPUT_METHOD_REGISTRY.add(method);
<InputMethod as InputMethodRefAspect>::add_node_members(node);
<InputMethod as InputMethodAspect>::add_node_members(node); <InputMethod as InputMethodAspect>::add_node_members(node);
node.add_aspect_raw(method.clone()); node.add_aspect_raw(method.clone());
Ok(method) Ok(method)
@@ -119,7 +120,7 @@ impl InputMethod {
.add(handler.uid.clone(), &handler_alias); .add(handler.uid.clone(), &handler_alias);
let Some(handler_field_node) = handler.field.spatial_ref().node.upgrade() else { let Some(handler_field_node) = handler.field.spatial_ref().node.upgrade() else {
return return;
}; };
// Handler's field // Handler's field
let Ok(rx_field_alias) = Alias::create( let Ok(rx_field_alias) = Alias::create(
@@ -134,8 +135,12 @@ impl InputMethod {
self.handler_aliases self.handler_aliases
.add(handler.uid.clone() + "-field", &rx_field_alias); .add(handler.uid.clone() + "-field", &rx_field_alias);
let _ = input_method_client::create_handler(
let _ = input_method_client::create_handler(&method_node, &handler.uid, &handler_node, &rx_field_alias); &method_node,
&handler.uid,
&handler_node,
&rx_field_alias,
);
} }
pub(super) fn handle_drop_handler(&self, handler: &InputHandler) { pub(super) fn handle_drop_handler(&self, handler: &InputHandler) {
let uid = handler.uid.as_str(); let uid = handler.uid.as_str();
@@ -151,6 +156,22 @@ impl InputMethod {
impl Aspect for InputMethod { impl Aspect for InputMethod {
const NAME: &'static str = "InputMethod"; const NAME: &'static str = "InputMethod";
} }
impl InputMethodRefAspect for InputMethod {
#[doc = "Have the input handler that this method reference came from capture the method for the next frame."]
fn request_capture(
node: Arc<Node>,
_calling_client: Arc<Client>,
handler: Arc<Node>,
) -> Result<()> {
let input_method = node.get_aspect::<InputMethod>()?;
let input_handler = handler.get_aspect::<InputHandler>()?;
input_method.captures.add_raw(&input_handler);
// input_method_client::
// node.send_remote_signal("capture", message)
Ok(())
}
}
impl InputMethodAspect for InputMethod { impl InputMethodAspect for InputMethod {
#[doc = "Set the spatial input component of this input method. You must keep the same input data type throughout the entire thing."] #[doc = "Set the spatial input component of this input method. You must keep the same input data type throughout the entire thing."]
fn set_input( fn set_input(
@@ -187,18 +208,20 @@ impl InputMethodAspect for InputMethod {
Ok(()) Ok(())
} }
#[doc = "Have the input handler that this method reference came from capture the method for the next frame."] #[doc = "Set which handlers are captured."]
fn request_capture( fn set_captures(
node: Arc<Node>, node: Arc<Node>,
_calling_client: Arc<Client>, _calling_client: Arc<Client>,
handler: Arc<Node>, handlers: Vec<Arc<Node>>,
) -> Result<()> { ) -> Result<()> {
let input_method = node.get_aspect::<InputMethod>()?; let input_method = node.get_aspect::<InputMethod>()?;
let input_handler = handler.get_aspect::<InputHandler>()?; input_method.captures.clear();
for handler in handlers {
input_method.captures.add_raw(&input_handler); let Ok(handler) = handler.get_aspect::<InputHandler>() else {
// input_method_client:: continue;
// node.send_remote_signal("capture", message) };
input_method.captures.add_raw(&handler);
}
Ok(()) Ok(())
} }
} }

View File

@@ -211,7 +211,6 @@ pub fn panel_item_from_node(node: &Node) -> Option<Arc<dyn PanelItemTrait>> {
} }
pub trait PanelItemTrait: Backend + Send + Sync + 'static { pub trait PanelItemTrait: Backend + Send + Sync + 'static {
fn uid(&self) -> &str;
fn serialize_start_data(&self, id: &str) -> Result<Message>; fn serialize_start_data(&self, id: &str) -> Result<Message>;
} }
@@ -533,10 +532,6 @@ impl<B: Backend + ?Sized> PanelItem<B> {
flex_no_args!(reset_touches_flex, reset_touches); flex_no_args!(reset_touches_flex, reset_touches);
} }
impl<B: Backend + ?Sized> PanelItemTrait for PanelItem<B> { impl<B: Backend + ?Sized> PanelItemTrait for PanelItem<B> {
fn uid(&self) -> &str {
&self.uid
}
fn serialize_start_data(&self, id: &str) -> Result<Message> { fn serialize_start_data(&self, id: &str) -> Result<Message> {
Ok(serialize((id, self.start_data()?))?.into()) Ok(serialize((id, self.start_data()?))?.into())
} }

View File

@@ -103,7 +103,7 @@ impl Node {
aspects: Default::default(), aspects: Default::default(),
destroyable, destroyable,
}; };
<Node as NodeAspect>::add_node_members(&node); <Node as OwnedAspect>::add_node_members(&node);
node node
} }
pub fn add_to_scenegraph(self) -> Result<Arc<Node>> { pub fn add_to_scenegraph(self) -> Result<Arc<Node>> {
@@ -267,7 +267,7 @@ impl Debug for Node {
.finish() .finish()
} }
} }
impl NodeAspect for Node { impl OwnedAspect for Node {
fn set_enabled(node: Arc<Node>, _calling_client: Arc<Client>, enabled: bool) -> Result<()> { fn set_enabled(node: Arc<Node>, _calling_client: Arc<Client>, enabled: bool) -> Result<()> {
node.enabled.store(enabled, Ordering::Relaxed); node.enabled.store(enabled, Ordering::Relaxed);
Ok(()) Ok(())

View File

@@ -77,6 +77,7 @@ impl Spatial {
if let Some(parent) = parent { if let Some(parent) = parent {
parent.children.add_raw(&spatial); parent.children.add_raw(&spatial);
} }
<Spatial as SpatialRefAspect>::add_node_members(node);
<Spatial as SpatialAspect>::add_node_members(node); <Spatial as SpatialAspect>::add_node_members(node);
node.add_aspect_raw(spatial.clone()); node.add_aspect_raw(spatial.clone());
spatial spatial
@@ -243,7 +244,7 @@ impl Spatial {
impl Aspect for Spatial { impl Aspect for Spatial {
const NAME: &'static str = "Spatial"; const NAME: &'static str = "Spatial";
} }
impl SpatialAspect for Spatial { impl SpatialRefAspect for Spatial {
async fn get_local_bounding_box( async fn get_local_bounding_box(
node: Arc<Node>, node: Arc<Node>,
_calling_client: Arc<Client>, _calling_client: Arc<Client>,
@@ -304,7 +305,8 @@ impl SpatialAspect for Spatial {
scale: Some(scale.into()), scale: Some(scale.into()),
}) })
} }
}
impl SpatialAspect for Spatial {
fn set_local_transform( fn set_local_transform(
node: Arc<Node>, node: Arc<Node>,
_calling_client: Arc<Client>, _calling_client: Arc<Client>,