-
Notifications
You must be signed in to change notification settings - Fork 126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
masonry: More efficient set of PointerButtons. #334
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some suggestions for added utilities, and a docs improvement.
masonry/src/event.rs
Outdated
|
||
impl std::fmt::Debug for PointerButtons { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
write!(f, "PointerButtons({:05b})", self.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we display this in full? I.e. Primary | Secondary | ...
We can maybe implement std::fmt::Binary
to use this display?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also linebender/vello#416. I should implement Binary
for DebugLayers
, I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done now as well.
@@ -50,6 +50,84 @@ pub enum PointerButton { | |||
Other, | |||
} | |||
|
|||
/// A set of [`PointerButton`]s. | |||
#[derive(PartialEq, Eq, Clone, Copy, Default)] | |||
pub struct PointerButtons(u8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we have the same utils as from bitflags (such as |
, etc.)
I know we don't want to have different public names for these versions of the values (which is right), so we can't really use bitflags directly.
In theory, I guess we could make PointerButton | PointerButton
yield PointerButtons
, but I think that's too cute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We barely use PointerButtons
right now (only on the PointerState
).
If I did this, I'd want to move it to a separate file as it would start to grow too large to just have it in event.rs
... logically, we could do masonry/src/event/pointer.rs
and then pub use
the stuff from it into masonry::event
. It would be easiest then if we left src/event.rs
rather than renaming it to src/event/mod.rs
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also starts to get closer to where I'd rather have a new crate called input-types
(name not taken yet) or something and go all out there since this isn't specific to Masonry (and I have another version of code like this in my own codebases...)
@@ -50,6 +50,84 @@ pub enum PointerButton { | |||
Other, | |||
} | |||
|
|||
/// A set of [`PointerButton`]s. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should point to the web spec for their equivalent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe! There's some interesting differences between what we do for button / buttons and what the mouse event and pointer events specs say.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think we should aim to move more towards pointer events and a cleaner model over time.)
a58afd2
to
1351e6a
Compare
PointerButton::Auxiliary => 0b100, | ||
PointerButton::X1 => 0b1000, | ||
PointerButton::X2 => 0b10000, | ||
// TODO: When we properly do `Other`, this changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have any ideas about how this might change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't.
masonry/src/event.rs
Outdated
|
||
/// Returns `true` if all the `buttons` are in the set. | ||
#[inline] | ||
pub fn is_superset(self, buttons: PointerButtons) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bitflags
uses contains
for this method. In linebender/vello#416, I renamed the same method to contains
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already a contains
for a single button ... I'll rename this to contains_all
for now unless you have another suggestion to deal with both.
masonry/src/event.rs
Outdated
|
||
impl std::fmt::Debug for PointerButtons { | ||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
write!(f, "PointerButtons({:05b})", self.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See also linebender/vello#416. I should implement Binary
for DebugLayers
, I guess.
This brings code over from glazier for a set of PointerButtons that just uses a single value and bit flags rather than a `HashSet`.
1351e6a
to
b9d37d9
Compare
This is done now, I think ... I didn't add tests, but probably will in the future. But right now, this code is barely even used! (But definitely should be used more.) |
This brings code over from glazier for a set of PointerButtons that just uses a single value and bit flags rather than a
HashSet
.