-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Use bitfield instead of bools in Response
and Sense
#5556
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.
Look great - thank you!
Response
and Sense
Preview available at https://egui-pr-preview.github.io/pr/5556-bitflags |
Thanks for the review! I will address your comments shortly. I see one CI job is failing, but it does not look like something I touched? I can fix it, but should I? EDIT NVM, I see it's already corrected in master. Will rebase. |
a69fa29
to
507c3e9
Compare
&& memory.has_focus(id) | ||
&& (input.key_pressed(Key::Space) || input.key_pressed(Key::Enter)) | ||
{ | ||
// Space/enter works like a primary click for e.g. selected buttons | ||
res.fake_primary_click = true; | ||
res.flags.set(Flags::FAKE_PRIMARY_CLICKED, true); |
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.
Nit: these could be shorter by using +=
or |=
res.flags.set(Flags::FAKE_PRIMARY_CLICKED, true); | |
res.flags += Flags::FAKE_PRIMARY_CLICKED; |
Closes #3862.
Factoring the
bool
members ofResponse
into a bitfield, the size ofResponse
is now 96 bytes (down from 104).I gave
Sense
the same treatment, however this has no effects onResponse
due to padding. I've decided not to pursuePointerState
, as it is quite large (many members that are sized and aligned to multiples of 8 bytes), so I don't expect any noticeable benefit from making handful ofbool
s slightly leaner.In any case, the changes to
Sense
are already quite a bit more intrusive than those toResponse
.The previous implementation overloaded the names of the attributes
click
anddrag
with similarly named methods that constructSense
with the corresponding flag set. Now, that the attributes can no longer be accessed directly, I had to introduce methods with new names (senses_click()
,senses_drag()
andis_focusable()
). I don't think this is the cleanest solution: the old methods are essentially redundant now that the named constants likeSense::CLICK
exist. I did however not want to needlessly break backwards compatibility.I am happy to revert it (or go further 🙂) if there are concerns.