Skip to content

Commit

Permalink
wip gtk adwaita bump
Browse files Browse the repository at this point in the history
  • Loading branch information
xou816 committed Nov 27, 2024
1 parent c5a5349 commit 292f17b
Show file tree
Hide file tree
Showing 50 changed files with 540 additions and 579 deletions.
213 changes: 112 additions & 101 deletions Cargo.lock

Large diffs are not rendered by default.

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

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

[dependencies.libadwaita]
version = "^0.4.1"
features = ["v1_2"]
version = "^0.5"
features = ["v1_4"]

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

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

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

[dependencies.librespot]
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.18"
ref_filter_map = "1.0.1"
regex = "1.8.3"
async-std = "1.12.0"
Expand Down
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
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;
}
13 changes: 8 additions & 5 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_from_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 Down
2 changes: 1 addition & 1 deletion src/app/components/artist_details/artist_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ 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());
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_from_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
37 changes: 13 additions & 24 deletions src/app/components/details/details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ mod imp {
#[template_child]
pub header_widget: TemplateChild<AlbumHeaderWidget>,

#[template_child]
pub header_mobile: TemplateChild<AlbumHeaderWidget>,

#[template_child]
pub album_tracks: TemplateChild<gtk::ListView>,
}
Expand All @@ -58,7 +55,7 @@ mod imp {
impl ObjectImpl for AlbumDetailsWidget {
fn constructed(&self) {
self.parent_constructed();
self.header_mobile.set_centered();
// self.header_mobile.set_centered();
self.headerbar.add_classes(&["details__headerbar"]);
}
}
Expand Down Expand Up @@ -118,59 +115,49 @@ impl AlbumDetailsWidget {

fn connect_liked<F>(&self, f: F)
where
F: Fn() + Clone + 'static,
F: Fn() + 'static,
{
self.imp().header_widget.connect_liked(f.clone());
self.imp().header_mobile.connect_liked(f);
self.imp().header_widget.connect_liked(f);
}

fn connect_play<F>(&self, f: F)
where
F: Fn() + Clone + 'static,
F: Fn() + 'static,
{
self.imp().header_widget.connect_play(f.clone());
self.imp().header_mobile.connect_play(f);
self.imp().header_widget.connect_play(f);
}

fn connect_info<F>(&self, f: F)
where
F: Fn() + Clone + 'static,
F: Fn() + 'static,
{
self.imp().header_widget.connect_info(f.clone());
self.imp().header_mobile.connect_info(f);
self.imp().header_widget.connect_info(f);
}

fn set_liked(&self, is_liked: bool) {
self.imp().header_widget.set_liked(is_liked);
self.imp().header_mobile.set_liked(is_liked);
}

fn set_playing(&self, is_playing: bool) {
self.imp().header_widget.set_playing(is_playing);
self.imp().header_mobile.set_playing(is_playing);
}

fn set_album_and_artist_and_year(&self, album: &str, artist: &str, year: Option<u32>) {
self.imp()
.header_widget
.set_album_and_artist_and_year(album, artist, year);
self.imp()
.header_mobile
.set_album_and_artist_and_year(album, artist, year);
self.imp().headerbar.set_title_and_subtitle(album, artist);
}

fn set_artwork(&self, art: &gdk_pixbuf::Pixbuf) {
self.imp().header_widget.set_artwork(art);
self.imp().header_mobile.set_artwork(art);
}

fn connect_artist_clicked<F>(&self, f: F)
where
F: Fn() + Clone + 'static,
F: Fn() + 'static,
{
self.imp().header_widget.connect_artist_clicked(f.clone());
self.imp().header_mobile.connect_artist_clicked(f);
self.imp().header_widget.connect_artist_clicked(f);
}
}

Expand All @@ -183,7 +170,10 @@ pub struct Details {
}

impl Details {
pub fn new(model: Rc<DetailsModel>, worker: Worker, leaflet: &libadwaita::Leaflet) -> Self {
pub fn new(
model: Rc<DetailsModel>,
worker: Worker,
) -> Self {
if model.get_album_info().is_none() {
model.load_album_info();
}
Expand All @@ -197,7 +187,6 @@ impl Details {
));

let headerbar_widget = widget.headerbar_widget();
headerbar_widget.bind_to_leaflet(leaflet);
let headerbar = Box::new(HeaderBarComponent::new(
headerbar_widget.clone(),
model.to_headerbar_model(),
Expand Down
Loading

0 comments on commit 292f17b

Please sign in to comment.