ryanmcgrath / cacao

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

Allow using frame-based layout #4

Closed MerlinDE closed 3 years ago

MerlinDE commented 3 years ago

Added set_frame() and set_translates_autoresizing_mask_into_constraints() to enable using Cacao with applications that use frame-based UI construction as per conversation with Ryan.

Also added NSPoint, NSSize and NSRect types to foundation.

ryanmcgrath commented 3 years ago

Appreciate you PR'ing this! I haven't had the time to do it on my side yet, as you can see...

One thing I'm curious about: NS(Point|Size|Rect) are so interchangeable with their CG counterpoints, and truth be told I don't think I've ever bothered to use an NSRect in any of my codebases... is there any reason we couldn't just use CG variants throughout, and map over them in the method that accepts them with something like Into<crate::geometry::Rect>? Am I missing anything critical?

I'd love to hear input from others. My personal take on it is that it's worth doing, since it just reduces clutter/imports/etc.

MerlinDE commented 3 years ago

Agree. Intoshould do.

ryanmcgrath commented 3 years ago

I'll take a crack at rolling this into my next push.

ryanmcgrath commented 3 years ago

Heya, so for this PR - I wound up just doing the implementation on the Layout trait in my changes I pushed tonight. This results in every control getting these methods, as the implementation is universal enough to fit for a trait - I think it should give the same results for you, but would love a once-over. Let me know if I messed anything up?

MerlinDE commented 3 years ago

In src/input/macos.rs you're returning bool instead of BOOL on decl.add_method for text_should_begin_editing and text_should_end_editing, which already ends the compilation with a non-primitive cast for me.

I'll further check from here and come back with results over the weekend.

ryanmcgrath commented 3 years ago

Aaaahh, yeah... I take it you're building on an Intel machine? BOOL is different depending on M1 vs Intel, I've found - probably why it built for me and not for you. I just pushed a change for that.

Reaaaally need to set up some sort of CI for this, even if it's Intel only...

MerlinDE commented 3 years ago

Interesting. And good to know for my future mistakes. ;)

I've pulled your changes into my project, fixed the NSRect to CGRect stuff and the String method signatures to &str. Now everything works like a charm! Awesome!

ryanmcgrath commented 3 years ago

Awesome! Glad to hear it - will close this issue then. Really appreciate the contributions.

At this point, I'm trying to ensure the documentation is actually usable throughout the project. I feel like the general selection of widgets/controls is "good enough" for building sufficiently complicated apps, and is close enough to a v0.1 that I hope to push up to crates.io soon (though contributions before v0.1 are of course welcome).

Fingers crossed!