pub struct MousePosition {
pub column: i16,
pub row: i16,
pub space: CoordSpace,
}Expand description
A mouse cursor position with an explicit coordinate space tag.
Always CoordSpace::Screen for dispatched events. The space field
exists to prevent accidental mixing of coordinate systems — a compile-time
reminder that all positions are in absolute screen coordinates and
should never be mutated during dispatch.
Fields§
§column: i16Column in cells (signed — no u16 underflow on out-of-bounds drag).
row: i16Row in cells (signed — no u16 underflow on out-of-bounds drag).
space: CoordSpaceCoordinate space tag. Always Screen for dispatched events.
Implementations§
Source§impl MousePosition
impl MousePosition
Sourcepub fn is_inside(&self, area: LayoutRect) -> bool
pub fn is_inside(&self, area: LayoutRect) -> bool
Returns true if this position lies within area in screen coordinates.
This is the unified replacement for ad-hoc rect_contains() checks
scattered across component handle_events methods. Because the
hitbox registry already guarantees the component was the hit target,
this is used only for sub-widget coordinate gallity checks.
Sourcepub fn to_local(&self, area: LayoutRect) -> Option<(u16, u16)>
pub fn to_local(&self, area: LayoutRect) -> Option<(u16, u16)>
Convert this screen-space position to local (area-relative) coordinates.
Returns Some((col, row)) if the position is inside area, or None
if outside. This replaces the pattern mouse.column - last_area.x with
a single checked operation.
Unlike bare subtraction, this does not underflow or produce nonsensical values for out-of-bounds positions.
Trait Implementations§
Source§impl Clone for MousePosition
impl Clone for MousePosition
Source§fn clone(&self) -> MousePosition
fn clone(&self) -> MousePosition
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more