diff --git a/src/common/mod.rs b/src/common/mod.rs index 05391af..090e3b1 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,9 +1,9 @@ use std::cell::Cell; use std::path::PathBuf; use std::time::Duration; -use adw::prelude::*; -use adw::gdk::pango::{AttrInt, AttrList, EllipsizeMode, FontScale, Weight}; +use adw::gdk::pango::{AttrInt, AttrList, EllipsizeMode, FontScale::Subscript, Weight::Bold}; use adw::glib::timeout_add_local_once; +use adw::prelude::*; use gtk::{Box, Button, Image, Label, Orientation, ScrolledWindow}; use gtk::builders::{BoxBuilder, LabelBuilder}; @@ -40,7 +40,7 @@ pub trait BoldLabelBuilder { impl BoldLabelBuilder for LabelBuilder { fn bold(self) -> Self { let attr_list = AttrList::new(); - attr_list.insert(AttrInt::new_weight(Weight::Bold)); + attr_list.insert(AttrInt::new_weight(Bold)); self.attributes(&attr_list) } } @@ -52,7 +52,7 @@ pub trait SubscriptLabelBuilder { impl SubscriptLabelBuilder for LabelBuilder { fn subscript(self) -> LabelBuilder { let attr_list = AttrList::new(); - attr_list.insert(AttrInt::new_font_scale(FontScale::Subscript)); + attr_list.insert(AttrInt::new_font_scale(Subscript)); self.attributes(&attr_list) } } @@ -64,8 +64,8 @@ pub trait BoldSubscriptLabelBuilder { impl BoldSubscriptLabelBuilder for LabelBuilder { fn bold_subscript(self) -> LabelBuilder { let attr_list = AttrList::new(); - attr_list.insert(AttrInt::new_font_scale(FontScale::Subscript)); - attr_list.insert(AttrInt::new_weight(Weight::Bold)); + attr_list.insert(AttrInt::new_font_scale(Subscript)); + attr_list.insert(AttrInt::new_weight(Bold)); self.attributes(&attr_list) } } @@ -106,13 +106,13 @@ impl ImagePathBuf for Image { } } -pub trait MonospaceLabel { - fn monospace(self) -> Self; +pub trait NumericLabel { + fn numeric(self) -> Self; } -impl MonospaceLabel for Label { - fn monospace(self) -> Self { - self.add_css_class("monospace"); +impl NumericLabel for Label { + fn numeric(self) -> Self { + self.add_css_class("numeric"); self } } diff --git a/src/main.rs b/src/main.rs index 0fcfdbd..368383c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,7 @@ use adw::prelude::*; use diesel::{delete, ExpressionMethods, insert_into, QueryDsl, RunQueryDsl, update}; use diesel::migration::Result; use diesel_migrations::MigrationHarness; -use gtk::{Button, MenuButton, Popover, ScrolledWindow}; +use gtk::{Button, CssProvider, MenuButton, Popover, ScrolledWindow, style_context_add_provider_for_display, STYLE_PROVIDER_PRIORITY_APPLICATION}; use gtk::Align::Fill; use gtk::Orientation::Vertical; use db::MIGRATIONS; @@ -46,6 +46,12 @@ fn main() -> Result { let window = ApplicationWindow::builder().application(application).content(&header_body) .default_width(config.window_width).default_height(config.window_height).maximized(config.maximized == 1) .build(); + let css_provider = CssProvider::new(); + css_provider.load_from_data("#accent-bg { background-color: @accent_bg_color; } \ + #accent-progress progress { background-color: @accent_fg_color; } \ + #small-slider slider { min-width: 16px; min-height: 16px; } trough { min-height: 4px }"); + style_context_add_provider_for_display(&header_body.display(), &css_provider, + STYLE_PROVIDER_PRIORITY_APPLICATION); let window_title = WindowTitle::builder().build(); let history: Rc, bool)>>> = Rc::new(RefCell::new(Vec::new())); let song_selected_body: Rc>>> = Rc::new(RefCell::new(None)); diff --git a/src/now_playing/body.rs b/src/now_playing/body.rs index 29cd988..eff2c8a 100644 --- a/src/now_playing/body.rs +++ b/src/now_playing/body.rs @@ -8,20 +8,20 @@ use crate::now_playing::now_playing::NowPlaying; use crate::now_playing::playbin::{PLAYBIN, Playbin}; pub(in crate::now_playing) fn create(now_playing: Rc>) -> (gtk::Box, GestureSwipe) { - let body = gtk::Box::builder().orientation(Vertical).margin_bottom(8).build(); + let body = gtk::Box::builder().orientation(Vertical).margin_bottom(16).build(); let image_and_song_info = gtk::Box::builder().orientation(Vertical).build(); body.append(&image_and_song_info); image_and_song_info.append(&now_playing.borrow().body_image); - let song_info = gtk::Box::builder().orientation(Vertical).margin_start(8).margin_end(8).build(); + let song_info = gtk::Box::builder().orientation(Vertical).spacing(4).margin_start(8).margin_end(8).build(); image_and_song_info.append(&song_info); let skip_song_gesture = GestureSwipe::new(); image_and_song_info.add_controller(skip_song_gesture.clone()); song_info.append(&now_playing.borrow().body_song); song_info.append(&now_playing.borrow().body_artist); - let time_and_controls = gtk::Box::builder().orientation(Vertical).margin_start(8).margin_end(8).build(); + let time_and_controls = gtk::Box::builder().orientation(Vertical).spacing(4).margin_start(8).margin_end(8).build(); body.append(&time_and_controls); time_and_controls.append(&now_playing.borrow().scale); - let time = gtk::Box::builder().build(); + let time = gtk::Box::builder().margin_start(11).margin_end(11).build(); time_and_controls.append(&time); time.append(&now_playing.borrow().body_position); time.append(&now_playing.borrow().body_duration); diff --git a/src/now_playing/bottom_widget.rs b/src/now_playing/bottom_widget.rs index adf868c..96b2e35 100644 --- a/src/now_playing/bottom_widget.rs +++ b/src/now_playing/bottom_widget.rs @@ -2,11 +2,10 @@ use std::cell::RefCell; use std::rc::Rc; use adw::prelude::*; use adw::WindowTitle; -use gtk::{Button, CssProvider, EventSequenceState, GestureClick, GestureLongPress, GestureSwipe, Label, ScrolledWindow, style_context_add_provider_for_display, STYLE_PROVIDER_PRIORITY_APPLICATION}; +use gtk::{Button, EventSequenceState, GestureClick, GestureLongPress, GestureSwipe, Label, ScrolledWindow}; use gtk::Orientation::Vertical; use gtk::PropagationPhase::Capture; use crate::body::Body; -use crate::common::MonospaceLabel; use crate::now_playing::now_playing::NowPlaying; pub(in crate::now_playing) fn create(now_playing: Rc>, @@ -14,11 +13,6 @@ pub(in crate::now_playing) fn create(now_playing: Rc>, history: Rc, bool)>>>, back_button: &Button) -> (gtk::Box, GestureSwipe, GestureClick) { let now_playing_and_progress = gtk::Box::builder().orientation(Vertical).name("accent-bg").build(); - let css_provider = CssProvider::new(); - css_provider.load_from_data("#accent-bg { background-color: @accent_bg_color; } \ - #accent-progress progress { background-color: @accent_fg_color; }"); - style_context_add_provider_for_display(&now_playing_and_progress.display(), &css_provider, - STYLE_PROVIDER_PRIORITY_APPLICATION); now_playing.borrow().progress_bar.add_css_class("osd"); now_playing_and_progress.append(&now_playing.borrow().progress_bar); let now_playing_and_play_pause = gtk::Box::builder().margin_start(8).margin_end(8).margin_top(8).margin_bottom(8) @@ -62,7 +56,7 @@ pub(in crate::now_playing) fn create(now_playing: Rc>, let time_box = gtk::Box::builder().spacing(4).margin_top(4).build(); song_info.append(&time_box); time_box.append(&now_playing.borrow().bottom_position); - time_box.append(&Label::new(Some("/")).monospace()); + time_box.append(&Label::new(Some("/"))); time_box.append(&now_playing.borrow().bottom_duration); now_playing_and_play_pause.append(&now_playing.borrow().bottom_play_pause); (now_playing_and_progress, skip_song_gesture, image_click) diff --git a/src/now_playing/now_playing.rs b/src/now_playing/now_playing.rs index 1888dba..068c8e1 100644 --- a/src/now_playing/now_playing.rs +++ b/src/now_playing/now_playing.rs @@ -5,8 +5,8 @@ use adw::WindowTitle; use gstreamer::ClockTime; use gstreamer::prelude::ElementExtManual; use gtk::{Button, Image, Label, ProgressBar, Scale}; -use gtk::Align::{Start, End}; -use crate::common::{BoldLabelBuilder, EllipsizedLabelBuilder, FlatButton, ImagePathBuf, MonospaceLabel, SONG}; +use gtk::Align::{End, Start}; +use crate::common::{BoldLabelBuilder, EllipsizedLabelBuilder, FlatButton, ImagePathBuf, NumericLabel, SONG}; use crate::common::util::{format, format_pad}; use crate::now_playing::playbin::PLAYBIN; @@ -71,8 +71,12 @@ impl NowPlaying { button.flat() } pub(in crate::now_playing) fn new() -> Self { - let scale = Scale::builder().hexpand(true).build(); + let scale = Scale::builder().hexpand(true).name("small-slider").build(); scale.set_range(0.0, 1.0); + let body_song = Label::builder().ellipsized().build(); + body_song.add_css_class("title-3"); + let body_artist = Label::builder().ellipsized().build(); + body_artist.add_css_class("title-4"); NowPlaying { cover: None, bottom_image: Image::builder().pixel_size(56).build(), @@ -81,10 +85,10 @@ impl NowPlaying { duration: 0, progress_bar: ProgressBar::builder().name("accent-progress").build(), scale, - bottom_position: Label::builder().label(&format(0)).build().monospace(), - body_position: Label::builder().label(&format(0)).hexpand(true).halign(Start).build().monospace(), - bottom_duration: Label::new(Some(&format(0))).monospace(), - body_duration: Label::builder().label(&format(0)).hexpand(true).halign(End).build().monospace(), + bottom_position: Label::builder().label(&format(0)).build().numeric(), + body_position: Label::builder().label(&format(0)).hexpand(true).halign(Start).build().numeric(), + bottom_duration: Label::new(Some(&format(0))).numeric(), + body_duration: Label::builder().label(&format(0)).hexpand(true).halign(End).build().numeric(), bottom_play_pause: Self::flat_play(Button::builder() .child(&Image::builder().pixel_size(40).build()).build()), body_play_pause: Self::flat_play(Button::builder().hexpand(true) @@ -92,9 +96,9 @@ impl NowPlaying { song: String::from(""), artist: String::from(""), bottom_song: Label::builder().ellipsized().bold().build(), - body_song: Label::builder().ellipsized().bold().build(), + body_song, bottom_artist: Label::builder().ellipsized().build(), - body_artist: Label::builder().ellipsized().build(), + body_artist, } } pub(in crate::now_playing) fn click_play_pause(&self) {