sense specific buttons

This commit is contained in:
2025-09-15 22:22:52 -04:00
parent 21aa2b3501
commit b48acccb8d
8 changed files with 167 additions and 107 deletions

View File

@@ -1,52 +0,0 @@
macro_rules! bitflags {
($enum:ident, $struct:ident, $mod:ident {$($val:expr; $ename:ident, $sname:ident,)*}) => {
#[repr(u32)]
#[derive(Clone, Copy, PartialEq)]
pub enum $enum {
$($ename = $val,)*
}
#[derive(Clone, Copy, PartialEq)]
pub struct $struct(u32);
#[allow(non_upper_case_globals)]
impl $struct {
$(pub const $sname: Self = Self($enum::$ename as u32);)*
pub fn iter(&self) -> impl Iterator<Item = $enum> {
$crate::util::Biterator::new(self.0).map(|v| unsafe {std::mem::transmute(v)})
}
}
impl std::ops::BitOr for $struct {
type Output = Self;
fn bitor(self, rhs: $struct) -> Self {
Self(self.0 | rhs.0)
}
}
pub mod $mod {
use super::*;
$(pub const $sname: $struct = $struct::$sname;)*
}
};
}
pub(crate) use bitflags;
pub struct Biterator(u32);
impl Iterator for Biterator {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
if self.0 == 0 {
return None;
}
let val = 1 << self.0.trailing_zeros();
self.0 &= !val;
Some(val)
}
}
impl Biterator {
pub fn new(val: u32) -> Self {
Self(val)
}
}

View File

@@ -1,11 +1,9 @@
mod bitflags;
mod borrow;
mod id;
mod idvec;
mod math;
mod refcount;
pub(crate) use bitflags::*;
pub(crate) use borrow::*;
pub(crate) use id::*;
pub(crate) use idvec::*;