-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add passthrough code #714
base: main
Are you sure you want to change the base?
Add passthrough code #714
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,11 @@ | |
use std::collections::{HashMap, VecDeque}; | ||
|
||
use accesskit::{ActionRequest, TreeUpdate}; | ||
use dpi::PhysicalPosition; | ||
use parley::fontique::{self, Collection, CollectionOptions}; | ||
use parley::{FontContext, LayoutContext}; | ||
use tracing::{info_span, warn}; | ||
use vello::kurbo::{self, Rect}; | ||
use vello::kurbo::{self, Rect, Vec2}; | ||
use vello::Scene; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
|
@@ -325,6 +326,28 @@ impl RenderRoot { | |
self.cursor_icon | ||
} | ||
|
||
pub fn is_passthrough(&self, pos: PhysicalPosition<f64>) -> bool { | ||
let pos = Vec2::new(pos.x, pos.y) / self.scale_factor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be nice if we were just using |
||
|
||
let mut target_id = self | ||
.get_root_widget() | ||
.find_widget_at_pos(pos.to_point()) | ||
.map(|widget| widget.id()); | ||
|
||
while let Some(widget_id) = target_id { | ||
let parent_id = self.widget_arena.parent_of(widget_id); | ||
let widget = self.widget_arena.get_widget(widget_id); | ||
|
||
if !widget.item.is_passthrough() { | ||
return false; | ||
} | ||
|
||
target_id = parent_id; | ||
} | ||
|
||
true | ||
} | ||
|
||
// --- MARK: ACCESS WIDGETS--- | ||
/// Get a [`WidgetRef`] to the root widget. | ||
pub fn get_root_widget(&self) -> WidgetRef<dyn Widget> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,13 @@ pub trait Widget: AsAny { | |
false | ||
} | ||
|
||
/// Whether this widgets obstructs pointer events for something behind the window. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd add a pointer back to the |
||
/// | ||
/// Somewhat experimental. | ||
fn is_passthrough(&self) -> bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the semantic difference between this and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There's probably a way to design these features to be more orthogonal and principled, but this is meant to be a quick-and-easy fix. |
||
false | ||
} | ||
|
||
// TODO - Write a generic default implementation once | ||
// `const std::any::type_name` is stable. | ||
// See https://github.com/rust-lang/rust/issues/63084 | ||
|
@@ -467,6 +474,10 @@ impl Widget for Box<dyn Widget> { | |
self.deref().accepts_text_input() | ||
} | ||
|
||
fn is_passthrough(&self) -> bool { | ||
self.deref().is_passthrough() | ||
} | ||
|
||
fn make_trace_span(&self) -> Span { | ||
self.deref().make_trace_span() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs a doc comment.