Making slides visible from song_editor
This commit is contained in:
parent
be3d84be33
commit
07a2a29097
|
@ -368,8 +368,9 @@ impl Presenter {
|
|||
}
|
||||
|
||||
pub fn view(&self) -> Element<Message> {
|
||||
self.slide_view(
|
||||
&self.current_slide,
|
||||
slide_view(
|
||||
self.current_slide.clone(),
|
||||
&self.video,
|
||||
self.current_font,
|
||||
false,
|
||||
true,
|
||||
|
@ -377,8 +378,9 @@ impl Presenter {
|
|||
}
|
||||
|
||||
pub fn view_preview(&self) -> Element<Message> {
|
||||
self.slide_view(
|
||||
&self.current_slide,
|
||||
slide_view(
|
||||
self.current_slide.clone(),
|
||||
&self.video,
|
||||
self.current_font,
|
||||
false,
|
||||
false,
|
||||
|
@ -419,7 +421,8 @@ impl Presenter {
|
|||
self.slides.iter().position(|s| s == slide).unwrap()
|
||||
as i32;
|
||||
|
||||
let container = self.slide_view(slide, font, true, false);
|
||||
let container =
|
||||
slide_view(slide.clone(), &self.video, font, true, false);
|
||||
let delegate = mouse_area(
|
||||
Container::new(container)
|
||||
.style(move |t| {
|
||||
|
@ -479,105 +482,6 @@ impl Presenter {
|
|||
delegate.into()
|
||||
}
|
||||
|
||||
fn slide_view<'a>(
|
||||
&'a self,
|
||||
slide: &'a Slide,
|
||||
font: Font,
|
||||
delegate: bool,
|
||||
hide_mouse: bool,
|
||||
) -> Element<'a, Message> {
|
||||
responsive(move |size| {
|
||||
let font_size = scale_font(
|
||||
slide.font_size() as f32,
|
||||
size.width,
|
||||
size.height,
|
||||
);
|
||||
let slide_text = slide.text();
|
||||
let lines = slide_text.lines();
|
||||
// let line_size = lines.clone().count();
|
||||
// debug!(?lines);
|
||||
let text: Vec<Element<Message>> = lines
|
||||
.map(|t| {
|
||||
rich_text([span(format!("{}\n", t.to_string()))
|
||||
.background(
|
||||
Background::Color(Color::BLACK)
|
||||
.scale_alpha(0.4),
|
||||
)
|
||||
.padding(3)])
|
||||
.size(font_size)
|
||||
.font(font)
|
||||
.center()
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
let text = Column::with_children(text).spacing(6);
|
||||
let text_container = Container::new(text)
|
||||
.center(Length::Fill)
|
||||
.align_x(Horizontal::Left);
|
||||
let black = Container::new(Space::new(0, 0))
|
||||
.style(|_| {
|
||||
container::background(Background::Color(
|
||||
Color::BLACK,
|
||||
))
|
||||
})
|
||||
.width(size.width)
|
||||
.height(size.height);
|
||||
let container = match slide.background().kind {
|
||||
BackgroundKind::Image => {
|
||||
let path = slide.background().path.clone();
|
||||
Container::new(
|
||||
image(path)
|
||||
.content_fit(ContentFit::Cover)
|
||||
.width(size.width)
|
||||
.height(size.height),
|
||||
)
|
||||
}
|
||||
BackgroundKind::Video => {
|
||||
if delegate {
|
||||
Container::new(Space::new(0, 0))
|
||||
.style(|_| {
|
||||
container::background(
|
||||
Background::Color(Color::BLACK),
|
||||
)
|
||||
})
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
} else if let Some(video) = &self.video {
|
||||
Container::new(
|
||||
VideoPlayer::new(video)
|
||||
.mouse_hidden(hide_mouse)
|
||||
.width(size.width)
|
||||
.height(size.width * 9.0 / 16.0)
|
||||
.on_end_of_stream(Message::EndVideo)
|
||||
.on_new_frame(Message::VideoFrame)
|
||||
.on_missing_plugin(
|
||||
Message::MissingPlugin,
|
||||
)
|
||||
.on_warning(|w| {
|
||||
Message::Error(w.to_string())
|
||||
})
|
||||
.on_error(|e| {
|
||||
Message::Error(e.to_string())
|
||||
})
|
||||
.content_fit(ContentFit::Cover),
|
||||
)
|
||||
} else {
|
||||
Container::new(Space::new(0, 0))
|
||||
}
|
||||
}
|
||||
};
|
||||
stack!(
|
||||
black,
|
||||
container.center(Length::Fill),
|
||||
text_container
|
||||
)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
||||
fn reset_video(&mut self) {
|
||||
if let Some(slide) =
|
||||
self.slides.get(self.current_slide_index as usize)
|
||||
|
@ -633,3 +537,94 @@ fn scale_font(font_size: f32, width: f32, height: f32) -> f32 {
|
|||
};
|
||||
font_size
|
||||
}
|
||||
|
||||
pub(crate) fn slide_view<'a>(
|
||||
slide: Slide,
|
||||
video: &'a Option<Video>,
|
||||
font: Font,
|
||||
delegate: bool,
|
||||
hide_mouse: bool,
|
||||
) -> Element<'a, Message> {
|
||||
responsive(move |size| {
|
||||
let font_size = scale_font(
|
||||
slide.font_size() as f32,
|
||||
size.width,
|
||||
size.height,
|
||||
);
|
||||
let slide_text = slide.text();
|
||||
let lines = slide_text.lines();
|
||||
// let line_size = lines.clone().count();
|
||||
// debug!(?lines);
|
||||
let text: Vec<Element<Message>> = lines
|
||||
.map(|t| {
|
||||
rich_text([span(format!("{}\n", t.to_string()))
|
||||
.background(
|
||||
Background::Color(Color::BLACK)
|
||||
.scale_alpha(0.4),
|
||||
)
|
||||
.padding(3)])
|
||||
.size(font_size)
|
||||
.font(font)
|
||||
.center()
|
||||
.into()
|
||||
})
|
||||
.collect();
|
||||
let text = Column::with_children(text).spacing(6);
|
||||
let text_container = Container::new(text)
|
||||
.center(Length::Fill)
|
||||
.align_x(Horizontal::Left);
|
||||
let black = Container::new(Space::new(0, 0))
|
||||
.style(|_| {
|
||||
container::background(Background::Color(Color::BLACK))
|
||||
})
|
||||
.width(size.width)
|
||||
.height(size.height);
|
||||
let container = match slide.background().kind {
|
||||
BackgroundKind::Image => {
|
||||
let path = slide.background().path.clone();
|
||||
Container::new(
|
||||
image(path)
|
||||
.content_fit(ContentFit::Cover)
|
||||
.width(size.width)
|
||||
.height(size.height),
|
||||
)
|
||||
}
|
||||
BackgroundKind::Video => {
|
||||
if delegate {
|
||||
Container::new(Space::new(0, 0))
|
||||
.style(|_| {
|
||||
container::background(Background::Color(
|
||||
Color::BLACK,
|
||||
))
|
||||
})
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
} else if let Some(video) = &video {
|
||||
Container::new(
|
||||
VideoPlayer::new(video)
|
||||
.mouse_hidden(hide_mouse)
|
||||
.width(size.width)
|
||||
.height(size.width * 9.0 / 16.0)
|
||||
.on_end_of_stream(Message::EndVideo)
|
||||
.on_new_frame(Message::VideoFrame)
|
||||
.on_missing_plugin(Message::MissingPlugin)
|
||||
.on_warning(|w| {
|
||||
Message::Error(w.to_string())
|
||||
})
|
||||
.on_error(|e| {
|
||||
Message::Error(e.to_string())
|
||||
})
|
||||
.content_fit(ContentFit::Cover),
|
||||
)
|
||||
} else {
|
||||
Container::new(Space::new(0, 0))
|
||||
}
|
||||
}
|
||||
};
|
||||
stack!(black, container.center(Length::Fill), text_container)
|
||||
.width(Length::Fill)
|
||||
.height(Length::Fill)
|
||||
.into()
|
||||
})
|
||||
.into()
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use cosmic::{
|
||||
iced::Length,
|
||||
iced::{
|
||||
font::{Family, Stretch, Style, Weight},
|
||||
Font, Length,
|
||||
},
|
||||
iced_widget::row,
|
||||
widget::{
|
||||
button, column, combo_box, container, dropdown,
|
||||
|
@ -10,9 +13,15 @@ use cosmic::{
|
|||
},
|
||||
Element, Task,
|
||||
};
|
||||
use iced_video_player::Video;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::core::songs::Song;
|
||||
use crate::{
|
||||
core::{service_items::ServiceTrait, songs::Song},
|
||||
Background,
|
||||
};
|
||||
|
||||
use super::presenter::slide_view;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SongEditor {
|
||||
|
@ -27,6 +36,9 @@ pub struct SongEditor {
|
|||
verse_order: String,
|
||||
lyrics: text_editor::Content,
|
||||
editing: bool,
|
||||
background: Option<Background>,
|
||||
video: Option<Video>,
|
||||
current_font: Font,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
@ -68,6 +80,9 @@ impl SongEditor {
|
|||
editing: false,
|
||||
author: "North Point Worship".into(),
|
||||
audio: PathBuf::new(),
|
||||
background: None,
|
||||
video: None,
|
||||
current_font: cosmic::font::default(),
|
||||
}
|
||||
}
|
||||
pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||
|
@ -81,7 +96,20 @@ impl SongEditor {
|
|||
Task::none()
|
||||
}
|
||||
Message::ChangeFont(font) => {
|
||||
self.font = font;
|
||||
self.font = font.clone();
|
||||
|
||||
let font_name = font.into_boxed_str();
|
||||
let family = Family::Name(Box::leak(font_name));
|
||||
let weight = Weight::Normal;
|
||||
let stretch = Stretch::Normal;
|
||||
let style = Style::Normal;
|
||||
let font = Font {
|
||||
family,
|
||||
weight,
|
||||
stretch,
|
||||
style,
|
||||
};
|
||||
self.current_font = font;
|
||||
Task::none()
|
||||
}
|
||||
Message::ChangeFontSize(size) => {
|
||||
|
@ -121,8 +149,8 @@ impl SongEditor {
|
|||
}
|
||||
|
||||
pub fn view(&self) -> Element<Message> {
|
||||
let slide_preview =
|
||||
container(vertical_space()).width(Length::FillPortion(2));
|
||||
let slide_preview = container(self.slide_preview())
|
||||
.width(Length::FillPortion(2));
|
||||
|
||||
let column = column::with_children(vec![
|
||||
self.toolbar(),
|
||||
|
@ -131,6 +159,31 @@ impl SongEditor {
|
|||
column.into()
|
||||
}
|
||||
|
||||
fn slide_preview(&self) -> Element<Message> {
|
||||
if let Some(song) = &self.song {
|
||||
if let Ok(slides) = song.to_slides() {
|
||||
let slides = slides
|
||||
.into_iter()
|
||||
.map(|slide| {
|
||||
slide_view(
|
||||
slide,
|
||||
&self.video,
|
||||
self.current_font,
|
||||
false,
|
||||
false,
|
||||
)
|
||||
.map(|_| Message::None)
|
||||
})
|
||||
.collect();
|
||||
column::with_children(slides).into()
|
||||
} else {
|
||||
horizontal_space().into()
|
||||
}
|
||||
} else {
|
||||
horizontal_space().into()
|
||||
}
|
||||
}
|
||||
|
||||
fn left_column(&self) -> Element<Message> {
|
||||
let title_input = text_input("song", &self.title)
|
||||
.on_input(Message::ChangeTitle)
|
||||
|
|
Loading…
Reference in a new issue