sciter-sdk / rust-sciter

Rust bindings for Sciter
https://sciter.com
MIT License
804 stars 76 forks source link

Implementation of fire_event #9

Closed a-nigredo closed 7 years ago

a-nigredo commented 7 years ago

Hi, @pravic. When are you gonna implement fire_event function for Element?

pravic commented 7 years ago

Not only fire_event, actually, need to add much more functions.

a-nigredo commented 7 years ago

ok, I see. Do you have an estimation?

pravic commented 7 years ago

Do you want to make a pull request for it?

a-nigredo commented 7 years ago

I'll try but can't guarantee that I'll be able to manage it since I'm newbie in Rust.

a-nigredo commented 7 years ago

@pravic I've started implementing and have questions about the next signatures: pub SciterSendEvent: extern "system" fn (he: HELEMENT, appEventCode: UINT, heSource: HELEMENT, reason: UINT_PTR, /*out*/ handled: * mut BOOL) -> SCDOM_RESULT, pub SciterFireEvent: extern "system" fn (evt: * const BEHAVIOR_EVENT_PARAMS, post: BOOL, handled: * mut BOOL) -> SCDOM_RESULT,

Why do we need raw mutable pointers for variable "handled"?

pravic commented 7 years ago

Check this doc if I understand your question correctly.

a-nigredo commented 7 years ago

@pravic I'm talking about type of variable handled. Why is it *mut? it might be just bool type I guess.

pravic commented 7 years ago

Because of /*out*/ BOOL* handled - it is out argument.

Also I can't create mut pointer for boolean type is Rust.

let mut handled = false as BOOL;
let params = BEHAVIOR_EVENT_PARAMS::default();
let ok = SciterFireEvent(&params, false as BOOL, &mut handled);
if ok == SCDOM_RESULT::OK && handled {
  // no error and behavior event was handled by element
}
pravic commented 7 years ago

Done in this and this commits.

However I found that send event feature mixes source and target elements, asked about it here: http://sciter.com/forums/topic/confusing-scitersendevent-k/.

pravic commented 7 years ago

But in general, why do you need this functionality in native code? Its easier (and better) to work with DOM via script, which can ask the native app about data and notify it about events.

a-nigredo commented 7 years ago

A goal was studying Rust by implementing desktop application for company's backend system but finally I use script;)

pravic commented 7 years ago

You can study it providing high-level logic and data in app, leaving UI-related operations to UI level.

That DOM API in Sciter - legacy (and compatibility) from HTMLayout (the successor of Sciter), where you managed UI things from native code only.

a-nigredo commented 7 years ago

yeap, that's why I migrate to tiscript

pravic commented 7 years ago

Enjoy then :)