slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
16.95k stars 568 forks source link

Callbacks only detected when they are added to rust first then slint #4840

Closed Oevin7 closed 2 months ago

Oevin7 commented 6 months ago

I am on Zorin OS and I am using rust with slint on VS Codium.

So when I add a new callback to slint first and then write it in rust, rust throws an error saying the callback does not exsist in the struct. However when I do it the other way around and write it in rust and then slint it works.

so if I write: callback reset-counter(); and then I go to write the functionality in rust say: ui.on_reset_counter(move || {});

rust throws the error.

If I then remove callback reset-counter(); and then paste it back into the slint file rust will fix the error. I'm not sure this is intended and it did throw me off a bit as I am trying to learn slint to make UI apps in rust.

ogoffart commented 6 months ago

Thanks for reporting a bug. What error exactly does it throws? Could you paste the complete source code as well as the error?

Oevin7 commented 6 months ago

Thanks for reporting a bug. What error exactly does it throws? Could you paste the complete source code as well as the error?

This is the error I recieve: no method named on_remove_text found for struct AppWindow in the current scope method not found in AppWindow

I made a new callback called: callback remove-text(); and then I made my rust code as such

main_window.on_remove_text(move || { //code goes here. });

I made the callback in slint first and it threw me the error. However, when I delete the slint callback and move it to a different line the error goes away.

After you create the callback it doesn't matter if it is deleted from slint and rust. It will work in whatever order, but on your first attemt to create the method it has to be done in rust first. I tried recreating it and it wouldn't work for my already created callbacks, so I had to make a new one and the same error appeared.

Thank you for the quick response!

ogoffart commented 6 months ago

What is the error? Are you talking about a Rust error or a Slint error? Given by the LSP or rust-analyzer or the compiler? Are you using the slint! macro or a custom build? What is your editor?

It's possible that it just take time for the build script to update and that is just a temporary error. If that's the case, there is not much we can do i'm afraid.

Oevin7 commented 6 months ago

I was using VSCodium with the slint plugin. In my rust project I was creating the logic for a simple project I was making to understand callbacks. It was a remake of the counter. What I did was make the callback in slint. I was making a decrease callback.

callback decrease;

when i put that code into rust as such main_window.on_decrease(move || {

});

It threw an error telling me decrease was not in the slint file. I went back into the slint file, deleted the callback and pasted it to a different line and rust recognized the callback.

I was saying I couldn't reproduce the error with the same callback. I had to create a new callback to replicate the error. If I make the callback in slint and then try to give it logic in rust I get the error if it is a new callback.

I might have done something wrong, I am new to all this and trying to learn lol. I also don't report much on github so I'm sorry if I wasn't clear enough.

I don't know if it was an update for the build script? I kept saving the file once I wrote the script. The error only went away once I removed and added the callback on a different line. I had slint in a seperate ui folder with the code in my main rust folder. I could be doing something wrong, but it seemed like weird behaviour.

ogoffart commented 6 months ago

Could you please post a screenshot so i can see exactly what error that is?

Oevin7 commented 2 months ago

Hey! I'm so sorry! I've been really busy the past few months and haven't had time to respond. I also never got a notification for this. I did just realize now I may have been dumb lol. I am very sorry fore the trouble! I was using VsCodium and I am not used to having to save beforehand as I usually use a JetBrains IDE. Therefore, I had to save the Rust file before I could access the new callback. It was my lack of understanding rather than a bug! I'm sorry for all the trouble and being a pain. Anywho you guys have a cool project and I can't wait to keep learning how to use it :)

ogoffart commented 2 months ago

Thank you. Closing this issue then.