Skip to main content

Mouse

Struct Mouse 

Source
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

Source

pub const fn new(kind: MouseKind, column: u16, row: u16) -> Mouse

Source

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");
Source

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));
Source

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.

Source

pub fn is_click(&self) -> bool

A press of the left button: the start of a click.

Trait Implementations§

Source§

impl Clone for Mouse

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Mouse

Source§

impl Debug for Mouse

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Mouse

Source§

impl Hash for Mouse

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for Mouse

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.