slint-ui / slint

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

`@image-url()` with URL working in SlintPad produces insubstantial error message in local build, and is silent in preview #6412

Closed Enyium closed 1 month ago

Enyium commented 1 month ago

The docs page "Syntax > Types > Images" has an example that works in SlintPad when you click "Edit" below the example. But when I copy it under Windows 10 into a Rust project with Slint (not matter whether FemtoVG or Skia), it produces the following error message through build.rs's slint_build::compile():

C:\...\slint-test\ui\app-window.slint:7: Cannot find image file https://slint.dev/logo/slint-logo-full-light.svg

It isn't clear why running the example in SlintPad and locally should differ in behavior. If local builds have a limitation regarding URLs, the message should reflect this and lead the developer on their way to understand the reasons and background better.


Also, the error is silent in the preview window shown via "Show Preview" from the VS Code editor. It just shows:

silent-error

Whereas SlintPad shows:

working

ogoffart commented 1 month ago

This was already reported: https://github.com/slint-ui/slint/issues/4132

slintpad runs on the browser and can load image from the network, while the slint compiler is not fetching files from the network, neither the slint runtime.

The docs are also rendered with the wasm interpreter, and it's an easy way to do preview.

Enyium commented 1 month ago

@ogoffart: The console showing an error message, but the preview window not, isn't a bug?!

And SlintPad being able to load files from the network has to do with it using the interpreter?

hunger commented 1 month ago

Yes, Slintpad uses the interpreter internally. No, that has nothing to do with Slintpad being able to load images from URLs:-)

Slintpad runs WASm code, and WASM has no access to any filesystem at all. So we needed to hack something there to load get any data into the interpreter... that hack forwards load requests to the browser and browsers happen to be really good at loading things from the web. It's more an implementation detail than a planned feature ;-)

Enyium commented 1 month ago

But don't you think it's confusing to first see @image-url("https://... in the docs, and then not being able to make use of it? I think this should be mentioned in the docs and in the console error message. And the local preview should show the error message also.

hunger commented 1 month ago

I agree: This is confusing. Most of the time its a relative path, so it is hard to tell whether its a URL or a file path, so we do get away with it rather often.

But yes, that is a problem. The preview and Slintpad should be as close as possible to the "normal" compiler.