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> {
|
pub fn view(&self) -> Element<Message> {
|
||||||
self.slide_view(
|
slide_view(
|
||||||
&self.current_slide,
|
self.current_slide.clone(),
|
||||||
|
&self.video,
|
||||||
self.current_font,
|
self.current_font,
|
||||||
false,
|
false,
|
||||||
true,
|
true,
|
||||||
|
@ -377,8 +378,9 @@ impl Presenter {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view_preview(&self) -> Element<Message> {
|
pub fn view_preview(&self) -> Element<Message> {
|
||||||
self.slide_view(
|
slide_view(
|
||||||
&self.current_slide,
|
self.current_slide.clone(),
|
||||||
|
&self.video,
|
||||||
self.current_font,
|
self.current_font,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -419,7 +421,8 @@ impl Presenter {
|
||||||
self.slides.iter().position(|s| s == slide).unwrap()
|
self.slides.iter().position(|s| s == slide).unwrap()
|
||||||
as i32;
|
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(
|
let delegate = mouse_area(
|
||||||
Container::new(container)
|
Container::new(container)
|
||||||
.style(move |t| {
|
.style(move |t| {
|
||||||
|
@ -479,105 +482,6 @@ impl Presenter {
|
||||||
delegate.into()
|
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) {
|
fn reset_video(&mut self) {
|
||||||
if let Some(slide) =
|
if let Some(slide) =
|
||||||
self.slides.get(self.current_slide_index as usize)
|
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
|
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 std::path::PathBuf;
|
||||||
|
|
||||||
use cosmic::{
|
use cosmic::{
|
||||||
iced::Length,
|
iced::{
|
||||||
|
font::{Family, Stretch, Style, Weight},
|
||||||
|
Font, Length,
|
||||||
|
},
|
||||||
iced_widget::row,
|
iced_widget::row,
|
||||||
widget::{
|
widget::{
|
||||||
button, column, combo_box, container, dropdown,
|
button, column, combo_box, container, dropdown,
|
||||||
|
@ -10,9 +13,15 @@ use cosmic::{
|
||||||
},
|
},
|
||||||
Element, Task,
|
Element, Task,
|
||||||
};
|
};
|
||||||
|
use iced_video_player::Video;
|
||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use crate::core::songs::Song;
|
use crate::{
|
||||||
|
core::{service_items::ServiceTrait, songs::Song},
|
||||||
|
Background,
|
||||||
|
};
|
||||||
|
|
||||||
|
use super::presenter::slide_view;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SongEditor {
|
pub struct SongEditor {
|
||||||
|
@ -27,6 +36,9 @@ pub struct SongEditor {
|
||||||
verse_order: String,
|
verse_order: String,
|
||||||
lyrics: text_editor::Content,
|
lyrics: text_editor::Content,
|
||||||
editing: bool,
|
editing: bool,
|
||||||
|
background: Option<Background>,
|
||||||
|
video: Option<Video>,
|
||||||
|
current_font: Font,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -68,6 +80,9 @@ impl SongEditor {
|
||||||
editing: false,
|
editing: false,
|
||||||
author: "North Point Worship".into(),
|
author: "North Point Worship".into(),
|
||||||
audio: PathBuf::new(),
|
audio: PathBuf::new(),
|
||||||
|
background: None,
|
||||||
|
video: None,
|
||||||
|
current_font: cosmic::font::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn update(&mut self, message: Message) -> Task<Message> {
|
pub fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
|
@ -81,7 +96,20 @@ impl SongEditor {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
Message::ChangeFont(font) => {
|
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()
|
Task::none()
|
||||||
}
|
}
|
||||||
Message::ChangeFontSize(size) => {
|
Message::ChangeFontSize(size) => {
|
||||||
|
@ -121,8 +149,8 @@ impl SongEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&self) -> Element<Message> {
|
pub fn view(&self) -> Element<Message> {
|
||||||
let slide_preview =
|
let slide_preview = container(self.slide_preview())
|
||||||
container(vertical_space()).width(Length::FillPortion(2));
|
.width(Length::FillPortion(2));
|
||||||
|
|
||||||
let column = column::with_children(vec![
|
let column = column::with_children(vec![
|
||||||
self.toolbar(),
|
self.toolbar(),
|
||||||
|
@ -131,6 +159,31 @@ impl SongEditor {
|
||||||
column.into()
|
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> {
|
fn left_column(&self) -> Element<Message> {
|
||||||
let title_input = text_input("song", &self.title)
|
let title_input = text_input("song", &self.title)
|
||||||
.on_input(Message::ChangeTitle)
|
.on_input(Message::ChangeTitle)
|
||||||
|
|
Loading…
Reference in a new issue