Add location and duration labels

This commit is contained in:
mars 2022-11-07 12:16:35 -07:00
parent 8c9f821835
commit fe9ea34a23
1 changed files with 40 additions and 9 deletions

View File

@ -99,7 +99,7 @@ impl Default for MusicPlayerStyle {
footer: Default::default(),
rounding: 5.0,
art_margin: 5.0,
button_spacing: 20.0,
button_spacing: 15.0,
}
}
}
@ -111,6 +111,8 @@ pub struct MusicPlayerWidget {
previous: Offset<RoundButton>,
play: Offset<RoundButton>,
next: Offset<RoundButton>,
position: Offset<Label>,
duration: Offset<Label>,
style: MusicPlayerStyle,
art_rect: Rect,
body_rect: Rect,
@ -125,6 +127,8 @@ impl Container for MusicPlayerWidget {
f(&mut self.previous);
f(&mut self.play);
f(&mut self.next);
f(&mut self.position);
f(&mut self.duration);
}
fn draw(&mut self, ctx: &DrawContext) {
@ -148,11 +152,13 @@ impl Container for MusicPlayerWidget {
impl MusicPlayerWidget {
pub fn new() -> Self {
let font = Font::new(crate::DISPLAY_FONT);
let style = MusicPlayerStyle::default();
let display_font = Font::new(crate::DISPLAY_FONT);
let content_font = Font::new(crate::CONTENT_FONT);
let make_label = |content: &str| {
let make_body_label = |content: &str| {
let text = LabelText {
font,
font: display_font,
text: content.to_string(),
};
@ -160,6 +166,27 @@ impl MusicPlayerWidget {
Offset::new(label, Vec2::ZERO)
};
let make_footer_label = |content: &str| {
let text = LabelText {
font: content_font,
text: content.to_string(),
};
let size = style.footer.height;
let scale = size * 0.4;
let baseline = size * 0.125;
let label = Label::new(
text,
HorizontalAlignment::Center,
scale,
Color::BLACK,
0.0,
0.0,
baseline,
);
Offset::new(label, Vec2::ZERO)
};
let icon_font = Font::new(crate::ICON_FONT);
let prev_text = LabelText {
@ -177,8 +204,6 @@ impl MusicPlayerWidget {
text: "".to_string(),
};
let style = MusicPlayerStyle::default();
let primary_button = RoundButtonStyle {
radius: style.footer.height * 0.3,
spacing: style.footer.height * 0.1,
@ -202,12 +227,14 @@ impl MusicPlayerWidget {
let next = RoundButton::new(secondary_button, Some(next_text));
Self {
artist: make_label("Artist"),
album: make_label("Album"),
track: make_label("Track"),
artist: make_body_label("Artist"),
album: make_body_label("Album"),
track: make_body_label("Track"),
previous: Offset::new(prev, Vec2::ZERO),
play: Offset::new(play, Vec2::ZERO),
next: Offset::new(next, Vec2::ZERO),
position: make_footer_label("--:--"),
duration: make_footer_label("--:--"),
style,
art_rect: Rect::from_xy_size(Vec2::ZERO, Vec2::ZERO),
body_rect: Rect::from_xy_size(Vec2::ZERO, Vec2::ZERO),
@ -235,10 +262,14 @@ impl MusicPlayerWidget {
let previous_x = style.button_spacing * 0.5;
let play_x = style.button_spacing * 1.5;
let next_x = style.button_spacing * 2.5;
let position_x = style.button_spacing * 3.5;
let duration_x = width - style.button_spacing * 0.75;
self.artist.set_offset(Vec2::new(label_x, artist_baseline));
self.album.set_offset(Vec2::new(label_x, album_baseline));
self.track.set_offset(Vec2::new(label_x, track_baseline));
self.position.set_offset(Vec2::new(position_x, button_y));
self.duration.set_offset(Vec2::new(duration_x, button_y));
self.body_rect = Rect::from_xy_size(Vec2::ZERO, body_size);
self.footer_rect = Rect::from_xy_size(self.body_rect.bl(), footer_size);