Skip to main content

Pointer

Struct Pointer 

Source
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

Source

pub fn new() -> Self

Source

pub fn set<W: Into<Area>>(&mut self, id: WidgetId, area: W)

Sets the clickable area for a widget.

Source

pub fn get(&self, id: WidgetId) -> Option<&Area>

Returns the area for a widget if it exists.

Source

pub fn on_click<F>(&mut self, id: WidgetId, handler: F)
where F: Fn(&mut World, Area, u16, u16) + Send + Sync + 'static,

Registers a click (mouse down) handler for a widget.

Source

pub fn on_down<F>(&mut self, id: WidgetId, handler: F)
where F: Fn(&mut World, Area, u16, u16) + Send + Sync + 'static,

Registers a mouse down handler for a widget.

Source

pub fn on_drag<F>(&mut self, id: WidgetId, handler: F)
where F: Fn(&mut World, Area, u16, u16) + Send + Sync + 'static,

Registers a drag handler for a widget. This is called when mouse moves while button is held down.

Source

pub fn on_up<F>(&mut self, id: WidgetId, handler: F)
where F: Fn(&mut World, Area, u16, u16) + Send + Sync + 'static,

Registers a mouse up handler for a widget.

Source

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.

Source

pub fn remove(&mut self, id: WidgetId)

Removes a widget’s area and all handlers.

Source

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.

Source

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.

Source

pub fn set_active(&mut self, id: Option<WidgetId>)

Sets the active widget (the one that received mouse down).

Source

pub fn active(&self) -> Option<WidgetId>

Returns the currently active widget.

Source

pub fn get_handler_for( &self, id: WidgetId, kind: MouseEventKind, ) -> Option<Arc<dyn Fn(&mut World, Area, u16, u16) + Send + Sync>>

Gets the handler for a specific event kind and widget.

Trait Implementations§

Source§

impl Default for Pointer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.