Skip to content

Commit

Permalink
more leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
xou816 committed Feb 13, 2023
1 parent 4688c90 commit d10a482
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 46 deletions.
47 changes: 31 additions & 16 deletions src/app/components/playlist_details/playlist_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,23 @@ impl PlaylistDetailsWidget {
self.imp().scrolling_header.connect_bottom_edge(f);
}

fn set_header_visible(&self, visible: bool) {
let widget = self.imp();
widget.headerbar.set_title_visible(true);
if visible {
widget.headerbar.add_classes(&["flat"]);
} else {
widget.headerbar.remove_classes(&["flat"]);
}
}

fn connect_header(&self) {
self.imp()
.scrolling_header
.connect_header_visibility(|_| {});
self.set_header_visible(false);
self.imp().scrolling_header.connect_header_visibility(
clone!(@weak self as _self => move |visible| {
_self.set_header_visible(visible);
}),
);
}

fn set_loaded(&self) {
Expand All @@ -111,26 +124,22 @@ impl PlaylistDetailsWidget {
self.imp().headerbar.set_editable(editing);
}

fn set_album_and_artist(&self, album: &str, artist: &str) {
self.imp()
.header_widget
.set_album_and_artist_and_year(album, artist, None);
self.imp()
.header_mobile
.set_album_and_artist_and_year(album, artist, None);
fn set_info(&self, playlist: &str, owner: &str) {
self.imp().header_widget.set_info(playlist, owner);
self.imp().header_mobile.set_info(playlist, owner);
}

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)
fn connect_owner_clicked<F>(&self, f: F)
where
F: Fn() + Clone + 'static,
{
self.imp().header_widget.connect_artist_clicked(f.clone());
self.imp().header_mobile.connect_artist_clicked(f);
self.imp().header_widget.connect_owner_clicked(f.clone());
self.imp().header_mobile.connect_owner_clicked(f);
}

pub fn connect_edit<F>(&self, f: F)
Expand All @@ -144,7 +153,13 @@ impl PlaylistDetailsWidget {
where
F: Fn() + 'static,
{
self.imp().headerbar.connect_cancel(f);
self.imp()
.headerbar
.connect_cancel(clone!(@weak self as _self => move || {
_self.imp().header_widget.reset_playlist_name();
_self.imp().header_mobile.reset_playlist_name();
f();
}));
}

pub fn connect_done<F>(&self, f: F)
Expand Down Expand Up @@ -195,7 +210,7 @@ impl PlaylistDetails {
model.load_more_tracks();
}));

widget.connect_artist_clicked(clone!(@weak model => move || model.view_owner()));
widget.connect_owner_clicked(clone!(@weak model => move || model.view_owner()));

widget.connect_edit(clone!(@weak model => move || {
model.enable_selection();
Expand Down Expand Up @@ -223,7 +238,7 @@ impl PlaylistDetails {
let owner = &info.owner.display_name[..];
let art_url = info.art.as_ref();

self.widget.set_album_and_artist(title, owner);
self.widget.set_info(title, owner);

if let Some(art_url) = art_url.cloned() {
let widget = self.widget.downgrade();
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/playlist_details/playlist_details.ui
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</object>
</child>
<style>
<class name="_details__clamp" />
<class name="playlist_details__clamp" />
</style>
</object>
</child>
Expand Down
22 changes: 22 additions & 0 deletions src/app/components/playlist_details/playlist_header.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,26 @@
margin-top: 18px;
margin-left: 6px;
margin-bottom: 6px;
}

clamp.playlist_details__clamp {
background-color: @view_bg_color;
box-shadow: inset 0px -1px 0px @borders;
}

headerbar.playlist_details__headerbar {
transition: background-color .3s ease;
}

headerbar.flat.playlist_details__headerbar windowtitle {
opacity: 0;
}

headerbar.playlist_details__headerbar windowtitle {
transition: opacity .3s ease;
opacity: 1;
}

.playlist_details__headerbar.flat {
background-color: @view_bg_color;
}
58 changes: 45 additions & 13 deletions src/app/components/playlist_details/playlist_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ const CSS_RO_ENTRY: &str = "playlist__title-entry--ro";

mod imp {

use std::cell::RefCell;
use std::convert::TryFrom;

use glib::{ParamSpec, Properties};

use super::*;

#[derive(Debug, Default, CompositeTemplate)]
#[derive(Debug, Default, CompositeTemplate, Properties)]
#[template(resource = "/dev/alextren/Spot/components/playlist_header.ui")]
#[properties(wrapper_type = super::PlaylistHeaderWidget)]
pub struct PlaylistHeaderWidget {
#[template_child]
pub playlist_label_entry: TemplateChild<gtk::Entry>,
Expand All @@ -27,8 +33,8 @@ mod imp {
#[template_child]
pub author_button_label: TemplateChild<gtk::Label>,

#[template_child]
pub year_label: TemplateChild<gtk::Label>,
#[property(get, set, name = "original-entry-text")]
pub original_entry_text: RefCell<String>,
}

#[glib::object_subclass]
Expand All @@ -47,7 +53,30 @@ mod imp {
}
}

impl ObjectImpl for PlaylistHeaderWidget {}
impl ObjectImpl for PlaylistHeaderWidget {
fn properties() -> &'static [ParamSpec] {
Self::derived_properties()
}

fn set_property(&self, id: usize, value: &glib::Value, pspec: &glib::ParamSpec) {
self.derived_set_property(id, value, pspec);
}

fn property(&self, id: usize, pspec: &glib::ParamSpec) -> glib::Value {
self.derived_property(id, pspec)
}

fn constructed(&self) {
self.parent_constructed();
let entry: &gtk::Entry = &self.playlist_label_entry;
entry
.bind_property("text", entry, "width-chars")
.transform_to(|_, text: &str| Some(text.len() as i32))
.flags(glib::BindingFlags::DEFAULT | glib::BindingFlags::SYNC_CREATE)
.build();
}
}

impl WidgetImpl for PlaylistHeaderWidget {}
impl BoxImpl for PlaylistHeaderWidget {}
}
Expand All @@ -61,7 +90,7 @@ impl PlaylistHeaderWidget {
glib::Object::new()
}

pub fn connect_artist_clicked<F>(&self, f: F)
pub fn connect_owner_clicked<F>(&self, f: F)
where
F: Fn() + 'static,
{
Expand All @@ -71,6 +100,12 @@ impl PlaylistHeaderWidget {
});
}

pub fn reset_playlist_name(&self) {
self.imp()
.playlist_label_entry
.set_text(&self.original_entry_text());
}

pub fn get_edited_playlist_name(&self) -> String {
self.imp().playlist_label_entry.text().to_string()
}
Expand All @@ -79,17 +114,14 @@ impl PlaylistHeaderWidget {
self.imp().playlist_art.set_from_pixbuf(Some(art));
}

pub fn set_album_and_artist_and_year(&self, album: &str, artist: &str, year: Option<u32>) {
pub fn set_info(&self, playlist: &str, owner: &str) {
let widget = self.imp();
widget.playlist_label_entry.set_text(album);
self.set_original_entry_text(playlist);
widget.playlist_label_entry.set_text(playlist);
widget
.playlist_label_entry
.set_placeholder_text(Some(album));
widget.author_button_label.set_label(artist);
match year {
Some(year) => widget.year_label.set_label(&year.to_string()),
None => widget.year_label.hide(),
}
.set_placeholder_text(Some(playlist));
widget.author_button_label.set_label(owner);
}

pub fn set_centered(&self) {
Expand Down
16 changes: 1 addition & 15 deletions src/app/components/playlist_details/playlist_header.ui
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<property name="spacing">6</property>
<child>
<object class="GtkEntry" id="playlist_label_entry">
<property name="hexpand">0</property>
<property name="hexpand">1</property>
<property name="halign">start</property>
<property name="editable">0</property>
<property name="can-focus">0</property>
Expand Down Expand Up @@ -63,20 +63,6 @@
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="year_label">
<property name="xalign">0</property>
<property name="halign">start</property>
<property name="label">Year</property>
<property name="ellipsize">end</property>
<property name="max-width-chars">50</property>
<property name="lines">1</property>
<property name="sensitive">0</property>
<style>
<class name="body" />
</style>
</object>
</child>
</object>
</child>
<style>
Expand Down
2 changes: 1 addition & 1 deletion src/app/components/playlist_details/playlist_headerbar.ui
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</object>
</child>
<style>
<class name="flat" />
<class name="playlist_details__headerbar" />
</style>
</object>
</child>
Expand Down
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ sources = files(
'./app/components/playlist_details/playlist_details_model.rs',
'./app/components/playlist_details/mod.rs',
'./app/components/playlist_details/playlist_details.rs',
'./app/components/playlist_details/playlist_headerbar.rs',
'./app/components/playlist_details/playlist_header.rs',
'./app/components/headerbar/widget.rs',
'./app/components/headerbar/component.rs',
'./app/components/headerbar/mod.rs',
Expand Down

0 comments on commit d10a482

Please sign in to comment.