pub struct Pointer { /* private fields */ }Expand description
Manages mouse/pointer interactions for widgets.
Pointer tracks clickable areas for widgets and dispatches mouse events
(down, drag, up) to the appropriate handlers. It maintains a z-order for
hit testing, where later-registered widgets appear on top.
§Example
let mut pointer = Pointer::new();
pointer.set(WidgetId("button"), Area::new(10, 5, 20, 3));
pointer.on_click(WidgetId("button"), |world, area, x, y| {
// Handle click at (x, y) within the button area
});Implementations§
Source§impl Pointer
impl Pointer
pub fn new() -> Self
Sourcepub fn set<W: Into<Area>>(&mut self, id: WidgetId, area: W)
pub fn set<W: Into<Area>>(&mut self, id: WidgetId, area: W)
Sets the clickable area for a widget.
Sourcepub fn on_click<F>(&mut self, id: WidgetId, handler: F)
pub fn on_click<F>(&mut self, id: WidgetId, handler: F)
Registers a click (mouse down) handler for a widget.
Sourcepub fn on_down<F>(&mut self, id: WidgetId, handler: F)
pub fn on_down<F>(&mut self, id: WidgetId, handler: F)
Registers a mouse down handler for a widget.
Sourcepub fn on_drag<F>(&mut self, id: WidgetId, handler: F)
pub fn on_drag<F>(&mut self, id: WidgetId, handler: F)
Registers a drag handler for a widget. This is called when mouse moves while button is held down.
Sourcepub fn on_up<F>(&mut self, id: WidgetId, handler: F)
pub fn on_up<F>(&mut self, id: WidgetId, handler: F)
Registers a mouse up handler for a widget.
Sourcepub fn get_handler(
&self,
id: WidgetId,
) -> Option<Arc<dyn Fn(&mut World, Area, u16, u16) + Send + Sync>>
pub fn get_handler( &self, id: WidgetId, ) -> Option<Arc<dyn Fn(&mut World, Area, u16, u16) + Send + Sync>>
Returns the click/down handler for a widget if it exists.
Sourcepub fn hit_test(&self, x: u16, y: u16) -> Option<WidgetId>
pub fn hit_test(&self, x: u16, y: u16) -> Option<WidgetId>
Performs a hit test to find which widget is at the given coordinates. Returns the topmost widget (last in order) that contains the point.
Sourcepub fn hit_test_handler(
&self,
x: u16,
y: u16,
) -> Option<(WidgetId, Arc<dyn Fn(&mut World, Area, u16, u16) + Send + Sync>)>
pub fn hit_test_handler( &self, x: u16, y: u16, ) -> Option<(WidgetId, Arc<dyn Fn(&mut World, Area, u16, u16) + Send + Sync>)>
Performs a hit test and returns the handler if found.
Sourcepub fn set_active(&mut self, id: Option<WidgetId>)
pub fn set_active(&mut self, id: Option<WidgetId>)
Sets the active widget (the one that received mouse down).
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Pointer
impl !UnwindSafe for Pointer
impl Forget for Pointer
impl Freeze for Pointer
impl Send for Pointer
impl Sync for Pointer
impl Unpin for Pointer
impl UnsafeUnpin for Pointer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more