Skip to main content

Clickable

Trait Clickable 

Source
pub trait Clickable {
    type ClickAction: Clone;

    // Required method
    fn click_regions(&self) -> &[ClickRegion<Self::ClickAction>];

    // Provided method
    fn handle_click(&self, col: u16, row: u16) -> Option<Self::ClickAction> { ... }
}
Expand description

Trait for components that respond to mouse clicks.

Implement this trait to make a component clickable with automatic hit-testing based on registered click regions.

Required Associated Types§

Source

type ClickAction: Clone

The type of action that a click produces.

Required Methods§

Source

fn click_regions(&self) -> &[ClickRegion<Self::ClickAction>]

Returns all click regions for this component.

Called after rendering to get the active regions.

Provided Methods§

Source

fn handle_click(&self, col: u16, row: u16) -> Option<Self::ClickAction>

Handle a click at the given position.

Returns Some(action) if the click was within a region, None otherwise.

Default implementation checks all regions and returns the first match.

Implementors§