move the slider as video is playing
This commit is contained in:
parent
4f3d5e560c
commit
54c264f55d
64
src/main.rs
64
src/main.rs
|
@ -183,11 +183,34 @@ impl cosmic::Application for App {
|
||||||
Some(&self.nav_model)
|
Some(&self.nav_model)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nav_bar(
|
// fn nav_bar(
|
||||||
&self,
|
// &self,
|
||||||
) -> Option<Element<cosmic::app::Message<Message>>> {
|
// ) -> Option<Element<cosmic::app::Message<Message>>> {
|
||||||
None
|
// if !self.core().nav_bar_active() {
|
||||||
}
|
// return None;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// let nav_model = self.nav_model()?;
|
||||||
|
|
||||||
|
// let mut nav = cosmic::widget::nav_bar(nav_model, |id| {
|
||||||
|
// cosmic::app::Message::Cosmic(cosmic::Message::NavBar(id))
|
||||||
|
// })
|
||||||
|
// .on_context(|id| {
|
||||||
|
// Message::Cosmic(cosmic::Message::NavBarContext(id))
|
||||||
|
// })
|
||||||
|
// .context_menu(
|
||||||
|
// self.nav_context_menu(self.core.nav_bar_context()),
|
||||||
|
// )
|
||||||
|
// .into_container()
|
||||||
|
// // XXX both must be shrink to avoid flex layout from ignoring it
|
||||||
|
// .width(iced::Length::Shrink)
|
||||||
|
// .height(iced::Length::Shrink);
|
||||||
|
|
||||||
|
// if !self.core().is_condensed() {
|
||||||
|
// nav = nav.max_width(280);
|
||||||
|
// }
|
||||||
|
// Some(nav.into())
|
||||||
|
// }
|
||||||
|
|
||||||
/// Called when a navigation item is selected.
|
/// Called when a navigation item is selected.
|
||||||
fn on_nav_select(
|
fn on_nav_select(
|
||||||
|
@ -411,7 +434,6 @@ impl cosmic::Application for App {
|
||||||
|
|
||||||
// Main window view
|
// Main window view
|
||||||
fn view(&self) -> Element<Message> {
|
fn view(&self) -> Element<Message> {
|
||||||
debug!("Main view");
|
|
||||||
let icon_left = icon::from_name("arrow-left");
|
let icon_left = icon::from_name("arrow-left");
|
||||||
let icon_right = icon::from_name("arrow-right");
|
let icon_right = icon::from_name("arrow-right");
|
||||||
|
|
||||||
|
@ -423,13 +445,6 @@ impl cosmic::Application for App {
|
||||||
0.0
|
0.0
|
||||||
};
|
};
|
||||||
|
|
||||||
let video_pos = if let Some(video) = &self.presenter.video {
|
|
||||||
let range = video.position();
|
|
||||||
range.as_secs_f32()
|
|
||||||
} else {
|
|
||||||
0.0
|
|
||||||
};
|
|
||||||
|
|
||||||
let video_button_icon =
|
let video_button_icon =
|
||||||
if let Some(video) = &self.presenter.video {
|
if let Some(video) = &self.presenter.video {
|
||||||
if video.paused() {
|
if video.paused() {
|
||||||
|
@ -456,9 +471,7 @@ impl cosmic::Application for App {
|
||||||
let slide_preview = column![
|
let slide_preview = column![
|
||||||
Space::with_height(Length::Fill),
|
Space::with_height(Length::Fill),
|
||||||
Responsive::new(|size| {
|
Responsive::new(|size| {
|
||||||
debug!(?size);
|
|
||||||
let height = size.width * 9.0 / 16.0;
|
let height = size.width * 9.0 / 16.0;
|
||||||
debug!(?height);
|
|
||||||
Container::new(
|
Container::new(
|
||||||
Container::new(
|
Container::new(
|
||||||
self.presenter
|
self.presenter
|
||||||
|
@ -473,15 +486,18 @@ impl cosmic::Application for App {
|
||||||
Container::new(if self.presenter.video.is_some() {
|
Container::new(if self.presenter.video.is_some() {
|
||||||
row![
|
row![
|
||||||
video_button_icon,
|
video_button_icon,
|
||||||
Container::new(slider(
|
Container::new(
|
||||||
0.0..=video_range,
|
slider(
|
||||||
video_pos,
|
0.0..=video_range,
|
||||||
|pos| {
|
self.presenter.video_position,
|
||||||
Message::Present(
|
|pos| {
|
||||||
presenter::Message::VideoPos(pos),
|
Message::Present(
|
||||||
)
|
presenter::Message::VideoPos(pos),
|
||||||
}
|
)
|
||||||
))
|
}
|
||||||
|
)
|
||||||
|
.step(0.1)
|
||||||
|
)
|
||||||
.center_x(Length::Fill)
|
.center_x(Length::Fill)
|
||||||
.padding([7, 0, 0, 0])
|
.padding([7, 0, 0, 0])
|
||||||
]
|
]
|
||||||
|
|
|
@ -24,6 +24,7 @@ pub(crate) struct Presenter {
|
||||||
pub current_slide: Slide,
|
pub current_slide: Slide,
|
||||||
pub current_slide_index: u16,
|
pub current_slide_index: u16,
|
||||||
pub video: Option<Video>,
|
pub video: Option<Video>,
|
||||||
|
pub video_position: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq)]
|
#[derive(Debug, Clone, PartialEq)]
|
||||||
|
@ -34,6 +35,7 @@ pub(crate) enum Message {
|
||||||
EndVideo,
|
EndVideo,
|
||||||
StartVideo,
|
StartVideo,
|
||||||
VideoPos(f32),
|
VideoPos(f32),
|
||||||
|
VideoFrame,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Presenter {
|
impl Presenter {
|
||||||
|
@ -66,6 +68,7 @@ impl Presenter {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
video_position: 0.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +150,13 @@ impl Presenter {
|
||||||
}
|
}
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
Message::VideoFrame => {
|
||||||
|
if let Some(video) = &self.video {
|
||||||
|
self.video_position =
|
||||||
|
video.position().as_secs_f32();
|
||||||
|
}
|
||||||
|
Task::none()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,6 +192,7 @@ impl Presenter {
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.on_end_of_stream(Message::EndVideo)
|
.on_end_of_stream(Message::EndVideo)
|
||||||
|
.on_new_frame(Message::VideoFrame)
|
||||||
.content_fit(ContentFit::Cover),
|
.content_fit(ContentFit::Cover),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue