Skip to content

Add .capture() on ElementBuilder #61

@TheRedDeveloper

Description

@TheRedDeveloper

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().

Metadata

Metadata

Assignees

No one assigned

    Labels

    approvedA feature that has been approvedfeatNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions