ryanmcgrath / cacao

Rust bindings for AppKit (macOS) and UIKit (iOS/tvOS). Experimental, but working!
MIT License
1.8k stars 65 forks source link

iOS support for label, text input, font, more tests #55

Closed simlay closed 12 months ago

simlay commented 1 year ago

I was on vacation last week and did this for fun so it's a bit disorganized. I started out doing unit tests and then got off track. This PR should probably be broken up into a few things.

changes

Tests on:

Protip:

There's not a great way to develop for mutually exclusive feature flags but what I have found is that if we structure things like:

#[cfg(feature = "appkit")]
mod appkit;

#[cfg(feature = "appkit")]
use appkit::{register_view_class, register_view_class_with_delegate};

#[cfg(feature = "uikit")]
mod uikit;

#[cfg(all(feature = "uikit", not(feature = "appkit")))]
use uikit::{register_view_class, register_view_class_with_delegate};

In an editor config (I use vim with an LSP client and rust-analyzer) enable both of those feature flags you can reasonably navigate the codebase. The "jump to definitionofregister_view_classis this case would go toappkitdefinition but to get to theuikitdefinition, you have to jump to definition of themod uikitand then theregister_view_class`.

Here's the .vim/settings.json I used in this PR (I think this is either identically or similar for most other setups):

{
    "rust-analyzer": {
        "cargo": {
            "target": "aarch64-apple-ios-sim",
            "features": ["uikit", "autolayout","appkit", "cloudkit", "user-notifications", "quicklook", "webview"],
            "noDefaultFeatures": true
        },
        "initialization_options": {
            "cargo": {
                "buildScripts": {
                    "enable": true
                }
            },
            "completion": { "autoimport": {"enable": true } },
            "procMacro": {
                "enable": true
            }
        }
    }
}
ryanmcgrath commented 1 year ago

This is so cool! Really excited to see the iOS side coming together - hella appreciated as always. Will look at merging this soon, sat down to look at the objc2 stuff today but got pulled into other issues work-related. :(

Re: the appkit/uikit breakdown, one thing I did in the view module was this:

https://github.com/ryanmcgrath/cacao/blob/f84a9dfaf6621cab82cf095ca10102d4648cdb78/src/view/mod.rs#L67-L69

Curious for your thoughts on it - is it better/worse/irrelevant given your point regarding feature flags above?

simlay commented 1 year ago

Will look at merging this soon, sat down to look at the objc2 stuff today but got pulled into other issues work-related. :(

No pressure! I was tempted to wait on the objc2 stuff but got excited doing this.

Re: the appkit/uikit breakdown, one thing I did in the view module was this:

https://github.com/ryanmcgrath/cacao/blob/f84a9dfaf6621cab82cf095ca10102d4648cdb78/src/view/mod.rs#L67-L69

Curious for your thoughts on it - is it better/worse/irrelevant given your point regarding feature flags above?

This is actually one of the few places I noticed it and found it a little difficult. I might submit a separate PR. I doubt there's any clippy/fmt-esk tool to help with this.

ryanmcgrath commented 1 year ago

@simlay is this okay to be merged? Looking to cut a 3.3-beta1 or something to crates.io and figured I should tie off some of the older PRs where I can.

simlay commented 1 year ago

@simlay is this okay to be merged? Looking to cut a 3.3-beta1 or something to crates.io and figured I should tie off some of the older PRs where I can.

Yeah. I actually updated this branch out of the blue 3 weeks ago. It looks like there might be more merge conflicts. Do you wanna deal with those or shall I?

ryanmcgrath commented 1 year ago

Hmmm, I think it's actually just a formatting pass that's needed... otherwise this stuff could fit into a 0.4.0-beta2.

simlay commented 1 year ago

Hmmm, I think it's actually just a formatting pass that's needed... otherwise this stuff could fit into a 0.4.0-beta2.

Hopefully I just fixed that. We'll see.

ryanmcgrath commented 1 year ago

Aye, looks like it's all smooth now - shall I merge?

SmartBoy84 commented 1 year ago

Merge! (pretty please)

ryanmcgrath commented 12 months ago

Merged. :)

I'll likely cut a 0.4.2 after one or two more PRs get in, or next week if they take longer.