I am having some trouble loading additional icons into a IconTheme
. At the moment my code is adding the path which is showing correctly with search_path()
however it always returns false when I check for an image with has_icon()
. Are there any examples of how to do this in Rust anyone knows about?
I have found a bunch of documentation on this in C but I'm struggling to translate it over. I have looked at this, this and this so far but if there are better examples that would help a lot.
This is how I am trying to add and search for the images at the moment which compiles but can't find the images.
use gtk::prelude::*;
use gtk::gdk::Display;
use adw::{Application, ApplicationWindow};
use std::path::PathBuf;
const APP_ID: &str = "org.test.app";
fn main() {
let app = Application::builder().application_id(APP_ID).build();
app.connect_startup(|_| load_images());
app.connect_activate(build_ui);
app.run();
}
fn load_images() {
let mut icon_path = PathBuf::new();
icon_path.push("/home/user/Projects/test_app/src/Icons");
let icons = gtk::IconTheme::for_display(&Display::default().expect("Could not connect to a display."));
icons.add_search_path(icon_path);
println!("IconTheme.name = {:?}", icons.theme_name());
println!("IconTheme.search_path() = {:?}", icons.search_path()); // The search path is showing the dir containing the icon.
println!("IconTheme.has_icon(\"test_icon.png\") = {}", icons.has_icon("test_icon.png")); // Returns false.
}
pub fn build_ui(app: &Application) {
let window = ApplicationWindow::builder()
.application(app)
.title("test_app")
.default_width(360)
.default_height(720)
.build();
window.present();
}