gtk-rs / gtk

DEPRECATED, use https://github.com/gtk-rs/gtk3-rs repository instead!
https://gtk-rs.org/
MIT License
1.24k stars 82 forks source link

How to validate input of entry #1006

Closed DBLouis closed 4 years ago

DBLouis commented 4 years ago

How would you implement input validation on an entry widget? I found an this example in C and try to do the same in Rust. I am struggling with signal_handler_block and signal_handler_unblock because I don't know how to get the SignalHandlerId.

sdroege commented 4 years ago

The connect_blablabla() functions return the SignalHandlerId that you can use for this.

DBLouis commented 4 years ago

Ok but this kind of a vicious circle because I need the SignalHandlerId in the closure that I connect.

sdroege commented 4 years ago

Those things are annoying. You could store it in a Rc<RefCell<Option<SignalHandlerId>>> outside the closure (or in some other way in your application state), and pass a reference to that into the signal handler closure to get access to it.

DBLouis commented 4 years ago

I guess there is no other way. Is g_signal_handlers_block_by_func could be made available eventually?

sdroege commented 4 years ago

No as you don't have access to the function parameter you'd pass there. It's a private function specific to the closure you pass in, your closure (but boxed) becomes the user data.

DBLouis commented 4 years ago

Ok thank you