Custom Resources
Include additional resources with your app like icons or CSS files using GResource
Last updated
Was this helpful?
Include additional resources with your app like icons or CSS files using GResource
Last updated
Was this helpful?
When using GResource, custom resource files will be compiled into your app's binary, ensuring they're available and loaded when your app launches. Regardless of which type of resource you'd like to include, you'll need to create a gresource.xml
file and include it in your build system.
Make sure to start with a Gtk.Application
as described in the . In the data
directory, create a new file called gresource.xml
like the one below. Then update your meson build file to include steps to build the resource into your binary. Make sure to update the resource prefix to match your app's RDNN.
Now that we have a gresource.xml
file and have included it in the build system, we can add files and reference them in our app.
You can provide custom icons and have your app automatically refer to them by name and choose the correct size by adding them your Gresource file under the namespace /icons
. For this to work properly, your resource path must match your application's ID.
Add a custom icon to the data
directory, and then update your gresource.xml
file to reference it:
If you want to use the same icon name in multiple sizes in your app, you can alias
the icon to paths in and GTK will automatically load the correct version when its size is referenced:
The last step is to create a Gtk.Image or Gtk.Button using your custom icon and add it to the main window:
When creating icons, it is important to know which sizes will be used and to design and hint the icon at that size. For more information about creating and hinting icons, check out the .