Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gtk + adwaita updates #735

Merged
merged 7 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
362 changes: 110 additions & 252 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ edition = "2018"
license = "MIT"

[dependencies.gtk]
version = "^0.6.6"
version = "^0.9"
package = "gtk4"
features = ["gnome_44", "blueprint"]
features = ["gnome_47", "blueprint"]

[dependencies.libadwaita]
version = "^0.4.1"
features = ["v1_2"]
version = "^0.7"
features = ["v1_6"]

[dependencies.gdk]
version = "^0.6.3"
version = "^0.9"
package = "gdk4"

[dependencies.gio]
version = "^0.17.9"
features = ["v2_60"]
version = "^0.20"
features = []

[dependencies.glib]
version = "^0.17.9"
features = ["v2_60"]
version = "^0.20"
features = []

[dependencies.librespot]
version = "0.6.0"
Expand Down Expand Up @@ -61,7 +61,7 @@ version = "3.0.1"
features = ["rt-async-io-crypto-rust"]

[dependencies]
gdk-pixbuf = "0.17.0"
gdk-pixbuf = "^0.20"
ref_filter_map = "1.0.1"
regex = "1.8.3"
async-std = "1.12.0"
Expand Down
340 changes: 105 additions & 235 deletions cargo-sources.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dev.alextren.Spot.snapshots.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"app-id": "dev.alextren.Spot",
"runtime": "org.gnome.Platform",
"runtime-version": "44",
"runtime-version": "47",
"sdk": "org.gnome.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.rust-stable"
Expand Down
2 changes: 1 addition & 1 deletion src/api/cached_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ enum SpotCacheKey<'a> {
UserPlaylists(&'a str, usize, usize),
}

impl<'a> SpotCacheKey<'a> {
impl SpotCacheKey<'_> {
fn into_raw(self) -> String {
match self {
Self::SavedAlbums(offset, limit) => format!("me_albums_{offset}_{limit}.json"),
Expand Down
12 changes: 6 additions & 6 deletions src/app/components/album/album.css
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
/* large style */

leaflet.unfolded .album .card {
navigation-split-view .album .card {
min-width: 200px;
min-height: 200px;
border-radius: 6px;
}

leaflet.unfolded .album {
navigation-split-view .album {
margin-top: 6px;
margin-bottom: 6px;
}

leaflet.unfolded .album button {
navigation-split-view .album button {
border-radius: 12px;
}
/* small style */

leaflet.folded .album .card {
navigation-split-view.collapsed .album .card {
min-width: 100px;
min-height: 100px;
border-radius: 6px;
margin-top: 0px;
margin-bottom: 0px;
}

leaflet.unfolded .album {
navigation-split-view .album {
margin-top: 0px;
margin-bottom: 0px;
}

leaflet.folded .album button {
navigation-split-view.collapsed .album button {
border-radius: 6px;
}
23 changes: 12 additions & 11 deletions src/app/components/album/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod imp {
use super::*;

#[derive(Debug, Default, CompositeTemplate)]
#[template(resource = "/dev/alextren/Spot/components/album.ui")]
#[template(file = "src/app/components/album/album.blp")]
pub struct AlbumWidget {
#[template_child]
pub album_label: TemplateChild<gtk::Label>,
Expand Down Expand Up @@ -77,8 +77,9 @@ impl AlbumWidget {
self.add_css_class("container--loaded");
}

fn set_image(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
self.imp().cover_image.set_from_pixbuf(pixbuf);
fn set_image(&self, pixbuf: &gdk_pixbuf::Pixbuf) {
let texture = gdk::Texture::for_pixbuf(pixbuf);
self.imp().cover_image.set_paintable(Some(&texture));
}

fn bind(&self, album_model: &AlbumModel, worker: Worker) {
Expand All @@ -91,8 +92,10 @@ impl AlbumWidget {
if let Some(_self) = _self.upgrade() {
let loader = ImageLoader::new();
let result = loader.load_remote(&cover_art, "jpg", 200, 200).await;
_self.set_image(result.as_ref());
_self.set_loaded();
if let Some(image) = result.as_ref() {
_self.set_image(image);
_self.set_loaded();
}
}
});
} else {
Expand All @@ -119,11 +122,9 @@ impl AlbumWidget {
}
}

pub fn connect_album_pressed<F: Fn(&Self) + 'static>(&self, f: F) {
self.imp()
.cover_btn
.connect_clicked(clone!(@weak self as _self => move |_| {
f(&_self);
}));
pub fn connect_album_pressed<F: Fn() + 'static>(&self, f: F) {
self.imp().cover_btn.connect_clicked(move |_| {
f();
});
}
}
10 changes: 4 additions & 6 deletions src/app/components/artist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,10 @@ impl ArtistWidget {
_self
}

pub fn connect_artist_pressed<F: Fn(&Self) + 'static>(&self, f: F) {
self.imp()
.avatar_btn
.connect_clicked(clone!(@weak self as _self => move |_| {
f(&_self);
}));
pub fn connect_artist_pressed<F: Fn() + 'static>(&self, f: F) {
self.imp().avatar_btn.connect_clicked(move |_| {
f();
});
}

fn bind(&self, model: &ArtistModel, worker: Worker) {
Expand Down
32 changes: 22 additions & 10 deletions src/app/components/artist_details/artist_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,18 @@ impl ArtistDetailsWidget {
{
self.imp()
.artist_releases
.bind_model(Some(store.unsafe_store()), move |item| {
.bind_model(Some(store.inner()), move |item| {
let item = item.downcast_ref::<AlbumModel>().unwrap();
let child = gtk::FlowBoxChild::new();
let album = AlbumWidget::for_model(item, worker.clone());
let f = on_album_pressed.clone();
album.connect_album_pressed(clone!(@weak item => move |_| {
f(item.uri());
}));
album.connect_album_pressed(clone!(
#[weak]
item,
move || {
f(item.uri());
}
));
child.set_child(Some(&album));
child.upcast::<gtk::Widget>()
});
Expand All @@ -115,17 +119,25 @@ impl ArtistDetails {

let widget = ArtistDetailsWidget::new();

widget.connect_bottom_edge(clone!(@weak model => move || {
model.load_more();
}));
widget.connect_bottom_edge(clone!(
#[weak]
model,
move || {
model.load_more();
}
));

if let Some(store) = model.get_list_store() {
widget.bind_artist_releases(
worker.clone(),
&store,
clone!(@weak model => move |id| {
model.open_album(id);
}),
clone!(
#[weak]
model,
move |id| {
model.open_album(id);
}
),
);
}

Expand Down
58 changes: 42 additions & 16 deletions src/app/components/details/album_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ use gtk::{glib, CompositeTemplate};

mod imp {

use std::cell::Cell;

use super::*;

#[derive(Debug, Default, CompositeTemplate)]
#[derive(Debug, Default, CompositeTemplate, glib::Properties)]
#[properties(wrapper_type = super::AlbumHeaderWidget)]
#[template(resource = "/dev/alextren/Spot/components/album_header.ui")]
pub struct AlbumHeaderWidget {
#[template_child]
Expand Down Expand Up @@ -43,6 +46,39 @@ mod imp {

#[template_child]
pub year_label: TemplateChild<gtk::Label>,

#[property(get, set = Self::set_vertical, name = "vertical-layout")]
pub vertical_layout: Cell<bool>,
}

impl AlbumHeaderWidget {
pub fn set_vertical(&self, vertical: bool) {
let self_ = self.obj();
let box_ = self_.upcast_ref::<gtk::Box>();
if vertical {
box_.set_orientation(gtk::Orientation::Vertical);
box_.set_spacing(12);
self.album_label.set_halign(gtk::Align::Center);
self.album_label.set_justify(gtk::Justification::Center);
self.artist_button.set_halign(gtk::Align::Center);
self.year_label.set_halign(gtk::Align::Center);
self.button_box.set_halign(gtk::Align::Center);
self.album_overlay.set_margin_start(0);
self.button_box.set_margin_end(0);
self.album_info.set_margin_start(0);
} else {
box_.set_orientation(gtk::Orientation::Horizontal);
box_.set_spacing(0);
self.album_label.set_halign(gtk::Align::Start);
self.album_label.set_justify(gtk::Justification::Left);
self.artist_button.set_halign(gtk::Align::Start);
self.year_label.set_halign(gtk::Align::Start);
self.button_box.set_halign(gtk::Align::Start);
self.album_overlay.set_margin_start(6);
self.button_box.set_margin_end(6);
self.album_info.set_margin_start(18);
}
}
}

#[glib::object_subclass]
Expand All @@ -61,6 +97,7 @@ mod imp {
}
}

#[glib::derived_properties]
impl ObjectImpl for AlbumHeaderWidget {}
impl WidgetImpl for AlbumHeaderWidget {}
impl BoxImpl for AlbumHeaderWidget {}
Expand Down Expand Up @@ -108,7 +145,7 @@ impl AlbumHeaderWidget {
{
self.imp().artist_button.connect_activate_link(move |_| {
f();
glib::signal::Inhibit(true)
glib::Propagation::Stop
});
}

Expand Down Expand Up @@ -138,8 +175,9 @@ impl AlbumHeaderWidget {
self.imp().play_button.set_tooltip_text(tooltip_text);
}

pub fn set_artwork(&self, art: &gdk_pixbuf::Pixbuf) {
self.imp().album_art.set_from_pixbuf(Some(art));
pub fn set_artwork(&self, pixbuf: &gdk_pixbuf::Pixbuf) {
let texture = gdk::Texture::for_pixbuf(pixbuf);
self.imp().album_art.set_paintable(Some(&texture));
}

pub fn set_album_and_artist_and_year(&self, album: &str, artist: &str, year: Option<u32>) {
Expand All @@ -151,16 +189,4 @@ impl AlbumHeaderWidget {
None => widget.year_label.set_visible(false),
}
}

pub fn set_centered(&self) {
let widget = self.imp();
widget.album_label.set_halign(gtk::Align::Center);
widget.album_label.set_justify(gtk::Justification::Center);
widget.artist_button.set_halign(gtk::Align::Center);
widget.year_label.set_halign(gtk::Align::Center);
widget.button_box.set_halign(gtk::Align::Center);
widget.album_overlay.set_margin_start(0);
widget.button_box.set_margin_end(0);
widget.album_info.set_margin_start(0);
}
}
30 changes: 14 additions & 16 deletions src/app/components/details/details.blp
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,31 @@ template $AlbumDetailsWidget : Adw.Bin {
vexpand: true;
hexpand: true;

$HeaderBarWidget headerbar {
}
$HeaderBarWidget headerbar {}

$ScrollingHeaderWidget scrolling_header {
[header]
WindowHandle {
Adw.Clamp {
maximum-size: 900;
styles [
"details__clamp",
]

Adw.Squeezer {
switch-threshold-policy: natural;
valign: center;
homogeneous: false;
transition-type: crossfade;
Adw.BreakpointBin {
width-request: 1;
height-request: 1;

$AlbumHeaderWidget header_widget {
}
Adw.Breakpoint {
condition("max-width:500sp")

$AlbumHeaderWidget header_mobile {
orientation: "vertical";
spacing: "12";
setters {
header_widget.vertical-layout: true;
}
}
}

styles [
"details__clamp",
]
$AlbumHeaderWidget header_widget {}
}
}
}

Expand Down
Loading
Loading