libnotcurses_sys/input/
mice_events.rs

1//!
2
3/// A bitmask of mice input events.
4///
5/// # Default
6/// *[`NcMiceEvents::None`]
7///
8/// # Flags
9/// - [`Move`][NcMiceEvents::Move]
10/// - [`Button`][NcMiceEvents::Button]
11/// - [`Drag`][NcMiceEvents::Drag]
12/// - [`None`][NcMiceEvents::None]
13/// - [`All`][NcMiceEvents::All]
14///
15/// # Used by
16/// - [`Nc.mice_disable`][crate::Nc#method.mice_disable]
17/// - [`Nc.mice_enable`][crate::Nc#method.mice_enable]
18#[repr(transparent)]
19#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub struct NcMiceEvents(pub c_api::NcMiceEvents_u32);
21
22/// # Flags
23impl NcMiceEvents {
24    /// Disables all mice events.
25    pub const None: NcMiceEvents = Self(c_api::NCMICE_NO_EVENTS);
26
27    /// Enables mice move events.
28    pub const Move: NcMiceEvents = Self(c_api::NCMICE_MOVE_EVENTS);
29
30    /// Enables mice button events.
31    pub const Button: NcMiceEvents = Self(c_api::NCMICE_BUTTON_EVENTS);
32
33    /// Enables mice drag events.
34    pub const Drag: NcMiceEvents = Self(c_api::NCMICE_DRAG_EVENTS);
35
36    /// Enables all mice tracking events.
37    pub const All: NcMiceEvents = Self(c_api::NCMICE_ALL_EVENTS);
38}
39
40/// # Methods
41impl NcMiceEvents {
42    /// Returns a new `NcMiceEvents`.
43    pub fn new(value: c_api::NcMiceEvents_u32) -> Self {
44        Self(value)
45    }
46
47    /// Returns true if the current mice events has `other` included.
48    pub fn has(&self, other: NcMiceEvents) -> bool {
49        (self.0 & other.0) == other.0
50    }
51
52    /// Adds `other` to the current mice events.
53    pub fn add(&mut self, other: NcMiceEvents) {
54        self.0 |= other.0
55    }
56}
57
58mod core_impls {
59    use super::{c_api::NcMiceEvents_u32, NcMiceEvents};
60
61    impl Default for NcMiceEvents {
62        fn default() -> Self {
63            Self::None
64        }
65    }
66    crate::from_primitive![NcMiceEvents, NcMiceEvents_u32];
67    crate::unit_impl_from![NcMiceEvents, NcMiceEvents_u32];
68    crate::unit_impl_ops![bitwise; NcMiceEvents, NcMiceEvents_u32];
69    crate::unit_impl_fmt![bases+display; NcMiceEvents];
70}
71
72pub(crate) mod c_api {
73    use crate::c_api::ffi;
74
75    /// A bitmask for mice input events.
76    ///
77    /// It's recommended to use [`NcMiceEvents`][crate::NcMiceEvents] instead.
78    ///
79    /// # Associated `c_api` constants
80    /// - [`NCMICE_NO_EVENTS`]
81    /// - [`NCMICE_MOVE_EVENTS`]
82    /// - [`NCMICE_BUTTON_EVENTS`]
83    /// - [`NCMICE_DRAG_EVENTS`]
84    /// - [`NCMICE_ALL_EVENTS`]
85    pub type NcMiceEvents_u32 = u32;
86
87    /// [`NcMiceEvents_u32`] flag that disables all mice events.
88    pub const NCMICE_NO_EVENTS: NcMiceEvents_u32 = ffi::NCMICE_NO_EVENTS;
89
90    /// [`NcMiceEvents_u32`] flag that enables mice *move* events
91    pub const NCMICE_MOVE_EVENTS: NcMiceEvents_u32 = ffi::NCMICE_MOVE_EVENT;
92
93    /// [`NcMiceEvents_u32`] flag that enables mice *button** events
94    pub const NCMICE_BUTTON_EVENTS: NcMiceEvents_u32 = ffi::NCMICE_BUTTON_EVENT;
95
96    /// [`NcMiceEvents_u32`] flag that enables mice *drag* events
97    pub const NCMICE_DRAG_EVENTS: NcMiceEvents_u32 = ffi::NCMICE_DRAG_EVENT;
98
99    /// [`NcMiceEvents_u32`] flag that enables all mice events.
100    pub const NCMICE_ALL_EVENTS: NcMiceEvents_u32 = ffi::NCMICE_ALL_EVENTS;
101}