use crate::PlaylistCard; use adw::prelude::AdwApplicationWindowExt; use gio::resources_lookup_data; use gtk::{prelude::*, STYLE_PROVIDER_PRIORITY_USER}; use std::iter::Iterator; #[derive(Clone)] pub struct ApplicationWindow { pub window: adw::ApplicationWindow, pub grid: gtk::Grid, pub playlists: Vec, } impl ApplicationWindow { pub fn new(app: &adw::Application) -> Self { let window = adw::ApplicationWindow::new(app); let stylesheet = String::from_utf8( resources_lookup_data( "/com/luminescent-dreams/gm-control-panel/style.css", gio::ResourceLookupFlags::NONE, ) .expect("stylesheet should just be available") .to_vec(), ) .expect("to parse stylesheet"); let provider = gtk::CssProvider::new(); provider.load_from_data(&stylesheet); let context = window.style_context(); context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER); let grid = gtk::Grid::new(); let playlists: Vec = vec![ "Creepy Cathedral", "Joyful Tavern", "Exploring", "Out on the streets", "The North Abbey", ] .into_iter() .map(|name| { let playlist = PlaylistCard::new(); playlist.set_name(name); playlist }) .collect(); playlists.iter().enumerate().for_each(|(i, card)| { grid.attach(card, 0, i as i32, 1, 1); }); window.set_content(Some(&grid)); Self { window, grid, playlists, } } }