christolliday / limn

Experimental cross platform GUI library
Other
404 stars 19 forks source link

Stop hard-coding paths to images #42

Closed fschutt closed 6 years ago

fschutt commented 6 years ago

This is a fairly annoying issue: Currently the only way to add images is by using the limn::widgets::image::Image. This is hard-coded to use images from the ./assets/images/[myimage.png] if you pass in Image::new("myimage.png"). The reason it is bad to hard-code strings like this is because it is relative to the working directory from which the application was executed. It is very likely that the path ./assets/ will not be found, just because the working directory wasn't set correctly.

Another optimization is to use sprites (with offsets into the image) instead of using seperate images for each icon. So my proposal would be:

jaroslaw-weber commented 6 years ago

you mean using texture as atlases? good idea.

we should get rid of assets path, yes. everything should be embedded inside the binary file, just like unity3d is doing it.

fschutt commented 6 years ago

It doesn't have to be embedded, but just give me control over where the images come from - from disk, from memory, from the binary, from a network ...

christolliday commented 6 years ago

I actually started working on loading from alternate paths a few days ago along with some other refactoring, the assets path was never intended to be used for any reason other than quick convenience.

For some parts of your proposal, the best way may be to implement it might be as an alternate draw state, at least for a start. Taking that approach you can implement it in an external application, source images from wherever you want, use your own resource management etc. I absolutely encourage people to do this by the way, that is, create components, work out the kinks then merge it back into the core if it makes sense.

As far as the optimization you are describing, before attempting anything like that I'd like to first perform some basic optimization of how webrender is used, and then have some basic benchmarks in place.

Anyway back to the main issue of hard coding paths, my plan is to replace image names in ImageState with an ImageDescriptor, and move the image loading parts of resources into a separate struct owned by resources called ImageLoader.

ImageDescriptor will be an enum that can store:

ImageLoader then will let you:

christolliday commented 6 years ago

Made a PR, ended up going with ImageSource instead of ImageDescriptor