fix: mesh pointer (#4)

Fixed so that webview can detect pointers correctly even if it is not the root entity.
This commit is contained in:
elm
2025-08-19 12:45:27 +09:00
committed by GitHub
parent de2fb61d17
commit e42a9beacd
4 changed files with 23 additions and 3 deletions

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
target/ target/
.idea/ .idea/
book/ book/
.DS_Store .DS_Store**/.DS_Store

View File

@@ -1,3 +1,9 @@
## Unreleased
### Bug Fixes
- Fixed so that webview can detect pointers correctly even if it is not the root entity.
## v0.1.0 ## v0.1.0
First release First release

BIN
examples/.DS_Store vendored

Binary file not shown.

View File

@@ -14,7 +14,7 @@ pub struct WebviewPointer<'w, 's, C: Component = Camera3d> {
(&'static GlobalTransform, &'static WebviewSize), (&'static GlobalTransform, &'static WebviewSize),
(With<CefWebviewUri>, Without<Camera>), (With<CefWebviewUri>, Without<Camera>),
>, >,
parents: Query<'w, 's, &'static ChildOf>, parents: Query<'w, 's, (Option<&'static ChildOf>, Has<CefWebviewUri>)>,
} }
impl<C: Component> WebviewPointer<'_, '_, C> { impl<C: Component> WebviewPointer<'_, '_, C> {
@@ -22,7 +22,7 @@ impl<C: Component> WebviewPointer<'_, '_, C> {
where where
P: Clone + Reflect + Debug, P: Clone + Reflect + Debug,
{ {
let webview = self.parents.root_ancestor(trigger.target); let webview = find_webview_entity(trigger.target, &self.parents)?;
let pos = self.pointer_pos(webview, trigger.pointer_location.position)?; let pos = self.pointer_pos(webview, trigger.pointer_location.position)?;
Some((webview, pos)) Some((webview, pos))
} }
@@ -44,6 +44,20 @@ impl<C: Component> WebviewPointer<'_, '_, C> {
} }
} }
fn find_webview_entity(
entity: Entity,
parents: &Query<(Option<&ChildOf>, Has<CefWebviewUri>)>,
) -> Option<Entity> {
let (child_of, has_webview) = parents.get(entity).ok()?;
if has_webview {
return Some(entity);
}
if let Some(parent) = child_of {
return find_webview_entity(parent.0, parents);
}
None
}
fn pointer_to_webview_uv( fn pointer_to_webview_uv(
cursor_pos: Vec2, cursor_pos: Vec2,
camera: &Camera, camera: &Camera,