Skip to content

How to use nsview.layer? #164

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

Open
Tracked by #719
bors-servo opened this issue Feb 1, 2018 · 6 comments
Open
Tracked by #719

How to use nsview.layer? #164

bors-servo opened this issue Feb 1, 2018 · 6 comments

Comments

@bors-servo
Copy link
Contributor

Issue by paulrouget
Friday Mar 17, 2017 at 08:08 GMT
Originally opened as servo/core-graphics-rs#78


I'm trying to animate a Cocoa nsview via its layer. But with no luck. What would it take to make it work?

I'm trying for example to set the opacity of a layer. All the conditions to enable core animation are met.

This code crashes:

let content_view: id = msg_send![nswindow, contentView];
let layer: id = msg_send![content_view, layer];
let transform: CGAffineTransform = msg_send![layer, affineTransform];
msg_send![layer, setAffineTransform:transform];

And this code behaves in a strange way:

let content_view: id = msg_send![nswindow, contentView];
let layer: id = msg_send![content_view, layer];
let opacity: CGFloat = msg_send![layer, opacity];
// opacity is equal to 0.
let opacity: CGFloat = 0.5;
msg_send![layer, setOpacity:opacity];
// view disappear
let opacity: CGFloat = msg_send![layer, opacity];
// opacity is still equal to 0.
@bors-servo
Copy link
Contributor Author

Comment by metajack
Saturday Mar 18, 2017 at 11:59 GMT


cc @pcwalton

@bors-servo
Copy link
Contributor Author

Comment by oluseyi
Wednesday Apr 26, 2017 at 02:55 GMT


@paulrouget Did you call setWantLayer:YES on the NSView? Unlike on iOS, macOS views are not CALayer-backed by default.

@bors-servo
Copy link
Contributor Author

Comment by paulrouget
Wednesday Apr 26, 2017 at 05:11 GMT


Did you call setWantLayer:YES on the NSView? Unlike on iOS, macOS views are not CALayer-backed by default.

Yes.

@bors-servo
Copy link
Contributor Author

Comment by oluseyi
Wednesday Apr 26, 2017 at 10:48 GMT


For the first snippet, any chance you got a stack trace?

For the second snippet, did you call setNeedsDisplay:YES, or displayIfNeeded if you wanted to evaluate attributes in the same runloop?

Sorry if the questions seem obvious, just eliminating the low-hanging fruit.

@bors-servo
Copy link
Contributor Author

Comment by pcwalton
Wednesday Apr 26, 2017 at 14:05 GMT


You might have to do something special to the NSWindow in order to get Core Animation to work. I think Interface Builder does this for you if you use nibs, but if you're setting things up manually there may be something magic you have to invoke.

@bors-servo
Copy link
Contributor Author

Comment by paulrouget
Thursday Apr 27, 2017 at 07:29 GMT


@pcwalton: Interface Builder does this for you if you use nibs

I use nibs.

@oluseyi: For the first snippet, any chance you got a stack trace?
For the second snippet, did you call setNeedsDisplay:YES, or displayIfNeeded if you wanted to evaluate attributes in the same runloop?

I'll try to get a backtrace and try these later.

jrmuizel pushed a commit to jrmuizel/core-foundation-rs that referenced this issue Feb 2, 2018
Make travis compile again.

<!-- 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/164)
<!-- Reviewable:end -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant