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.71k stars 614 forks source link

Add support for loading images from the network #3279

Open aniceking99 opened 1 year ago

aniceking99 commented 1 year ago

The load_from_path method in the Image API can load local images. How can we load network images?

tronical commented 1 year ago

At the moment this is not supported by Slint out of the box. It is however something that we'd like to support in the future. To my surprise there's no tracking issue for this yet - so this one will be it :)

ogoffart commented 1 year ago

The way to do it now is using a crate like reqwest to download the data, and then either load the temporary file, or use the image crate to generate an image that can be loaded into slint

SO9010 commented 1 week ago

Hello, are there any updates on this? I’d be happy to explore implementing this feature into Slint, as I believe it could provide significant benefits for many projects, particularly those with dynamic content requirements. Let me know if this is something you'd like me to work on or if there are any specific guidelines I should follow.

tronical commented 1 week ago

What I could imagine is an opt-in feature in Slint to permit image URL, including API to construct a slint::Image from a url at run-time. The main caveats that I can see:

Those aren't blockers, just something to keep in the back of the mind.

Implementation wise I think a single image loading thread should suffice. I wouldn't go beyond that. So if it's possible to combine reqwest, as Olivier suggested, with smol (that uses a single thread), then I think that would be good compromise.

I wonder if I'm missing something. cc @ogoffart for additional input :)