I have the image in the Struct of window.rs, I was looking for a way to change the path of the image without creating a new widget from scratch. But if new_from_file is the only way it’s ok
(Edit: I found that gtk::Image::set_from_file() works, unfortunately tha path works only if I pass the absolute one. Is there a way to pass as a parameter the relative path of the image, like: “data/images/5-Spade.png” )
If by “data directory” you mean “/usr/share” or similar (the exact path may depend on the distro, in flatpak it will be “/app/share”), then you can get it programmatically with GLib.get_system_data_dirs
the data directory I meant was the directory inside the project structure that gnome-builder creates for every new project. so <Project_Path>/data/images/image.png. And I need to ask if I can use paths or I need to link the image into the binary during the build or during the export phase
If you need a reliable way to find the images, you can either:
link them directly into the binary using gresources, and set the image with Gtk.Image.set_from_resource (“resource://virtual/path/to/image.png”)
configure meson to install the images under get_option('prefix') / get_option('datadir') / meson.project_name() / image.png, then use GLib.get_system_data_dirs to lookup for them
The 1st option is more reliable but will increase the binary size. Typically used for small/mid-sized images that always/often need to be loaded.
The 2nd option is better suited for bigger images that only need to be loaded on demand.