pub struct Mouse {
pub kind: MouseKind,
pub column: u16,
pub row: u16,
pub modifiers: Modifiers,
pub pixel: Option<Subcell>,
}Expand description
A mouse event, at a column and row (0-based). The event loop reports them to a component relative to the top left of its own view (#476), so row 0 is the view’s first line wherever the view is on screen.
Fields§
§kind: MouseKind§column: u16§row: u16§modifiers: Modifiers§pixel: Option<Subcell>Where in its cell the pointer was, from a terminal that reports the
mouse in pixels (SGR-Pixels, mode 1016; #819); None from one that
reports cells. It is relative to the cell, not the screen, so it
stays right however the column and row are moved into a view’s or
a node’s own coordinates. precise reads it.
Implementations§
Source§impl Mouse
impl Mouse
pub const fn new(kind: MouseKind, column: u16, row: u16) -> Mouse
Sourcepub fn from_pixels(
kind: MouseKind,
x: u32,
y: u32,
cell: (u16, u16),
) -> Option<Mouse>
pub fn from_pixels( kind: MouseKind, x: u32, y: u32, cell: (u16, u16), ) -> Option<Mouse>
A mouse event a terminal reported in pixels (SGR-Pixels, mode
1016): x and y from the screen’s top left, 0-based, in cells of
cell pixels (width, height). None for a cell size of 0.
use rich_interact::{Mouse, MouseKind, Button, Subcell};
// 10 by 20 pixel cells: pixel (25, 47) is in column 2, row 2.
let mouse = Mouse::from_pixels(MouseKind::Down(Button::Left), 25, 47, (10, 20)).unwrap();
assert_eq!((mouse.column, mouse.row), (2, 2));
assert_eq!(mouse.pixel, Some(Subcell { x: 5, y: 7, width: 10, height: 20 }));
let (column, row) = mouse.precise();
assert_eq!(format!("{column:.2} {row:.2}"), "2.50 2.35");Sourcepub fn precise(&self) -> (f32, f32)
pub fn precise(&self) -> (f32, f32)
Where the pointer was, in fractional cells (column, row) of the
same coordinates as column and row:
to the pixel from a pixel-precise terminal, else the cell’s centre
(column + 0.5, row + 0.5).
use rich_interact::{Mouse, MouseKind};
assert_eq!(Mouse::new(MouseKind::Moved, 3, 1).precise(), (3.5, 1.5));Sourcepub fn reread_as_pixels(self, cell: (u16, u16)) -> Option<Mouse>
pub fn reread_as_pixels(self, cell: (u16, u16)) -> Option<Mouse>
The same event read as a pixel report: a terminal with mode 1016 on
sends pixels where the column and row are, and a library that
parses SGR mouse reports (crossterm, termion, termwiz) reads them
as cells. None for a cell size of 0.
Trait Implementations§
impl Copy for Mouse
impl Eq for Mouse
impl StructuralPartialEq for Mouse
Auto Trait Implementations§
impl Freeze for Mouse
impl RefUnwindSafe for Mouse
impl Send for Mouse
impl Sync for Mouse
impl Unpin for Mouse
impl UnsafeUnpin for Mouse
impl UnwindSafe for Mouse
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.