use retroglyph_core::grid::{Pos, Rect};
#[allow(clippy::struct_excessive_bools)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Response<Id> {
pub(crate) id: Id,
pub(crate) hovered: bool,
pub(crate) pressed: bool,
pub(crate) released: bool,
pub(crate) clicked: bool,
pub(crate) double_clicked: bool,
pub(crate) held: bool,
pub(crate) dragging: bool,
pub(crate) focused: bool,
pub(crate) gained_focus: bool,
pub(crate) lost_focus: bool,
pub(crate) secondary_clicked: bool,
pub(crate) disabled: bool,
pub(crate) scroll_delta: i32,
pub(crate) pointer_pos: Option<Pos>,
pub(crate) press_origin: Option<Pos>,
pub(crate) drag_delta: Option<(i32, i32)>,
pub(crate) rect: Rect,
}
impl Default for Response<()> {
fn default() -> Self {
Self {
id: (),
hovered: false,
pressed: false,
released: false,
clicked: false,
double_clicked: false,
held: false,
dragging: false,
focused: false,
gained_focus: false,
lost_focus: false,
secondary_clicked: false,
disabled: false,
scroll_delta: 0,
pointer_pos: None,
press_origin: None,
drag_delta: None,
rect: Rect::default(),
}
}
}
impl<Id: Copy> Response<Id> {
#[must_use]
pub const fn id(&self) -> Id {
self.id
}
}
impl<Id> Response<Id> {
#[must_use]
pub const fn hovered(&self) -> bool {
self.hovered
}
#[must_use]
pub const fn pressed(&self) -> bool {
self.pressed
}
#[must_use]
pub const fn released(&self) -> bool {
self.released
}
#[must_use]
pub const fn clicked(&self) -> bool {
self.clicked
}
#[must_use]
pub const fn double_clicked(&self) -> bool {
self.double_clicked
}
#[must_use]
pub const fn held(&self) -> bool {
self.held
}
#[must_use]
pub const fn dragging(&self) -> bool {
self.dragging
}
#[must_use]
pub const fn focused(&self) -> bool {
self.focused
}
#[must_use]
pub const fn gained_focus(&self) -> bool {
self.gained_focus
}
#[must_use]
pub const fn lost_focus(&self) -> bool {
self.lost_focus
}
#[must_use]
pub const fn secondary_clicked(&self) -> bool {
self.secondary_clicked
}
#[must_use]
pub const fn scroll_delta(&self) -> i32 {
self.scroll_delta
}
#[must_use]
pub const fn disabled(&self) -> bool {
self.disabled
}
#[must_use]
pub const fn pointer_pos(&self) -> Option<Pos> {
self.pointer_pos
}
#[must_use]
pub const fn press_origin(&self) -> Option<Pos> {
self.press_origin
}
#[must_use]
pub const fn drag_delta(&self) -> Option<(i32, i32)> {
self.drag_delta
}
#[must_use]
pub const fn rect(&self) -> Rect {
self.rect
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_is_all_falsy() {
let r: Response<()> = Response::default();
assert_eq!(r.id(), ());
assert!(!r.hovered());
assert!(!r.pressed());
assert!(!r.released());
assert!(!r.clicked());
assert!(!r.double_clicked());
assert!(!r.held());
assert!(!r.dragging());
assert!(!r.focused());
assert!(!r.gained_focus());
assert!(!r.lost_focus());
assert!(!r.secondary_clicked());
assert!(!r.disabled());
assert_eq!(r.scroll_delta(), 0);
assert_eq!(r.pointer_pos(), None);
assert_eq!(r.press_origin(), None);
assert_eq!(r.drag_delta(), None);
assert_eq!(r.rect(), Rect::default());
}
}