Skip to content
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

chore: add simple NSControl class #272

Conversation

@acheronfail
Copy link
Contributor

acheronfail commented Nov 8, 2018

I needed to use [button setEnabled] for an NSButton, so I added some of NSControl's basic functionality.

Example usage:

use cocoa::foundation::NSRect;
use cocoa::appkit::{NSButton, NSControl, NSView};

// Parent view
let view = NSView::alloc(nil)
    .initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)));

// Add button to view
let button = NSButton::alloc(nil)
    .initWithFrame_(NSRect::new(NSPoint::new(20., 20.), NSSize::new(150., 50.)));
NSView::addSubview_(view, button);

// Prints "1" (button enabled)
println!("{:?}", NSControl::isEnabled_(button));

// Disable the button
NSControl::setEnabled_(button, NO);

// Prints "0" (button disabled)
println!("{:?}", NSControl::isEnabled_(button));

This change is Reviewable

@jdm
Copy link
Member

jdm commented Nov 8, 2018

@bors-servo
Copy link
Contributor

bors-servo commented Nov 8, 2018

📌 Commit 8a72e96 has been approved by jdm

@bors-servo
Copy link
Contributor

bors-servo commented Nov 8, 2018

Testing commit 8a72e96 with merge 9f23b51...

bors-servo added a commit that referenced this pull request Nov 8, 2018
…button, r=jdm

chore: add simple NSControl class

I needed to use `[button setEnabled]` for an `NSButton`, so I added some of `NSControl`'s basic functionality.

Example usage:

```rust
use cocoa::foundation::NSRect;
use cocoa::appkit::{NSButton, NSControl, NSView};

// Parent view
let view = NSView::alloc(nil)
    .initWithFrame_(NSRect::new(NSPoint::new(0., 0.), NSSize::new(200., 200.)));

// Add button to view
let button = NSButton::alloc(nil)
    .initWithFrame_(NSRect::new(NSPoint::new(20., 20.), NSSize::new(150., 50.)));
NSView::addSubview_(view, button);

// Prints "1" (button enabled)
println!("{:?}", NSControl::isEnabled_(button));

// Disable the button
NSControl::setEnabled_(button, NO);

// Prints "0" (button disabled)
println!("{:?}", NSControl::isEnabled_(button));
```

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/core-foundation-rs/272)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

bors-servo commented Nov 8, 2018

☀️ Test successful - status-travis
Approved by: jdm
Pushing 9f23b51 to master...

@bors-servo bors-servo merged commit 8a72e96 into servo:master Nov 8, 2018
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@acheronfail acheronfail deleted the acheronfail:chore/add-isEnabled-setEnabled-to-nsbutton branch Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.