feat: compose interactive world ui across nested 3d viewports
This commit is contained in:
+69
-3
@@ -57,6 +57,8 @@ enum Query {
|
||||
ScrollIntoView,
|
||||
FitView,
|
||||
Pick3D,
|
||||
ToView,
|
||||
ToLocal,
|
||||
Parent,
|
||||
FirstChild,
|
||||
NextSibling,
|
||||
@@ -81,7 +83,12 @@ impl NativeCallable for Method {
|
||||
Some(endor_core::CallArity::exact(
|
||||
if matches!(
|
||||
self.query,
|
||||
Query::HitTest | Query::Pick3D | Query::ScrollTo | Query::ScrollBy
|
||||
Query::HitTest
|
||||
| Query::Pick3D
|
||||
| Query::ToView
|
||||
| Query::ToLocal
|
||||
| Query::ScrollTo
|
||||
| Query::ScrollBy
|
||||
) {
|
||||
2
|
||||
} else {
|
||||
@@ -103,6 +110,8 @@ impl NativeCallable for Method {
|
||||
| Query::ScrollIntoView
|
||||
| Query::FitView
|
||||
| Query::Pick3D
|
||||
| Query::ToView
|
||||
| Query::ToLocal
|
||||
| Query::ScrollPosition
|
||||
)
|
||||
{
|
||||
@@ -110,7 +119,12 @@ impl NativeCallable for Method {
|
||||
}
|
||||
let arity = if matches!(
|
||||
self.query,
|
||||
Query::HitTest | Query::Pick3D | Query::ScrollTo | Query::ScrollBy
|
||||
Query::HitTest
|
||||
| Query::Pick3D
|
||||
| Query::ToView
|
||||
| Query::ToLocal
|
||||
| Query::ScrollTo
|
||||
| Query::ScrollBy
|
||||
) {
|
||||
2
|
||||
} else {
|
||||
@@ -120,6 +134,50 @@ impl NativeCallable for Method {
|
||||
return Err(VmError::InvalidArgument("incorrect Mount method arity"));
|
||||
}
|
||||
let value = match self.query {
|
||||
Query::ToView | Query::ToLocal => {
|
||||
if mount.layout.is_some() {
|
||||
return Err(VmError::InvalidArgument(
|
||||
"coordinate conversion requires committed geometry",
|
||||
));
|
||||
}
|
||||
let point = crate::geometry::Point::new(
|
||||
crate::scroll::coordinate(&args[0])?,
|
||||
crate::scroll::coordinate(&args[1])?,
|
||||
);
|
||||
let point =
|
||||
if matches!(self.query, Query::ToView) {
|
||||
let point = mount.geometry.view.unwrap_or_default().point(
|
||||
crate::geometry::Point::new(
|
||||
point.x + mount.geometry.x,
|
||||
point.y + mount.geometry.y,
|
||||
),
|
||||
);
|
||||
mount
|
||||
.geometry
|
||||
.panel
|
||||
.as_ref()
|
||||
.map_or(Some(point), |panel| panel.project_point(point))
|
||||
} else {
|
||||
mount.geometry.logical_point(point).map(|point| {
|
||||
crate::geometry::Point::new(
|
||||
point.x - mount.geometry.x,
|
||||
point.y - mount.geometry.y,
|
||||
)
|
||||
})
|
||||
};
|
||||
if let Some(point) = point {
|
||||
let result = cx.new_object()?;
|
||||
let desktop = cx.upgrade(self.desktop)?.ok_or(VmError::InvalidArgument(
|
||||
"coordinate conversion desktop expired",
|
||||
))?;
|
||||
crate::ui_bridge::attach_desktop_type(cx, result, "Point", desktop)?;
|
||||
cx.set_attr(result, "x", crate::native_visual::value(point.x))?;
|
||||
cx.set_attr(result, "y", crate::native_visual::value(point.y))?;
|
||||
Value::Object(result)
|
||||
} else {
|
||||
Value::Nil
|
||||
}
|
||||
}
|
||||
Query::ScrollTo | Query::ScrollBy => {
|
||||
crate::scroll::set(
|
||||
cx,
|
||||
@@ -281,6 +339,7 @@ fn mount_signature(
|
||||
Query::Page => CallType::nullable(nominal("Page")?),
|
||||
Query::HitTest => T::Bool.into(),
|
||||
Query::Pick3D => CallType::nullable(nominal("RayHit3D")?),
|
||||
Query::ToView | Query::ToLocal => CallType::nullable(nominal("Point")?),
|
||||
Query::ScrollPosition => T::Any.into(),
|
||||
_ => T::Unit.into(),
|
||||
};
|
||||
@@ -294,7 +353,12 @@ fn mount_signature(
|
||||
};
|
||||
let parameters = if matches!(
|
||||
query,
|
||||
Query::HitTest | Query::Pick3D | Query::ScrollTo | Query::ScrollBy
|
||||
Query::HitTest
|
||||
| Query::Pick3D
|
||||
| Query::ToView
|
||||
| Query::ToLocal
|
||||
| Query::ScrollTo
|
||||
| Query::ScrollBy
|
||||
) {
|
||||
vec![T::Number, T::Number]
|
||||
} else {
|
||||
@@ -433,6 +497,8 @@ impl NativeCallable for Sync {
|
||||
("scrollIntoView", Query::ScrollIntoView),
|
||||
("fitView", Query::FitView),
|
||||
("pick3D", Query::Pick3D),
|
||||
("toView", Query::ToView),
|
||||
("toLocal", Query::ToLocal),
|
||||
("parent", Query::Parent),
|
||||
("firstChild", Query::FirstChild),
|
||||
("nextSibling", Query::NextSibling),
|
||||
|
||||
Reference in New Issue
Block a user