ryanmcgrath / cacao

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

Standard macOS event handlers for TextField #5

Closed MerlinDE closed 3 years ago

MerlinDE commented 3 years ago

Added

For now these only take the value from the TextField and hand it over as a String.

@ryanmcgrath Hope this doesn't create any races/incompatibilities with your central notification center implementation.

ryanmcgrath commented 3 years ago

This is probably perfect, haha - I needed these myself but hadn’t gotten around to adding them.

I need to push my (...big, but shouldn’t be breaking for you) changes to get things in sync here. Maybe my Sunday night project.

On Sun, Mar 14, 2021 at 09:55, Alexander Czernay @.***> wrote:

Added

  • text_should_begin_editing()
  • text_did_begin_editing()
  • text_did_change()
  • text_should_end_editing()
  • text_did_end_editing() event handlers.

For now these only take the value from the TextField and hand it over as a String.

@.***(https://github.com/ryanmcgrath) Hope this doesn't create any races/incompatibilities with your central notification center implementation.


You can view, comment on, or merge this pull request online at:

https://github.com/ryanmcgrath/cacao/pull/5

Commit Summary

  • Standard macOS event handlers for TextField

File Changes

Patch Links:

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

ryanmcgrath commented 3 years ago

Hmmm, so looking at this, one thing I think we should consider changing - rather than doing to_string() in the extern fn, call the trait method with the &str reference and let the implementor allocate if they need or want to. I believe with the current approach, a stock input label with delegate would allocate a string on every event.

MerlinDE commented 3 years ago

If we can be sure that the &str remains stable in memory it makes perfect sense. I'm not experienced enough with Cocoa to judge on this — especially within a callback that might run in a separate thread AFAIU. Happy to try, though. :)

ryanmcgrath commented 3 years ago

I'd think it's stable for that call point, but the remark about it potentially running in a separate thread makes me pause, haha...

Is there some documentation (I know I'm asking for Cocoa-specific docs, so the answer may be a resounding "nope"...) that indicates this can happen? I've never experienced it, but very open to being misinformed here.

ryanmcgrath commented 3 years ago

(I can dig further on this and see what I can come up with)

MerlinDE commented 3 years ago

I‘m afraid I misinterpreted some of your code in regards to having it running in a separate thread. Let’s just go with the &str.

ryanmcgrath commented 3 years ago

Going ahead and merging this, will alter the &str bit in my next push. Really appreciate it!