ryanmcgrath / cacao

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

TextField not on edit mode at window opening #106

Open jimmy-hypi opened 9 months ago

jimmy-hypi commented 9 months ago

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

ryanmcgrath commented 9 months ago

You probably need to call [window makeFirstResponder:nil] (which we need to add on the Window in appkit) or you could try programmatically calling resignFirstResponder to hack around it for now.

e.g (pseudocode, you'll want to use the with_ accessor to get the native handle):

unsafe {
    let _: () = msg_send![native_handle, resignFirstResponder];
}

If that works, feel free to PR one (or both) to the library - they should be straightforward-ish to handle. I can't merge it until another PR is in, but this change shouldn't be interfering with it so it'd be nice to have lined up.

Hope it helps!

jimmy-hypi commented 9 months ago

Unfortunately I'm afraid I'm not familiar enough with the framework to be able to make useful changes. In particular, I'm not sure where to call the code you suggested. To the best of my understanding, using resignFirstResponder the native handle should be the TextField handle right? All the changes that I'm trying to apply are just ignored. But again, quite a trial and error as I have very little clue of what I'm doing.