Summary
Add a .capture() method to ElementBuilder that captures the pointer, preventing it from propagating to parent elements.
Motivation
Currently, when an element is pressed, all parent elements in the hierarchy also receive on_press and on_release callbacks. This might be bad for a button inside a larger clickable area.
Currently, you make such elements .floating(), but then elements can't size around them. While the workaround of checking pointer_over_ids().last() == Some(id) exists, a dedicated .capture() method would be cleaner.
Origin: #55
Proposed API
// Capture the pointer, preventing it from propagating to parent elements
pub fn capture(mut self) -> Self {
self.pointer_capture_mode = PointerCaptureMode::Capture;
self
}
Behavior
on_press and on_release callbacks still fire on elements with .capture() and its children.
on_press and on_release callbacks don't fire on elements under an element with .capture().
pointer_over_ids() still includes the element with .capture() and its children.
pointer_over_ids() doesn't include elements under an element with .capture().
- Floating elements with
PointerCaptureMode::Capture continue to capture the pointer.
.capture().floating(|f| f.passthrough()) still captures the pointer.
- The pointer still propagates to parent elements unless the element has
.capture().
Summary
Add a
.capture()method toElementBuilderthat captures the pointer, preventing it from propagating to parent elements.Motivation
Currently, when an element is pressed, all parent elements in the hierarchy also receive
on_pressandon_releasecallbacks. This might be bad for a button inside a larger clickable area.Currently, you make such elements
.floating(), but then elements can't size around them. While the workaround of checkingpointer_over_ids().last() == Some(id)exists, a dedicated.capture()method would be cleaner.Origin: #55
Proposed API
Behavior
on_pressandon_releasecallbacks still fire on elements with.capture()and its children.on_pressandon_releasecallbacks don't fire on elements under an element with.capture().pointer_over_ids()still includes the element with.capture()and its children.pointer_over_ids()doesn't include elements under an element with.capture().PointerCaptureMode::Capturecontinue to capture the pointer..capture().floating(|f| f.passthrough())still captures the pointer..capture().