Skip to content

Commit ec0874c

Browse files
committed
feat: new tiny lil status widget
1 parent 9c7a173 commit ec0874c

4 files changed

Lines changed: 95 additions & 0 deletions

File tree

‎player/rsrc/play_status.png‎

1.1 KB
Loading

‎player/src/gui.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ pub mod bitrate_bar;
2727
pub mod marquee_label;
2828
pub mod visualizer;
2929
pub mod group_box;
30+
pub mod play_status;
3031

3132
use crate::preferences::Server;
3233
use crate::State;
3334

3435
use self::connection_window::ConnectionWindow;
3536
use self::main_window::*;
37+
use self::play_status::PlayStatusIcon;
3638
use self::preferences_window::PrefsWindow;
3739
use self::queue_window::QueueWindow;
3840

@@ -474,7 +476,30 @@ impl UIThread {
474476
fn update_status(&mut self) {
475477
let status = self.get_status();
476478
self.gui.status_field.set_label(&status);
479+
// and the little thingy too
480+
let play_status = self.get_play_status();
481+
self.gui.play_status.update(play_status);
477482
}
483+
484+
fn get_play_status(&self) -> PlayStatusIcon {
485+
// i love duplicated logic ^-^
486+
let state = self.state.blocking_read();
487+
488+
if let Some(connection) = &state.connection {
489+
if let Some(r) = &connection.room {
490+
if let Some(t) = &r.playing {
491+
if t.owner == state.my_id {
492+
// todo: pause?
493+
return PlayStatusIcon::PlayTx
494+
} else {
495+
return PlayStatusIcon::PlayRx
496+
}
497+
}
498+
}
499+
}
500+
PlayStatusIcon::Stop
501+
}
502+
478503
fn get_status(&self) -> String {
479504
let state = self.state.blocking_read();
480505

‎player/src/gui/main_window.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use fltk::window::*;
1212
use super::bitrate_bar::*;
1313
use super::marquee_label::*;
1414
use super::visualizer::*;
15+
use super::play_status::*;
1516

1617
use super::add_bar;
1718
use super::UIEvent;
@@ -27,6 +28,7 @@ pub struct MainWindow {
2728
pub lbl_artist: Frame,
2829
pub visualizer: Visualizer,
2930
pub bitrate_bar: BitrateBar,
31+
pub play_status: PlayStatus,
3032
pub volume_slider: HorSlider,
3133
pub art_frame: Frame,
3234
}
@@ -159,6 +161,9 @@ impl MainWindow {
159161
let bitrate_bar = BitrateBar::new(67, 69);
160162
display.add(&*bitrate_bar);
161163

164+
let play_status = PlayStatus::new(18, 38);
165+
display.add(&*play_status);
166+
162167
display.end();
163168
main_win.add(&display);
164169

@@ -198,6 +203,7 @@ impl MainWindow {
198203
lbl_artist,
199204
visualizer,
200205
bitrate_bar,
206+
play_status,
201207
volume_slider,
202208
art_frame,
203209
}

‎player/src/gui/play_status.rs‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
use std::cell::RefCell;
2+
use std::rc::Rc;
3+
4+
use fltk::draw;
5+
use fltk::enums::*;
6+
use fltk::image::PngImage;
7+
use fltk::prelude::*;
8+
use fltk::widget;
9+
use fltk::widget_extends;
10+
11+
#[derive(Clone, Copy)]
12+
pub enum PlayStatusIcon {
13+
PlayTx,
14+
PlayRx,
15+
Pause,
16+
Stop
17+
}
18+
19+
pub struct PlayStatus {
20+
inner: widget::Widget,
21+
icon: Rc<RefCell<PlayStatusIcon>>,
22+
}
23+
24+
widget_extends!(PlayStatus, widget::Widget, inner);
25+
26+
impl PlayStatus {
27+
pub fn new(x: i32, y: i32) -> Self {
28+
let mut inner = widget::Widget::default()
29+
.with_size(14, 14)
30+
.with_pos(x, y);
31+
inner.set_frame(FrameType::FlatBox);
32+
33+
let mut img_data = PngImage::from_data(include_bytes!("../../rsrc/play_status.png")).unwrap();
34+
35+
let icon = Rc::new(RefCell::new(PlayStatusIcon::Stop));
36+
let icon_h = icon.clone();
37+
38+
inner.draw(move |i| {
39+
draw::draw_box(i.frame(), i.x(), i.y(), i.w(), i.h(), i.color());
40+
let icon = icon_h.borrow();
41+
let cx = Self::icon_offset(*icon);
42+
img_data.draw_ext(x, y, 14, 14, cx, 0);
43+
});
44+
45+
Self {
46+
inner,
47+
icon
48+
}
49+
}
50+
51+
fn icon_offset(icon: PlayStatusIcon) -> i32 {
52+
match icon {
53+
PlayStatusIcon::PlayTx => 0,
54+
PlayStatusIcon::PlayRx => 16,
55+
PlayStatusIcon::Pause => 32,
56+
PlayStatusIcon::Stop => 48,
57+
}
58+
}
59+
60+
pub fn update(&mut self, icon: PlayStatusIcon) {
61+
self.icon.replace(icon);
62+
self.redraw();
63+
}
64+
}

0 commit comments

Comments
 (0)