From 778ae751e74128e33566b1f131d03d047e838a93 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Thu, 29 Feb 2024 02:19:29 +0100 Subject: [PATCH] stuff --- hui/src/input.rs | 25 ++++++++++++++++++++----- hui/src/rectangle.rs | 8 ++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/hui/src/input.rs b/hui/src/input.rs index 43399a3..afbcfb3 100644 --- a/hui/src/input.rs +++ b/hui/src/input.rs @@ -4,6 +4,7 @@ use std::hash::{Hash, Hasher}; use glam::Vec2; use hashbrown::HashMap; use nohash_hasher::BuildNoHashHasher; +use crate::rectangle::Rect; /// Represents a mouse button. /// @@ -81,17 +82,19 @@ pub enum KeyboardKey { } -/// Information about a mouse buttons or a touchscreen input that's continuously held down +/// Information about the state of a mouse button pub(crate) struct ActiveMouseButton { + /// Whether the input is currently active (i.e. the button is currently held down) + pub active: bool, /// The button that initiated the input pub button: MouseButton, - /// Position at which the input was initiated - pub start_position: Vec2, + /// Position at which the input was initiated (last time it was pressed **down**) + pub start_position: Option, } pub(crate) struct MousePointer { pub current_position: Vec2, - pub active_buttons: HashMap>, + pub buttons: HashMap>, } pub(crate) struct TouchFinger { @@ -126,5 +129,17 @@ impl ActiveMouseButton { } pub(crate) struct UiInputState { - pub pointers: Vec, + pointers: Vec, +} + +impl UiInputState { + pub fn new() -> Self { + Self { + pointers: Vec::new(), + } + } + + pub fn query_pointer(&self, area: Rect) -> bool { + todo!() + } } diff --git a/hui/src/rectangle.rs b/hui/src/rectangle.rs index 277e8ba..09848fa 100644 --- a/hui/src/rectangle.rs +++ b/hui/src/rectangle.rs @@ -1,5 +1,13 @@ //! Contains types which represent the sides and corners of a rectangular shape. +use glam::Vec2; + +#[derive(Clone, Copy, Debug, PartialEq, Default)] +pub struct Rect { + pub position: Vec2, + pub size: Vec2, +} + /// Represents 4 sides of a rectangular shape. #[derive(Default, Clone, Copy, PartialEq, Eq, Debug)] pub struct Sides {