-
Notifications
You must be signed in to change notification settings - Fork 232
Higher-level interface to create delegates #205
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
Comments
Neither |
Did you mean to file that on the |
True, this is not about Core Foundation, but it is about Cocoa, which is a part of this crate. This crate defines |
Oh I see. |
Any update ? I was also using setDelegate and didn't find any other way than the one mentionned by @vbo , may I create a pull request to implement a more high level inteface ? |
A higher level interface sounds like a useful improvement, yes. |
I tried something in #314 |
delegate! macro, a higher-level way to create Cocoa delegates (e.g. NSWindowDelegate) As @vbo mentioned in #205 the only way to create cocoa delegates such as NSWindowDelegate is to use the objc crate and it's a bit hard. I thought a macro for this would be useful. ## Example with NSWindowDelegate Without macro : ```rust let mut decl = ClassDecl::new("MyWindowDelegate", class!(NSObject)).unwrap(); decl.add_ivar::<id>("window"); decl.add_method(sel!(windowWillEnterFullScreen:), on_enter_fullscreen as extern fn(&Object, Sel, id)); let cl = decl.register(); let delegate: id = msg_send![cl, alloc]; (*delegate).set_ivar("window", window); window.setDelegate_(delegate); ``` With macro : ```rust window.setDelegate_(delegate!("MyWindowDelegate", { window: id = window, (windowWillEnterFullScreen:) => on_enter_fullscreen as extern fn(&Object, Sel, id) })); ``` <!-- 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/314) <!-- Reviewable:end -->
It seems currently the only way to create e.g. an NSWindowDelegate is through
objc::declare::ClassDecl
interface:Should this crate expose
trait NSWindowDelegate
and make the creation of such delegate more type-safe?The text was updated successfully, but these errors were encountered: