Skip to content

Commit

Permalink
Improve now playing body styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza Ghassemi committed Aug 5, 2023
1 parent 877defb commit d79c45c
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 33 deletions.
22 changes: 11 additions & 11 deletions src/common/mod.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,6 +46,12 @@ fn main() -> Result<ExitCode> {
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<RefCell<Vec<(Rc<Body>, bool)>>> = Rc::new(RefCell::new(Vec::new()));
let song_selected_body: Rc<RefCell<Option<Rc<Body>>>> = Rc::new(RefCell::new(None));
Expand Down
8 changes: 4 additions & 4 deletions src/now_playing/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RefCell<NowPlaying>>) -> (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);
Expand Down
10 changes: 2 additions & 8 deletions src/now_playing/bottom_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,17 @@ 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<RefCell<NowPlaying>>,
song_selected_body: Rc<RefCell<Option<Rc<Body>>>>, window_title: &WindowTitle, scrolled_window: &ScrolledWindow,
history: Rc<RefCell<Vec<(Rc<Body>, 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)
Expand Down Expand Up @@ -62,7 +56,7 @@ pub(in crate::now_playing) fn create(now_playing: Rc<RefCell<NowPlaying>>,
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)
Expand Down
22 changes: 13 additions & 9 deletions src/now_playing/now_playing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Expand All @@ -81,20 +85,20 @@ 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)
.child(&Image::builder().pixel_size(40).build()).build()),
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) {
Expand Down

0 comments on commit d79c45c

Please sign in to comment.