Giter Site home page Giter Site logo

cacao's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cacao's Issues

TextField not on edit mode at window opening

I want to premise by saying that I just started using cacao so probably there's something silly I'm missing. I apologize in advance if that's the case.
The issue that I have is very simple: is there a way for a TextField to not be on edit mode right when the window finishes loading? Meaning: when the window is done loading and showing the TextField immediately awaits for input. Is there a way you can have it inactive until you click on it, as if "enter" is the first thing pressed? I can't figure out a way to make this work even though it sounds like a simple task :/

You can use the text_input.rs in the examples folder as an example.
Thanks

iOS example crash on real hardware with error "-[RSTView animator]: unrecognized selector sent to instance"

This was tested against a790eb9 with the example on the repo

It appears to me that RSTView is registered in multiple places of the codebase, those could possibly conflict I suppose?

Cargo.toml:

cacao = { git = "https://github.com/ryanmcgrath/cacao", features = [ "uikit", "autolayout" ], default-features = false }

Device syslog for the process:

Jul 14 11:23:48 testing_ios_rust(RunningBoardServices)[43732] <Notice>: Initializing connection
Jul 14 11:23:48 testing_ios_rust(RunningBoardServices)[43732] <Notice>: Removing all cached process handles
Jul 14 11:23:48 testing_ios_rust(RunningBoardServices)[43732] <Notice>: Sending handshake request attempt #1 to server
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: Deactivation reason added: 10; deactivation reasons: 0 -> 1024; animating application lifecycle event: 0
Jul 14 11:23:48 testing_ios_rust(RunningBoardServices)[43732] <Notice>: Creating connection to com.apple.runningboard
Jul 14 11:23:48 testing_ios_rust(libMobileGestalt.dylib)[43732] <Notice>: Cache loaded with 4896 pre-cached in CacheData and 52 items in CacheExtra.
Jul 14 11:23:48 testing_ios_rust(BoardServices)[43732] <Notice>: activating monitor for service com.apple.frontboard.open
Jul 14 11:23:48 testing_ios_rust(BoardServices)[43732] <Notice>: activating monitor for service com.apple.frontboard.workspace-service
Jul 14 11:23:48 testing_ios_rust(FrontBoardServices)[43732] <Notice>: FBSWorkspace connecting to endpoint : <private>
Jul 14 11:23:48 testing_ios_rust(FrontBoardServices)[43732] <Notice>: FBSWorkspace registering source: <private>
Jul 14 11:23:48 testing_ios_rust(FrontBoardServices)[43732] <Notice>: FBSWorkspace connected to endpoint : <private>
Jul 14 11:23:48 testing_ios_rust(RunningBoardServices)[43732] <Notice>: Added observer for process assertions expiration warning: <_RBSExpirationWarningClient: 0x28042d4c0>
Jul 14 11:23:48 testing_ios_rust(RunningBoardServices)[43732] <Notice>: Handshake succeeded
Jul 14 11:23:48 testing_ios_rust(RunningBoardServices)[43732] <Notice>: Identity resolved as application<zone.mary.testing.testing-ios-rust>
Jul 14 11:23:48 testing_ios_rust(libAccessibility.dylib)[43732] <Notice>: Read CategoryName: per-app = 1, category name = (null)
Jul 14 11:23:48 testing_ios_rust(libAccessibility.dylib)[43732] <Notice>: Read CategoryName: per-app = 0, category name = (null)
Jul 14 11:23:48 testing_ios_rust(XCTTargetBootstrap)[43732] <Notice>: Registering for test daemon availability notify post.
Jul 14 11:23:48 testing_ios_rust(XCTTargetBootstrap)[43732] <Notice>: notify_get_state check indicated test daemon not ready.
Jul 14 11:23:48 testing_ios_rust(XCTTargetBootstrap)[43732] <Notice>: notify_get_state check indicated test daemon not ready.
Jul 14 11:23:48 testing_ios_rust(XCTTargetBootstrap)[43732] <Notice>: notify_get_state check indicated test daemon not ready.
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: Deactivation reason added: 11; deactivation reasons: 1024 -> 3072; animating application lifecycle event: 0
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: Deactivation reason removed: 10; deactivation reasons: 3072 -> 2048; animating application lifecycle event: 0
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: <private>: Will add backgroundTask with taskName: <private>, expirationHandler: <__NSGlobalBlock__: 0x2089178f0>
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: <private>: Created background task <private>. Assertion will be assigned soon
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: <private>: Creating new assertion since assertion is nil
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: <private>: Created new assertion <BKSProcessAssertion: 0x282721ae0>
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: Deactivation reason added: 5; deactivation reasons: 2048 -> 2080; animating application lifecycle event: 1 
Jul 14 11:23:48 testing_ios_rust(UIKitCore)[43732] <Notice>: [0x282f30000] Initialized with scene: <UIWindowScene: 0x13ff04be0>; behavior: <_UIEventDeferringBehavior_Default: 0x28042bc20>
Jul 14 11:23:48 testing_ios_rust(CoreFoundation)[43732] <Notice>: -[RSTView animator]: unrecognized selector sent to instance 0x141d05510
Jul 14 11:23:48 testing_ios_rust(CoreFoundation)[43732] <Notice>: *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RSTView animator]: unrecognized selector sent to instance 0x141d05510'
*** First throw call stack:
(0x1ad679288 0x1c6373744 0x1ad756fc4 0x1b09cdf5c 0x1ad60de98 0x1ad60cf70 0x1000e71f0 0x1000e57d4 0x1000f0f40 0x1000e9ba4 0x1000e94e4 0x1000e939c 0x1000d6788 0x1000d63e8 0x1000d5484 0x1afdaf390 0x1b00aec64 0x1afdb1a48 0x1afcf2508 0x1bf883294 0x1bf8a9090 0x1bf864308 0x1bf865958 0x1ad2e0a30 0x1ad2e44e0 0x1bf865c70 0x1bf865040 0x1bf869700 0x1ad69b414 0x1ad6ac1a0 0x1ad5e56f8 0x1ad5eb05c 0x1ad5febc8 0x1c9732374 0x1aff6e648 0x1afcefd90 0x1000ddaa8 0x1000d6724 0x1000d99f4 0x1000e0414 0x1000d5ca0 0x10012c9dc 0x1000d5c68 0x1000d68e4 0x10063dce4)

NSTextView and NSDocument

I'm trying to learn rust by writing a simple plain text editor. I followed this tutorial in Swift and I have a working prototype. I'm trying to port it to rust using your library, but I can't find NSTextView or NSDocument. In the README you mention:

Each UI control contains a objc field, which you can use as an escape hatch - if the control doesn't support something, you're free to drop to the Objective-C runtime yourself and handle it.

I'm new to UI development on the mac, but it seems like there are several way forwards here:

  1. I can try to use the Objective-C runtime to get NSTextView and NSDocument (I don't know if this even makes sense)
  2. I can try to read how you implemented TextField (which I saw bindings for) and try to copy what you did there
  3. Maybe I'm misunderstanding something and it's actually simple to do

I saw in this example that you said

A Window Controller is backed by NSWindowController, and typically used in scenarios where
you might have documents (backed by NSDocument) that you're working with.

So it seems like you plan on supporting a Document Based App use-case.

It would be very helpful to me if you could point me in the right direction, or provide an example document based app example (maybe along the lines of the tutorial linked earlier). If this is too much to ask, you can also just close this issue without comment. Thanks for you time!

EDIT: clarity

[Question] Desktop notification seems not work?

Hello, I'm testing desktop notification using cacao in my repo, cacao_playground.

I just added one line for notification based on hello world. But I get an error like this when I run cargo run. I saw a readme in cacao but doesn't understand this word

Note that this requires your application be code-signed, and will not work without it.

What am I doing wrong?

❯ cargo run
   Compiling cacao_playground v0.1.0 (/Users/young/Desktop/moloco/playground/rust/cacao_playground)
    Finished dev [unoptimized + debuginfo] target(s) in 1.15s
     Running `target/debug/cacao_playground`
2021-10-24 13:24:19.446 cacao_playground[46977:5130533] *** Assertion failure in +[UNUserNotificationCenter currentNotificationCenter], UNUserNotificationCenter.m:54
2021-10-24 13:24:19.449 cacao_playground[46977:5130533] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL file:///Users/young/Desktop/moloco/playground/rust/cacao_playground/target/debug/'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff205f81db __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00007fff20331d92 objc_exception_throw + 48
	2   CoreFoundation                      0x00007fff20621352 +[NSException raise:format:arguments:] + 88
	3   Foundation                          0x00007fff213e04d2 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 191
	4   UserNotifications                   0x00007fff2a4fa540 __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke + 985
	5   libdispatch.dylib                   0x00007fff202dc806 _dispatch_client_callout + 8
	6   libdispatch.dylib                   0x00007fff202dd98c _dispatch_once_callout + 20
	7   UserNotifications                   0x00007fff2a4fa165 +[UNUserNotificationCenter currentNotificationCenter] + 101
	8   cacao_playground                    0x000000010d540be6 _ZN60_$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$6invoke17h3fc300ea76f1fcadE + 70
	9   cacao_playground                    0x000000010d53f282 _ZN4objc7message8platform15send_unverified17he01a71148119e4eaE + 98
	10  cacao_playground                    0x000000010d54024b _ZN5cacao18user_notifications18NotificationCenter6notify17h59789fbb44092ba5E + 2619
	11  cacao_playground                    0x000000010d52a77c _ZN85_$LT$cacao_playground..BasicApp$u20$as$u20$cacao..macos..app..traits..AppDelegate$GT$20did_finish_launching17h9887249749ff2e54E + 108
	12  cacao_playground                    0x000000010d52b5ce _ZN5cacao5macos3app8delegate20did_finish_launching17h35985f97e2106380E + 46
	13  CoreFoundation                      0x00007fff20573a53 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
	14  CoreFoundation                      0x00007fff2060f4d9 ___CFXRegistrationPost_block_invoke + 49
	15  CoreFoundation                      0x00007fff2060f454 _CFXRegistrationPost + 496
	16  CoreFoundation                      0x00007fff20544cce _CFXNotificationPost + 736
	17  Foundation                          0x00007fff212b6bb8 -[NSNotificationCenter postNotificationName:object:userInfo:] + 59
	18  AppKit                              0x00007fff22d8e440 -[NSApplication _postDidFinishNotification] + 305
	19  AppKit                              0x00007fff22d8e192 -[NSApplication _sendFinishLaunchingNotification] + 208
	20  AppKit                              0x00007fff22d8b331 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 541
	21  AppKit                              0x00007fff22d8af87 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665
	22  Foundation                          0x00007fff212e2306 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
	23  Foundation                          0x00007fff212e2176 _NSAppleEventManagerGenericHandler + 80
	24  AE                                  0x00007fff2635e7f3 _AppleEventsCheckInAppWithBlock + 15720
	25  AE                                  0x00007fff2635df0e _AppleEventsCheckInAppWithBlock + 13443
	26  AE                                  0x00007fff26356c23 aeProcessAppleEvent + 448
	27  HIToolbox                           0x00007fff287d6012 AEProcessAppleEvent + 54
	28  AppKit                              0x00007fff22d85610 _DPSNextEvent + 2046
	29  AppKit                              0x00007fff22d83945 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1364
	30  AppKit                              0x00007fff22d75c69 -[NSApplication run] + 586
	31  cacao_playground                    0x000000010d540b96 _ZN60_$LT$$LP$$RP$$u20$as$u20$objc..message..MessageArguments$GT$6invoke17h11fd747e9c6b6bd4E + 70
	32  cacao_playground                    0x000000010d53eccc _ZN4objc7message8platform15send_unverified17h66e57c952470fa58E + 92
	33  cacao_playground                    0x000000010d5307c6 _ZN5cacao5macos3app12App$LT$T$GT$3run17h185027ef278d9109E + 1206
	34  cacao_playground                    0x000000010d52a7cb _ZN16cacao_playground4main17hf4adb535eeac4ec1E + 59
	35  cacao_playground                    0x000000010d529d4e _ZN4core3ops8function6FnOnce9call_once17hfad80ba2a9fe4a31E + 14
	36  cacao_playground                    0x000000010d531021 _ZN3std10sys_common9backtrace28__rust_begin_short_backtrace17he91fbb5a9ef377b9E + 17
	37  cacao_playground                    0x000000010d52ab94 _ZN3std2rt10lang_start28_$u7b$$u7b$closure$u7d$$u7d$17h48ed62f72d20011eE + 20
	38  cacao_playground                    0x000000010d5d087a _ZN3std2rt19lang_start_internal17h9fcc861d49447111E + 650
	39  cacao_playground                    0x000000010d52ab5e _ZN3std2rt10lang_start17h96fe9822a85ecbd5E + 46
	40  cacao_playground                    0x000000010d52a856 main + 22
	41  libdyld.dylib                       0x00007fff204a1f3d start + 1
)
libc++abi: terminating with uncaught exception of type NSException
[1]    46977 abort      cargo run

Build fails for webview feature

Hi, this crate is currently failing to build with the webview feature turned on.

From the build errors it looks like this is due to the recent refactoring work on the Layout components:

Build errors

``` -cargo build --features=webview Compiling cacao v0.1.0 (/Users/david/gits/cacao) error[E0599]: no variant or associated item named `new` found for enum `LayoutAnchorY` in the current scope --> src/webview/mod.rs:131:33 | 131 | top: LayoutAnchorY::new(unsafe { msg_send![view, topAnchor] }), | ^^^ variant or associated item not found in `LayoutAnchorY` | ::: src/layout/vertical.rs:11:1 | 11 | pub enum LayoutAnchorY { | ---------------------- variant or associated item `new` not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorX in the current scope
--> src/webview/mod.rs:132:37
|
132 | leading: LayoutAnchorX::new(unsafe { msg_send![view, leadingAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorX
|
::: src/layout/horizontal.rs:14:1
|
14 | pub enum LayoutAnchorX {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorX in the current scope
--> src/webview/mod.rs:133:38
|
133 | trailing: LayoutAnchorX::new(unsafe { msg_send![view, trailingAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorX
|
::: src/layout/horizontal.rs:14:1
|
14 | pub enum LayoutAnchorX {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorY in the current scope
--> src/webview/mod.rs:134:36
|
134 | bottom: LayoutAnchorY::new(unsafe { msg_send![view, bottomAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorY
|
::: src/layout/vertical.rs:11:1
|
11 | pub enum LayoutAnchorY {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorDimension in the current scope
--> src/webview/mod.rs:135:43
|
135 | width: LayoutAnchorDimension::new(unsafe { msg_send![view, widthAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorDimension
|
::: src/layout/dimension.rs:20:1
|
20 | pub enum LayoutAnchorDimension {
| ------------------------------ variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorDimension in the current scope
--> src/webview/mod.rs:136:44
|
136 | height: LayoutAnchorDimension::new(unsafe { msg_send![view, heightAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorDimension
|
::: src/layout/dimension.rs:20:1
|
20 | pub enum LayoutAnchorDimension {
| ------------------------------ variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorX in the current scope
--> src/webview/mod.rs:137:38
|
137 | center_x: LayoutAnchorX::new(unsafe { msg_send![view, centerXAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorX
|
::: src/layout/horizontal.rs:14:1
|
14 | pub enum LayoutAnchorX {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorY in the current scope
--> src/webview/mod.rs:138:38
|
138 | center_y: LayoutAnchorY::new(unsafe { msg_send![view, centerYAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorY
|
::: src/layout/vertical.rs:11:1
|
11 | pub enum LayoutAnchorY {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorY in the current scope
--> src/webview/mod.rs:162:33
|
162 | top: LayoutAnchorY::new(unsafe { msg_send![view, topAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorY
|
::: src/layout/vertical.rs:11:1
|
11 | pub enum LayoutAnchorY {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorX in the current scope
--> src/webview/mod.rs:163:37
|
163 | leading: LayoutAnchorX::new(unsafe { msg_send![view, leadingAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorX
|
::: src/layout/horizontal.rs:14:1
|
14 | pub enum LayoutAnchorX {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorX in the current scope
--> src/webview/mod.rs:164:38
|
164 | trailing: LayoutAnchorX::new(unsafe { msg_send![view, trailingAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorX
|
::: src/layout/horizontal.rs:14:1
|
14 | pub enum LayoutAnchorX {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorY in the current scope
--> src/webview/mod.rs:165:36
|
165 | bottom: LayoutAnchorY::new(unsafe { msg_send![view, bottomAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorY
|
::: src/layout/vertical.rs:11:1
|
11 | pub enum LayoutAnchorY {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorDimension in the current scope
--> src/webview/mod.rs:166:43
|
166 | width: LayoutAnchorDimension::new(unsafe { msg_send![view, widthAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorDimension
|
::: src/layout/dimension.rs:20:1
|
20 | pub enum LayoutAnchorDimension {
| ------------------------------ variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorDimension in the current scope
--> src/webview/mod.rs:167:44
|
167 | height: LayoutAnchorDimension::new(unsafe { msg_send![view, heightAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorDimension
|
::: src/layout/dimension.rs:20:1
|
20 | pub enum LayoutAnchorDimension {
| ------------------------------ variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorX in the current scope
--> src/webview/mod.rs:168:38
|
168 | center_x: LayoutAnchorX::new(unsafe { msg_send![view, centerXAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorX
|
::: src/layout/horizontal.rs:14:1
|
14 | pub enum LayoutAnchorX {
| ---------------------- variant or associated item new not found here

error[E0599]: no variant or associated item named new found for enum LayoutAnchorY in the current scope
--> src/webview/mod.rs:169:38
|
169 | center_y: LayoutAnchorY::new(unsafe { msg_send![view, centerYAnchor] }),
| ^^^ variant or associated item not found in LayoutAnchorY
|
::: src/layout/vertical.rs:11:1
|
11 | pub enum LayoutAnchorY {
| ---------------------- variant or associated item new not found here

error[E0308]: mismatched types
--> src/webview/mod.rs:219:76
|
219 | fn get_from_backing_node<F: Fn(&Object) -> R, R>(&self, handler: F) -> R {
| --------------------- - ^ expected type parameter R, found ()
| | |
| | this type parameter
| implicitly returns () as its body has no tail or return expression
|
= note: expected type parameter R
found unit type ()

error: aborting due to 17 previous errors

Some errors have detailed explanations: E0308, E0599.
For more information about an error, try rustc --explain E0308.
error: could not compile cacao

To learn more, run the command again with --verbose.

</p></details>

tvOS example

When running the ios-beta on tvOS simulator it triggers an error. Works on iOS simulator. Wondering if it can work on tvOS or not

[Question] Rendering a pixel buffer to a window?

Hey there, I'm pretty new to mac/cocoa programming, I'm trying to basically write a renderer, ending up with some kind of array of pixel data, and display that to a window.

It seems like I could use Bitmap contexts/Image::draw to achieve this somehow, but so far I haven't been able to.

I tried stuff like this, which doesn't render anything to the screen:

struct BasicApp {
    window: Window,
}

impl AppDelegate for BasicApp {
    fn did_finish_launching(&self) {
        self.window.set_minimum_content_size(400., 400.);
        self.window.set_title("Hello World!");
        self.window.show();
        self.window.make_key_window();
        self.window.make_key_and_order_front();

        let config = DrawConfig {
            source: (0., 100.),
            target: (0., 100.),
            resize: cacao::image::ResizeBehavior::Stretch,
        };
        let image = Image::draw(config, |cg_rect, cg_context_ref| {
            cg_context_ref.set_fill_color(&CGColor::rgb(255., 255., 255., 255.));
            cg_context_ref.fill_rect(cg_rect);
            cg_context_ref.flush();

            true
        });
        let image_view = ImageView::new();
        image_view.set_background_color(cacao::color::Color::SystemBlue);
        image_view.set_image(&image);

        let view = View::new();
        view.add_subview(&image_view);

        LayoutConstraint::activate(&[
            image_view.top.constraint_equal_to(&view.top),
            image_view.leading.constraint_equal_to(&view.leading),
            image_view.trailing.constraint_equal_to(&view.trailing),
            image_view.bottom.constraint_equal_to(&view.bottom),
        ]);

        self.window.set_content_view(&view);
    }
}

fn main() {
    let app_delegate = BasicApp {
        window: Window::default(),
    };
    let app = App::new("com.hello.world", app_delegate);

    app.run()
}

And many variations of it (without really achieving anything), any ideas?

Can't seem to make Button fire when clicked

I just got started with cacao today so am probably missing something but I can't seem to get the button to fire when clicked.
Here is my code:

use cacao::appkit::window::Window;
use cacao::appkit::{App, AppDelegate};
use cacao::filesystem::FileSelectPanel;
use cacao::layout::Layout;
use cacao::notification_center::Dispatcher;
use cacao::text::{Font, Label};
use cacao::view::{View, ViewController, ViewDelegate};
use cacao::{button, view};

struct BasicApp {
    window: Window,
    content_view: ViewController<ContentView>,
}

impl Default for BasicApp {
    fn default() -> Self {
        Self {
            window: Window::default(),
            content_view: ViewController::new(ContentView::default()),
        }
    }
}

impl Dispatcher for BasicApp {
    type Message = Message;

    /// Handles a message that came over on the main (UI) thread.
    fn on_ui_message(&self, message: Self::Message) {
        eprint!("Got message");
        if let Some(delegate) = &self.content_view.view.delegate {
            delegate.on_ui_message(message);
        }
    }
}

impl AppDelegate for BasicApp {
    fn did_finish_launching(&self) {
        App::activate();
        self.window.set_minimum_content_size(400., 400.);
        self.window.set_title("Hello World!");
        self.window.set_movable_by_background(true);
        self.window.set_content_view_controller(&self.content_view);
        self.window.show();
        //        FileSelectPanel::new().show(|_| {});
    }

    fn should_terminate_after_last_window_closed(&self) -> bool {
        true
    }
}

#[derive(Default)]
struct ContentView {
    content: view::View,
    label: Label,
}

impl ViewDelegate for ContentView {
    const NAME: &'static str = "SafeAreaView";

    fn did_load(&mut self, view: View) {
        let font = Font::system(30.);
        self.label.set_font(&font);
        self.label.set_text("Hello World");
        self.label
            .set_text_color(cacao::color::Color::rgb(255, 255, 255));

        self.content.add_subview(&self.label);
        let mut btn = button::Button::new("Click me");
        btn.set_action(|| dispatch_ui(Message::ChangeText));
        btn.set_key_equivalent("c");
        self.content.add_subview(&btn);
        view.add_subview(&self.content);

        // Add layout constraints to be 100% excluding the safe area
        // Do last because it will crash because the view needs to be inside the hierarchy
        cacao::layout::LayoutConstraint::activate(&[
            self.content
                .top
                .constraint_equal_to(&view.safe_layout_guide.top),
            self.content
                .leading
                .constraint_equal_to(&view.safe_layout_guide.leading),
            self.content
                .trailing
                .constraint_equal_to(&view.safe_layout_guide.trailing),
            self.content
                .bottom
                .constraint_equal_to(&view.safe_layout_guide.bottom),
        ])
    }
}

impl Dispatcher for ContentView {
    type Message = Message;

    /// Handles a message that came over on the main (UI) thread.
    fn on_ui_message(&self, message: Self::Message) {
        self.label.set_text("Changed text")
    }
}

/// Dispatch a message on a background thread.
fn dispatch_ui(message: Message) {
    println!("Dispatching UI message: {:?}", message);
    App::<BasicApp, Message>::dispatch_main(message);
}

#[derive(Clone, Debug)]
enum Message {
    ChangeText,
}
fn main() {
    App::new("com.hello.world", BasicApp::default()).run();
}


No matter what I do the button refuses to call the action when I click on it, is this a bug or have I missed something?
It may be relevant that I am using VoiceOver, the macOS screen reader, but have tested without it and still have the same issue so don't think its related.

Minimum system requirements

What are the official minimum system requirements for this project?
Rust version:
Mac OS version:
GNUStep version:

Get screen dimensions for positioning below toolbar

I looked through the docs so sorry if I missed it, but I didn't see a real way to get the system's dimensions? I would like this info so I can properly calculate the top and left values for positioning my Window, as my app itself is a utility and not a full fledged desktop application (hence why I want it to appear to the right under the icons on the toolbar)

Window closes on blocking operations

Not sure if its an issue with Cacao or macOS itself but it seems as though my main window in cacao apps closes if I perform a blocking operation on the main thread for too long.
I don't really have any good examples atm but running the following code in the on_ui_message method should replicate it:


                let len = 1024usize.pow(3);
                let mut vec = Vec::with_capacity(len);
                for i in 0..len {
                    vec.push(std::time::SystemTime::now());
                }
                for i in &vec {
                    if i.duration_since(std::time::SystemTime::UNIX_EPOCH).unwrap()
                        > Duration::from_secs(365 * 24 * 60 * 60 * 100)
                    {
                        eprintln!("Its 2070");
                    }
                }
                eprintln!("Len: {:?}", vec.len());
            

Simply calling sleep(Duration::from_secs(xxx)) doesn't seem to do it so maybe there has to be an element of work being done or large memory allocation, I'm not quite sure.
This is happening for me in an unoptimised image processing algorithm I'm running and I'd like to verify its working before preceding but currently can't because it just crashes the window.
Do you know what might be going on?

Broken import in Hello, world

This line of the Hello, world example in the README fails:

use cacao::macos::app::{App, AppDelegate};

The solution is just to change it to

use cacao::macos::{App, AppDelegate};

because the macos module re-exports app::* but app is not a pub mod.

Really interesting project, I'm looking forward to playing around with it.

todos_list example perference planel size

I've been trying to read through the code and make sense of it all. The todos example is great as it touches a lot of topics.
Unfortunately I can't figure out why the preference panel size is borked. It seems to be missing a min content area perhaps? Where would I find more docs for this? Are there other things LayoutConstraint::activate takes than is in the code?
I'd appreciate any sort of docs here you may have. (I don't know much about C# and being able to build macos apps with rust is a dream. This is a fantastic crate!

Using trunk as of c739479
With rust 1.64.0

image

Async, Background, and Local Dispatchers support

I think we should add the following features to make development easier:

  • Async
    • Maybe you need to call async functions
    • Could be done by calling a background task to modify the view later instead of in the did_load
  • Background
    • Maybe a background task might be useful for like setInterval
  • Local Dispatcher
    • So that instead of adding complicated logic in App, you can do it in the local view impl

webview compilation error

Hi,after I added cacao (v0.2.0) as a project dependency, when I introduced the webveiw scope, a compilation error occurred.

use cacao::webview::{WebView, WebViewConfig, WebViewDelegate};

error:

unresolved import `cacao::webview`

could not find `webview` in `cacao`rustc(E0432)
webview_custom_protocol.rs(5, 12): could not find `webview` in `cacao`
cacao-0.2.0/src/webview/mod.rs

Improved documentation for ListView

I'm attempting to build a table component, similar to what's in the todo list example but can't seem to get anything to display and the most progress I've been able to make is to have the item_for method being called with an index that's double the number of rows.
Would it be possible to improve the module level documentation for ListViews to explain how they are meant to be used and to add more detailed comments to the todo list example please.
For context I've not done any object c stuff before so am not aware of how the original framework really works.

Ensure architecture differences are respected

From: https://developer.apple.com/documentation/apple-silicon/addressing-architectural-differences-in-your-macos-code

  • The NSTextAlignment enumeration uses different numerical values for some constants on arm64 and x86_64 architectures. When referring to constants using numerical values, validate that you use the correct values on each architecture.
  • The NSImage.ResizingMode and UIImage.ResizingMode enumerations uses different numerical values for some constants on arm64 and x86_64 architectures. When referring to constants using numerical values, validate that you use the correct values on each architecture.

I know some of these are handled already, but it's worth doing another pass to make sure.

Path to support labels, text, images, etc in iOS

I tried to add labels/text input for the iOS example and ran into a bunch of feature flags.

Is there a way to get labels/text wired up for iOS?

If not, can you give some direction on how to add it via a PR? I understand some of the code patterns, but there's still some architecture (make an Architecture.md?) that I would need to dig into to understand how to enable it properly. Also, is there a obj-c spec you're working off of or just using your ios/macos dev experience to know which NS concepts to bridge over?

Hello World example does not build

Using the cacao 0.2.1 release i get an error when I copy the hello world example from the docs:

error[E0603]: module `app` is private
  --> src/main.rs:1:19
   |
1  | use cacao::macos::app::{App, AppDelegate};
   |                   ^^^ private module
   |
note: the module `app` is defined here
  --> /Users/jelle/.cargo/registry/src/github.com-1ecc6299db9ec823/cacao-0.2.1/src/macos/mod.rs:11:1
   |
11 | mod app;
   | ^^^^^^^^

For more information about this error, try `rustc --explain E0603`.
error: could not compile `rustgui` due to previous error

Please add NSOpenGLView

I tried to do this in my project code but it seems like I need access to ObjcAccess in order to write a Layout impl. It seems like maybe new widgets need to be wrapped directly in cacao or certain interfaces would need to be made public?

I just want a way to render to an OpenGL area from within a program that I was thinking of writing in cacao. I don't really know the API well enough, but looking at the image example it seemed like maybe I need to use add_subview or set_content_view passing the wrapper I made for NSOpenGLView? That's the point where I run into the issue that I can't write a Layout impl.

Story for unowned pointers in collections

Both of the collection types (NSArray and NSMutableDictionary) only accept owned pointers to elements. This makes sense, but there are many types that are always shared (NSURL, NSImage, etc), which means we cannot store these elements in any collections. This prevents using some APIs and just generally is a bit weird.

Why are those types always unowned, and what would need to happen in order to properly add them to a collection without leaking?

Xib file support?

Hi, I like simple some of the examples. I was hoping to see an example that made use of an xib file.
Also can we have an example that calls NSApplicationMain()?
This is the description of the method from here: https://developer.apple.com/documentation/appkit/1428499-nsapplicationmain

Creates the application, loads the main nib file from the application’s main bundle, and runs the application. You must call this function from the main thread of your application, and you typically call it only once from your application’s main function. Your main function is usually generated automatically by Xcode.

I feel this function is important because it is responsible for loading values from the info.plist file.

Could not compile user-notifications feature.

Compiling below (cargo build):

# Cargo.toml
[dependencies]
cacao = {version = "0.2.1", features = ["user-notifications"]}
// main.rs
use cacao::macos::{App, window::Window, AppDelegate};
use cacao::notification_center;


#[derive(Default)]
struct BasicApp {
    window: Window
}

impl AppDelegate for BasicApp {
    fn did_finish_launching(&self) {
        self.window.set_minimum_content_size(400., 400.);
        self.window.set_title("Hello World!");
        self.window.show();
        
    }
}

fn main() {
    App::new("com.hello.world", BasicApp::default()).run();
}

leads to the following errors:

❯ cargo build
   Compiling cacao v0.2.1
error[E0599]: no function or associated item named `wrap` found for struct `NSString<'_>` in the current scope
  --> /Users/ej/.cargo/registry/src/github.com-1ecc6299db9ec823/cacao-0.2.1/src/user_notifications/mod.rs:29:55
   |
29 |                 let localized_description = NSString::wrap(msg_send![error, localizedDescription]); 
   |                                                       ^^^^ function or associated item not found in `NSString<'_>`
   |
  ::: /Users/ej/.cargo/registry/src/github.com-1ecc6299db9ec823/cacao-0.2.1/src/foundation/string.rs:19:1
   |
19 | pub struct NSString<'a> {
   | ----------------------- function or associated item `wrap` not found for this

For more information about this error, try `rustc --explain E0599`.
error: could not compile `cacao` due to previous error

I am on a M1 Macbook Pro (2021, 14-inch) running MacOS Monterey using stable-aarch64-apple-darwin. stable-x86_64-apple-darwin produces the same result.

ViewAnimatorProxy?

Where is ViewAnimatorProxy defined?
Compilation is failing because it can't be found

`examples/animation.rs` is laggy

Title. Running on M1 Mac mini and feels like it should be faster. Is there anything making this slower than native Obj-C AppKit?

Segmentation fault (EXC_BAD_ACCESS) on webview when receiving messages from the webpage.

Problem:

When a message is sent from the web page to the WKWebView it generates a segmentation fault.

Versions:

  • cacao 0.2.0, feature "Webview"
  • rust 1.51.0
  • OS-X Catalina on a Mac Mini

Steps to reproduce it:

On the webview_custom_message.rs example do this:

  1. Insert this after line 71, on AppWindow:new()
    webview_config.add_handler("notify");
    This will add an handler for javascript messages.

  2. Change the html code on line 37 into this
    <body onload="window.webkit.messageHandlers.notify.postMessage('Page loaded');">

This will send a message from the webpage to the handler abore. And will also generate an error.

I created a simple gist containing both the modified example and a Cargo.toml file to build it.

This error only hapens if the message is sent from the javascript page only. There will be no issue if the message is posted from the rust code, like this:
webview_config.add_user_script("window.webkit.messageHandlers.notify.postMessage("loaded");", InjectAt::End, true);

On my debuging I found that the problem is generated on the exit of the on_message() function on file webview/class.rs. More specifically, if this line 52 is commented out the problem won't happen:
line 52: // let body = NSString::from_retained(msg_send![script_message, body]);
line 53: delegate.on_message(name.to_str(), "dummy body value" );
It is during the execution of objc_autoreleasePoolPop->objc_release for the body variable that the problem happens.

`Info.plist` bundle

I'm trying to integrate an Info.plist into a project using Cacao to set the ATSApplicationFontsPath key to load custom fonts. How is this possible?

cyclic package dependency error

I'd like to try out cacao but I get a cargo error when I want to add the library to the project.

This is my Cargo.toml:

[package]
name = "cacao-example-app"
version = "0.1.0"
edition = "2021"

[dependencies]
cacao = "0.3.0"

I get this error when I run cargo build:

error: cyclic package dependency: package `core-foundation v0.9.3` depends on itself. Cycle:
package `core-foundation v0.9.3`
    ... which satisfies dependency `core-foundation = "^0.9"` of package `iana-time-zone v0.1.42`
    ... which satisfies dependency `iana-time-zone = "^0.1.41"` of package `chrono v0.4.21`
    ... which satisfies dependency `chrono = "^0.4"` of package `core-foundation v0.9.3`
    ... which satisfies dependency `core-foundation = "^0.9"` of package `cacao v0.3.0`

I'm relatively new to rust so I'm not sure if this is a noob question. Can you give a hint on how to fix this?
What would be the minimal Cargo.toml to run an example app?

MacOS: 12.3.1, M1 pro chip
Rustc: 1.62.1

webview crashes when used from two different bundles

i'm building two different "formats" of my app (they're audio plug-ins) as separate plugin bundles. when loading both bundles together in a host application, both of them crash simultaneously. the following unwrap() seems to be causing the crash: https://github.com/ryanmcgrath/cacao/blob/trunk/src/webview/class.rs#L194

if i've understood correctly, this is just where the class in question gets declared (not even initialised), so might the crash happen when trying to declare the class when it's already declared? any other ideas?

implement acceptsFirstMouse on webview?

when cacao's webview is not in focus (e.g. the window containing the webview is partially behind another focused window), the first click on the webview will not go through to the view itself. this first click will only focus the window, after which any subsequent clicks will actually be registered on the webview.

the behaviour described above can be changed by implementing and returning YES from the acceptsFirstMouse method on the webview. now, from a quick test it seems like most apps allow the first click to go through to the view, so my question is whether you'd accept a PR where this method is implemented on the webview by default? another question is whether every other cacao view should implement this method too.

disclaimer: i'm no expert on macOS UI stuff so it's entirely possible that i've missed something and that there's another way to allow for the first click to go through to the view.

Replace `objc` with `objc2`?

Hey, macOS maintainer of winit here. I've been working on a replacement for objc called objc2, and I think it could be interesting for this crate?

Some of the concrete improvements you'd reap benefit from, mainly in the category "improving correctness":

  • Helper macro msg_send_id! for following cocoa's memory management rules - as a quick example, NSString::new currently leaks because it uses Id::from_ptr instead of Id::from_retained_ptr.
  • Implementing Encode is now required for all types that go across msg_send! - this is great for catching bugs, for example this code in ListView::select_row_indexes is wrong, the type of index is &usize while it should be usize.
  • Soundness fixes concerning message sending, autoreleasepools and reference counting.

I have an implementation of Foundation that you may be interested in using, at the very least it can be useful as an example of how to use objc2 well.

See also my PR to the core-foundation-rs project.

Opening this issue to start the discussion, am a bit tired so sorry it's not more detailed. I would really like to work towards a completely safe interface over (the most commonly used parts of) Cocoa, but wanted to keep it out of the scope of objc2 itself - cacao seems like a nice work in that direction, would like to help out in this effort (other than just working on objc2).

Minimal example with button

The library seems to have all the needed controls/widgets, but I'm struggling to add a button in a window.

wrapping an existing NSView?

i'm getting an NSView as a *mut core::ffi::c_void from the outside which i'd like to add a cacao::webview::WebView. is this possible? tried:

let mut webview_config = WebViewConfig::default();
let webview = WebView::with(webview_config, WebViewInstance::default());
webview.load_html("<strong>hello world</strong>");
let mut view = View::new();
view.objc = ObjcProperty::retain(raw_window_handle.ns_view as id);
view.add_subview(&webview);

but that didn't seem to work. any ideas?

cacao 0.3.0 doesn't compile for iOS

I get the following error after upgrading cacao to the latest version.

error[E0308]: mismatched types
--> .../cacao-0.3.0/src/image/image.rs:211:26
|
211 | false => {
| _________^
212 | | #[cfg(target_os = "macos")]
213 | | panic!("SFSymbols are only supported on macOS 11.0 and up.")
214 | | }
| |
^ expected *-ptr, found ()
|
= note: expected raw pointer *mut Object
found unit type ()

Menubar support

Hi, is it possible to create a menubar app via cacao? if so, is it documented?

Mixing runtimes

I'm interested in how others may have mixed the AppKit runtime with something Rust-centric, whether async-std, tokio, or something else. Use cases are primarily in mixed platform systems, the core Rust code can't be designed around the standard Apple runtime, and needs something from the Rust ecosystem to actually be usable.

I have found that naively calling NSApplication.run() within tokio::task::spawn_blocking results in the event loop hanging.

To work in Catalina (macOS 10.15.7) NSToolbarSidebarTrackingSeparatorItemIdentifier had to be removed

Hi,
first of all, GREAT WORK! I had no problems getting some examples to run in 10.15.7 - but unfortunately the NSToolbarSidebarTrackingSeparatorItemIdentifier is part of macOS 11 and I got a compile error on my Catalina (10.15.7) system:

note: Undefined symbols for architecture x86_64:
          "_NSToolbarSidebarTrackingSeparatorItemIdentifier", referenced from:
              cacao::macos::toolbar::enums::ItemIdentifier::to_nsstring::h93aee7ff60b47338 in libcacao-666ce155f0266e01.rlib(cacao-666ce155f0266e01.cacao.6ipigaqo-cgu.15.rcgu.o)
        ld: symbol(s) not found for architecture x86_64

I removed the Enum-entry and corresponding code and got the todo_list compiled and running. No Crashes or bugs (so far). Here is my modified enums.rs
enums.txt

How to publish an app

Touched on in #19 I think it would be super useful to describe a way to compile your rust code with xcode to get code-signing to work and publish it in either app store (macOS and iOS).
Using cargo-bundle gives us the bundle but I have not found a way to use it to code sign the binary for distribution.
I have seen xcode templates for running rust but they seem all outdated and not working well.
I feel like that might be the last bit for an end-to-end dev cycle for cacao.

Implement `writeObjects` for Pasteboard

Referencing this Stack Overflow article, the following code allows the user to copy some object (in this case, a file) to the clipboard:

NSURL *object = [[NSURL alloc] initFileURLWithPath:@"/Users/username/Desktop/main.png"];
NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb clearContents];

NSArray *objectsToCopy = [[NSArray alloc] initWithObjects:object, nil];
BOOL pasted = [pb writeObjects:objectsToCopy];

if(pasted) // paste was successful
    NSLog(@"pasted");

[object release];
[objectsToCopy release];
[pb release];

However, after reading through the documentation/the Pasteboard implementation, it does not appear that there is a straightforward way to do this by using Cacao, as there is only support for writing text to the Pasteboard (clipboard).

SplitViewController doesn't implement Layout (or super-trait ObjcAccess) - example code?

I'm impressed with what I've been able to do with cacao, thank you for the hard work you've put into this:

I'm trying to scaffold an app with the SplitViewController three column setup as a candidate for using this for one of our internal apps, and have gotten stuck on instantiating a SuperViewController in a simple test app.

If there is an example of a SplitViewController being instantiated and presented in a cacao example (or other) app. I've searched thoroughly, to no avail, but would be happy to get a referral and if it is working, I'll thank you and consider this closed and will focus on analyzing what the example did that I'm missing.

Without an example, though, here is what I tried:

mod views;

use cacao::appkit::{App, AppDelegate};
use cacao::button::Button;
use cacao::appkit::window::{Window, WindowConfig, WindowStyle};
use cacao::geometry::Rect;
use cacao::appkit::window::WindowToolbarStyle;
use cacao::foundation::NSUInteger;
use cacao::view::{SplitViewController, View};
use crate::views::sidebar_view::SidebarView;
use crate::views::content_view::ContentView;
use crate::views::detail_view::DetailView;

struct CacaoTest2 {
  window: Window,
}

impl AppDelegate for CacaoTest2 {
  fn did_finish_launching(&self) {
    self.window.show();
  }
}

fn main() {
  let button = Button::new("Click me!");
  // let main_view = MainView::default();
  let window_config = WindowConfig {
    style: (WindowStyle::Titled as NSUInteger
      | WindowStyle::Closable as NSUInteger
      | WindowStyle::Resizable as NSUInteger) as NSUInteger,
    initial_dimensions: Rect::new(0.0, 0.0, 800.0, 600.0),
    defer: false,
    toolbar_style: WindowToolbarStyle::Automatic,
  };

  let window = Window::new(window_config);
  let split_view_controller = SplitViewController::new(SidebarView::default(),
                                                       ContentView::default(),
                                                       Some(DetailView::default()));
  window.set_content_view(&split_view_controller);


  App::new("net.xdix.cacao_test_2", CacaoTest2 { window }).run();
}

I have the SidebarView, ContentView and DetailView views defined and usable as simple (just a Label) views that work on their own just fine.

I've tried embedding the SplitControllerView in an enclosing MainView, and calling add_subview(splitViewController) in the did_load() override for that MainView -- same error:

error[E0277]: the trait bound `SplitViewController<SidebarView, ContentView, DetailView>: cacao::layout::Layout` is not satisfied
   --> src/main.rs:25:36
    |
25  |       self.window.set_content_view(&split_view_controller);
    |                   ---------------- ^^^^^^^^^^^^^^^^^^^^^^ the trait `cacao::layout::Layout` is not implemented for `SplitViewController<SidebarView, ContentView, DetailView>`
    |                   |
    |                   required by a bound introduced by this call

I can upload a zip of the entire (small) project if it helps, but I'm guessing I just have a conceptual problem here in terms of the specific recipe needed for getting a SplitViewController working.

Setting window level

Is there a way to set the window level ?

If not, I was trying to understand how it can be done similar to the window style, but could you please explain how these enum values are converted to NSUInteger

WindowStyle::Borderless => 0,
WindowStyle::Titled => 1 << 0,
WindowStyle::Closable => 1 << 1,
WindowStyle::Miniaturizable => 1 << 2,
WindowStyle::Resizable => 1 << 3,
WindowStyle::UnifiedTitleAndToolbar => 1 << 12,
WindowStyle::FullScreen => 1 << 14,
WindowStyle::FullSizeContentView => 1 << 15,
WindowStyle::Utility => 1 << 4,
WindowStyle::DocModalWindow => 1 << 6,
WindowStyle::NonActivatingPanel => 1 << 7,
WindowStyle::HUDWindow => 1 << 13

NSMutableArray

Is there a particular reason why NSArray is being used, and not NSMutableArray? The pattern for NSDictionary was to use the mutable variant, and unless we're worried about the perf impact of the mutable type (which I think is negligible, especially given what this code is doing), I think that NSMutableArray should be used instead.

The only problem I foresee with this (and NSMutableDictionary has the same issue) is if a caller receives a immutable type through an API call, we cast it on the Rust side to be mutable, which means users can call insert or whatever on them.

[UISceneConfiguration isEqualToString:]: unrecognized selector error with 0.4.0-beta1

After updating to the latest Cacao version (0.4.0-beta1) I get the following runtime error:

2023-06-09 08:43:58.534893+0200 viewer-rs-ios[87147:28872615] [Assert] BUG IN CLIENT OF UIKIT: Attempting to define a mismatched UISceneSessionRole! This will be an assert in future UIKit releases! Assigning a UISceneConfiguration with role "UIWindowSceneSessionRoleApplication" for a UISceneSession with role "<UISceneConfiguration: 0x600002ecd000; name: 0x0>".
2023-06-09 08:43:58.535361+0200 viewer-rs-ios[87147:28872615] -[UISceneConfiguration isEqualToString:]: unrecognized selector sent to instance 0x600002ecd000
2023-06-09 08:43:58.538850+0200 viewer-rs-ios[87147:28872615] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UISceneConfiguration isEqualToString:]: unrecognized selector sent to instance 0x600002ecd000'
*** First throw call stack:
(
	0   CoreFoundation                      0x0000000190e7f19c __exceptionPreprocess + 176
	1   libobjc.A.dylib                     0x000000019099e4d4 objc_exception_throw + 60
	2   CoreFoundation                      0x0000000190f26178 -[NSObject(NSObject) __retain_OA] + 0
	3   CoreFoundation                      0x0000000190de7150 ___forwarding___ + 1600
	4   CoreFoundation                      0x0000000190de6a50 _CF_forwarding_prep_0 + 96
	5   UIKitCore                           0x00000001bd201470 -[UIWindowScene _allowsEventUIWindowRouting] + 76
	6   UIKitCore                           0x00000001bc766cdc -[UIScene _updateTargetOfKeyboardEventDeferringEnvironment] + 52
	7   UIKitCore                           0x00000001bc4ff05c -[UIScene initWithSession:connectionOptions:] + 1340
	8   UIKitCore                           0x00000001bc4fe7d0 -[UIWindowScene initWithSession:connectionOptions:] + 92
	9   UIKitCore                           0x00000001bc4fde7c +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 416
	10  UIKitCore                           0x00000001bc4fcab4 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 884
	11  UIKitCore                           0x00000001bc4fbd8c -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 372
	12  UIKitCore                           0x00000001bc4fbba0 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 288
	13  FrontBoardServices                  0x00000001a51cb0bc -[FBSScene _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 372
	14  FrontBoardServices                  0x00000001a51eea30 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke.102 + 120
	15  FrontBoardServices                  0x00000001a51b9cd0 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 196
	16  FrontBoardServices                  0x00000001a51ee664 __92-[FBSWorkspaceScenesClient createSceneWithIdentity:parameters:transitionContext:completion:]_block_invoke + 356
	17  libdispatch.dylib                   0x00000001053aa99c _dispatch_client_callout + 20
	18  libdispatch.dylib                   0x00000001053aed70 _dispatch_block_invoke_direct + 388
	19  FrontBoardServices                  0x00000001a51b9be4 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 48
	20  FrontBoardServices                  0x00000001a5209060 -[FBSSerialQueue _targetQueue_performNextIfPossible] + 220
	21  FrontBoardServices                  0x00000001a51b9b84 -[FBSSerialQueue _performNextFromRunLoopSource] + 28
	22  CoreFoundation                      0x0000000190e06710 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
	23  CoreFoundation                      0x0000000190e066a4 __CFRunLoopDoSource0 + 176
	24  CoreFoundation                      0x0000000190e06414 __CFRunLoopDoSources0 + 244
	25  CoreFoundation                      0x0000000190e0501c __CFRunLoopRun + 828
	26  CoreFoundation                      0x0000000190e0458c CFRunLoopRunSpecific + 612
	27  HIToolbox                           0x000000019a639df4 RunCurrentEventLoopInMode + 292
	28  HIToolbox                           0x000000019a639c30 ReceiveNextEventCommon + 648
	29  HIToolbox                           0x000000019a639988 _BlockUntilNextEventMatchingListInModeWithFilter + 76
	30  AppKit                              0x0000000194023f58 _DPSNextEvent + 636
	31  AppKit                              0x00000001940230f4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716
	32  AppKit                              0x0000000194017558 -[NSApplication run] + 464
	33  AppKit                              0x0000000193fee9a8 NSApplicationMain + 880
	34  AppKit                              0x00000001942470ec +[NSWindow _savedFrameFromString:] + 0
	35  UIKitMacHelper                      0x00000001a8434b08 UINSApplicationMain + 988
	36  UIKitCore                           0x00000001bc4e3fdc UIApplicationMain + 148
	37  viewer-rs-ios                       0x000000010430b7f8 _ZN5cacao5uikit3app20App$LT$T$C$W$C$F$GT$3run17h291a1bb9f07402c9E + 512
	38  viewer-rs-ios                       0x0000000104330bc4 _ZN5storm10standalone8platform3ios12execute_impl17hf160a36e57c1f169E + 156
	39  viewer-rs-ios                       0x000000010433d7e0 run_app + 32
	40  viewer-rs-ios                       0x00000001042fd10c main + 24
	41  dyld                                0x00000001909cff28 start + 2236
)

I have no issue when I use Cacao commit 64908e5.

Method to access the layout anchors of a view

I'd like to attempt to write some helper methods that can take a list of views that have top, leading, etc properties on them and create the layout constraints for them automatically, at least for simple cases.
Write now this doesn't seem to be doable as those properties are not exposed in a way that can be accessed with generics.
Would it be possible to add some sort of HasLayout trait that would possess methods like

fn get_top(&self)->LayoutAnchorY;

please.
I'm happy to make a PR with this if needed.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.