SAO UI music player sets position from slider
This commit is contained in:
parent
f37ec4251d
commit
1453ab0c46
|
@ -126,6 +126,7 @@ pub struct MusicPlayerWidget {
|
|||
position_secs: f32,
|
||||
duration_secs: f32,
|
||||
position_dirty: bool,
|
||||
position_updating: bool,
|
||||
status: PlaybackStatus,
|
||||
}
|
||||
|
||||
|
@ -143,17 +144,30 @@ impl Container for MusicPlayerWidget {
|
|||
}
|
||||
|
||||
fn update(&mut self, dt: f32) {
|
||||
if let PlaybackStatus::Playing = self.status {
|
||||
let position_display = if let Some(position) = self.slider.has_update() {
|
||||
self.position_updating = true;
|
||||
Some(position * self.duration_secs)
|
||||
} else if self.position_updating {
|
||||
let position = self.slider.get_position() * self.duration_secs;
|
||||
let msg = OutMsg::SetPosition { position };
|
||||
self.send_message(&msg);
|
||||
self.position_updating = false;
|
||||
Some(position)
|
||||
} else if let PlaybackStatus::Playing = self.status {
|
||||
self.position_secs += dt;
|
||||
self.position_dirty = true;
|
||||
}
|
||||
|
||||
if self.position_dirty {
|
||||
self.slider
|
||||
.set_position(self.position_secs / self.duration_secs);
|
||||
Some(self.position_secs)
|
||||
} else if self.position_dirty {
|
||||
self.position_dirty = false;
|
||||
self.position
|
||||
.set_text(&Self::format_time(self.position_secs));
|
||||
Some(self.position_secs)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
self.slider.set_position(self.position_secs / self.duration_secs);
|
||||
if let Some(position) = position_display {
|
||||
self.position_dirty = false;
|
||||
self.position.set_text(&Self::format_time(position));
|
||||
}
|
||||
|
||||
if self.previous.was_clicked() {
|
||||
|
@ -289,6 +303,7 @@ impl MusicPlayerWidget {
|
|||
position_secs: 0.0,
|
||||
duration_secs: 0.0,
|
||||
position_dirty: false,
|
||||
position_updating: false,
|
||||
status: PlaybackStatus::Paused,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue