Implement NSWindowStyleMask as bitflags #160
Conversation
…r and is therefore bitwise-combinable, though it loses type information. Instead of implementing NSWindowMask as a packed-data object with a u64 representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementing std::ops::BitOr for the type.
src/appkit.rs
Outdated
msg_send![self, styleMask] | ||
unsafe fn styleMask(self) -> NSWindowMask { | ||
let styleMask = msg_send![self, styleMask]; | ||
styleMask |
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'm surprised that this works as written. Doesn't this need to call NSWindowMask::from_bits or from_bits_truncate?
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.
from_bits_truncate
would add a nice validity check. I'll add that in.
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.
Done. Also renamed NSWindowMask
to NSWindowStyleMask
to match AppKit.
…nd maps to declared fields. Prefer truncate because macOS may use reserved bits for private purposes, or introduce new values in future versions.
@bors-servo: r+ |
📌 Commit 135fce2 has been approved by |
Implement NSWindowStyleMask as bitflags RE #159 `NSWindowStyleMask`, as an enumeration in Objective-C, degrades to `NSUInteger` and is therefore bitwise-combinable, though it loses type information. Instead of implementing `NSWindowStyleMask` as a packed-data object with a `u64` representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementing `std::ops::BitOr` for the type. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/160) <!-- Reviewable:end -->
💔 Test failed - status-travis |
Example needs to be updated now:
|
Yeah, saw the message from bors-servo. Was at lunch; committing now. Thanks @jdm. |
@bors-servo: r+ |
📌 Commit e773703 has been approved by |
Implement NSWindowStyleMask as bitflags RE #159 `NSWindowStyleMask`, as an enumeration in Objective-C, degrades to `NSUInteger` and is therefore bitwise-combinable, though it loses type information. Instead of implementing `NSWindowStyleMask` as a packed-data object with a `u64` representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementing `std::ops::BitOr` for the type. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/cocoa-rs/160) <!-- Reviewable:end -->
☀️ Test successful - status-travis |
RE #159
NSWindowStyleMask
, as an enumeration in Objective-C, degrades toNSUInteger
and is therefore bitwise-combinable, though it loses type information. Instead of implementingNSWindowStyleMask
as a packed-data object with au64
representational form, we ought to employ bit flags to generate a strong type that remains combinable in the manner Cocoa programmers are accustomed to. Also easier than manually implementingstd::ops::BitOr
for the type.This change is