Set up a reflowing layout for the cards

This commit is contained in:
Savanni D'Gerinel 2023-08-19 19:41:29 -04:00
parent e203b17c8b
commit 5478d388cb
4 changed files with 9 additions and 14 deletions

View File

@ -13,7 +13,7 @@ futures = { version = "0.3" }
gio = { version = "0.17" }
glib = { version = "0.17" }
gdk = { version = "0.6", package = "gdk4" }
gtk = { version = "0.6", package = "gtk4" }
gtk = { version = "0.6", package = "gtk4", features = [ "v4_6" ] }
serde = { version = "1" }
serde_json = { version = "*" }
tokio = { version = "1", features = ["full"] }

View File

@ -1,4 +1,6 @@
.playlist-card {
margin: 8px;
padding: 8px;
min-width: 100px;
min-height: 100px;
}

View File

@ -7,7 +7,7 @@ use std::iter::Iterator;
#[derive(Clone)]
pub struct ApplicationWindow {
pub window: adw::ApplicationWindow,
pub grid: gtk::Grid,
pub layout: gtk::FlowBox,
pub playlists: Vec<PlaylistCard>,
}
@ -16,6 +16,7 @@ impl ApplicationWindow {
let window = adw::ApplicationWindow::builder()
.application(app)
.title("GM-control-panel")
.width_request(500)
.build();
let stylesheet = String::from_utf8(
@ -33,7 +34,7 @@ impl ApplicationWindow {
let context = window.style_context();
context.add_provider(&provider, STYLE_PROVIDER_PRIORITY_USER);
let grid = gtk::Grid::new();
let layout = gtk::FlowBox::new();
let playlists: Vec<PlaylistCard> = vec![
"Creepy Cathedral",
@ -50,15 +51,13 @@ impl ApplicationWindow {
})
.collect();
playlists.iter().enumerate().for_each(|(i, card)| {
grid.attach(card, 0, i as i32, 1, 1);
});
playlists.iter().for_each(|card| layout.append(card));
window.set_content(Some(&grid));
window.set_content(Some(&layout));
Self {
window,
grid,
layout,
playlists,
}
}

View File

@ -37,12 +37,6 @@ impl PlaylistCard {
s.set_orientation(gtk::Orientation::Vertical);
s.add_css_class("playlist-card");
s.add_css_class("card");
/*
s.set_margin_start(8);
s.set_margin_end(8);
s.set_margin_top(8);
s.set_margin_bottom(8);
*/
s.append(&s.imp().name);
s.append(&s.imp().playing);