icon button
This commit is contained in:
parent
39982edc10
commit
28b7bbdf60
4 changed files with 27 additions and 2 deletions
|
@ -117,8 +117,7 @@ template $AudreyUiPlaybar: Adw.Bin {
|
||||||
}
|
}
|
||||||
|
|
||||||
Button {
|
Button {
|
||||||
icon-name: "media-playback-start";
|
icon-name: bind $play_pause_icon_name (template.idle-active, template.pause) as <string>;
|
||||||
//icon-name: bind $play_pause_icon_name (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as <string>;
|
|
||||||
valign: center;
|
valign: center;
|
||||||
//sensitive: bind $can_press_play (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>, template.playbin as <$AudreyPlaybin>.play-queue-length) as <bool>;
|
//sensitive: bind $can_press_play (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>, template.playbin as <$AudreyPlaybin>.play-queue-length) as <bool>;
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,7 @@ template $AudreyUiWindow: Adw.ApplicationWindow {
|
||||||
pause: bind template.pause bidirectional;
|
pause: bind template.pause bidirectional;
|
||||||
position: bind template.time-pos;
|
position: bind template.time-pos;
|
||||||
duration: bind template.song as <$AudreyPlaybinSong>.duration;
|
duration: bind template.song as <$AudreyPlaybinSong>.duration;
|
||||||
|
idle-active: bind template.idle-active;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ mod imp {
|
||||||
_mute: Cell<bool>,
|
_mute: Cell<bool>,
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
_pause: Cell<bool>,
|
_pause: Cell<bool>,
|
||||||
|
#[property(get, set)]
|
||||||
|
_idle_active: Cell<bool>,
|
||||||
|
|
||||||
#[property(get, set)]
|
#[property(get, set)]
|
||||||
position: Cell<f64>,
|
position: Cell<f64>,
|
||||||
|
@ -153,6 +155,15 @@ mod imp {
|
||||||
self.obj().set_mute(!self.obj().mute());
|
self.obj().set_mute(!self.obj().mute());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[template_callback]
|
||||||
|
fn play_pause_icon_name(&self, idle_active: bool, pause: bool) -> &'static str {
|
||||||
|
match (idle_active, pause) {
|
||||||
|
(true, _) => "media-playback-start",
|
||||||
|
(false, true) => "media-playback-start",
|
||||||
|
(false, false) => "media-playback-pause",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn window(&self) -> crate::ui::Window {
|
fn window(&self) -> crate::ui::Window {
|
||||||
self.obj().root().unwrap().dynamic_cast().unwrap()
|
self.obj().root().unwrap().dynamic_cast().unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,8 @@ mod imp {
|
||||||
_playlist_pos: (),
|
_playlist_pos: (),
|
||||||
#[property(type = f64, get = Self::time_pos)]
|
#[property(type = f64, get = Self::time_pos)]
|
||||||
_time_pos: (),
|
_time_pos: (),
|
||||||
|
#[property(type = bool, get = Self::idle_active)]
|
||||||
|
_idle_active: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Window {
|
impl Default for Window {
|
||||||
|
@ -61,6 +63,7 @@ mod imp {
|
||||||
mpv.observe_property(1, "mute").unwrap();
|
mpv.observe_property(1, "mute").unwrap();
|
||||||
mpv.observe_property(2, "pause").unwrap();
|
mpv.observe_property(2, "pause").unwrap();
|
||||||
mpv.observe_property(3, "playlist-pos").unwrap();
|
mpv.observe_property(3, "playlist-pos").unwrap();
|
||||||
|
mpv.observe_property(4, "idle-active").unwrap();
|
||||||
|
|
||||||
// "Useful to drain property changes before a new file is loaded."
|
// "Useful to drain property changes before a new file is loaded."
|
||||||
mpv.add_hook(0, "on_before_start_file", 0).unwrap();
|
mpv.add_hook(0, "on_before_start_file", 0).unwrap();
|
||||||
|
@ -81,6 +84,7 @@ mod imp {
|
||||||
_pause: (),
|
_pause: (),
|
||||||
_playlist_pos: (),
|
_playlist_pos: (),
|
||||||
_time_pos: (),
|
_time_pos: (),
|
||||||
|
_idle_active: (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,6 +139,11 @@ mod imp {
|
||||||
window.notify("playlist-pos");
|
window.notify("playlist-pos");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4 => {
|
||||||
|
assert_eq!(event.name, "idle-active");
|
||||||
|
window.notify("idle-active");
|
||||||
|
}
|
||||||
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -242,6 +251,7 @@ mod imp {
|
||||||
|
|
||||||
self.mpv.command(["stop"]).unwrap();
|
self.mpv.command(["stop"]).unwrap();
|
||||||
self.playlist_model.remove_all();
|
self.playlist_model.remove_all();
|
||||||
|
self.set_pause(false);
|
||||||
|
|
||||||
let api = {
|
let api = {
|
||||||
let api = self.api.borrow();
|
let api = self.api.borrow();
|
||||||
|
@ -299,6 +309,10 @@ mod imp {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn idle_active(&self) -> bool {
|
||||||
|
self.mpv.get_property("idle-active").unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
fn song(&self) -> Option<PlaybinSong> {
|
fn song(&self) -> Option<PlaybinSong> {
|
||||||
if self.obj().playlist_pos() < 0 {
|
if self.obj().playlist_pos() < 0 {
|
||||||
None
|
None
|
||||||
|
|
Loading…
Reference in a new issue