the song_editor has it's slides in it's state now
This commit is contained in:
parent
302d9f1582
commit
944b365d19
1 changed files with 60 additions and 61 deletions
|
|
@ -19,6 +19,7 @@ use cosmic::{
|
||||||
};
|
};
|
||||||
use dirs::font_dir;
|
use dirs::font_dir;
|
||||||
use iced_video_player::Video;
|
use iced_video_player::Video;
|
||||||
|
use rayon::iter::{IntoParallelIterator, ParallelIterator};
|
||||||
use tracing::{debug, error, warn};
|
use tracing::{debug, error, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -34,7 +35,6 @@ pub struct SongEditor {
|
||||||
pub song: Option<Song>,
|
pub song: Option<Song>,
|
||||||
title: String,
|
title: String,
|
||||||
font_db: Arc<fontdb::Database>,
|
font_db: Arc<fontdb::Database>,
|
||||||
fonts: Vec<(fontdb::ID, String)>,
|
|
||||||
fonts_combo: combo_box::State<String>,
|
fonts_combo: combo_box::State<String>,
|
||||||
font_sizes: combo_box::State<String>,
|
font_sizes: combo_box::State<String>,
|
||||||
font: String,
|
font: String,
|
||||||
|
|
@ -48,7 +48,7 @@ pub struct SongEditor {
|
||||||
video: Option<Video>,
|
video: Option<Video>,
|
||||||
current_font: Font,
|
current_font: Font,
|
||||||
ccli: String,
|
ccli: String,
|
||||||
song_as_slide: Option<Vec<Slide>>,
|
song_slides: Option<Vec<Slide>>,
|
||||||
slide_state: SlideEditor,
|
slide_state: SlideEditor,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,22 +79,12 @@ impl SongEditor {
|
||||||
pub fn new(font_db: Arc<fontdb::Database>) -> Self {
|
pub fn new(font_db: Arc<fontdb::Database>) -> Self {
|
||||||
let fonts = font_dir();
|
let fonts = font_dir();
|
||||||
debug!(?fonts);
|
debug!(?fonts);
|
||||||
let mut fonts: Vec<(fontdb::ID, String)> = font_db
|
let mut fonts: Vec<String> = font_db
|
||||||
.faces()
|
.faces()
|
||||||
.map(|f| {
|
.map(|f| f.families[0].0.clone())
|
||||||
let id = f.id;
|
|
||||||
let font_base_name: String = f.families[0].0.clone();
|
|
||||||
let font_weight = f.weight;
|
|
||||||
let font_style = f.style;
|
|
||||||
let font_stretch = f.stretch;
|
|
||||||
(id, font_base_name)
|
|
||||||
})
|
|
||||||
.collect();
|
.collect();
|
||||||
fonts.dedup();
|
fonts.dedup();
|
||||||
// let fonts = vec![
|
fonts.sort();
|
||||||
// String::from("Quicksand"),
|
|
||||||
// String::from("Noto Sans"),
|
|
||||||
// ];
|
|
||||||
let font_sizes = vec![
|
let font_sizes = vec![
|
||||||
"5".to_string(),
|
"5".to_string(),
|
||||||
"6".to_string(),
|
"6".to_string(),
|
||||||
|
|
@ -126,15 +116,10 @@ impl SongEditor {
|
||||||
"160".to_string(),
|
"160".to_string(),
|
||||||
"170".to_string(),
|
"170".to_string(),
|
||||||
];
|
];
|
||||||
let mut font_texts: Vec<String> =
|
|
||||||
fonts.iter().map(|f| f.1.to_string()).collect();
|
|
||||||
font_texts.dedup();
|
|
||||||
font_texts.sort();
|
|
||||||
Self {
|
Self {
|
||||||
song: None,
|
song: None,
|
||||||
font_db,
|
font_db,
|
||||||
fonts,
|
fonts_combo: combo_box::State::new(fonts),
|
||||||
fonts_combo: combo_box::State::new(font_texts),
|
|
||||||
title: "Death was Arrested".to_string(),
|
title: "Death was Arrested".to_string(),
|
||||||
font: "Quicksand".to_string(),
|
font: "Quicksand".to_string(),
|
||||||
font_size: 16,
|
font_size: 16,
|
||||||
|
|
@ -149,13 +134,24 @@ impl SongEditor {
|
||||||
current_font: cosmic::font::default(),
|
current_font: cosmic::font::default(),
|
||||||
ccli: "8".to_string(),
|
ccli: "8".to_string(),
|
||||||
slide_state: SlideEditor::default(),
|
slide_state: SlideEditor::default(),
|
||||||
song_as_slide: None,
|
song_slides: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn update(&mut self, message: Message) -> Action {
|
pub fn update(&mut self, message: Message) -> Action {
|
||||||
match message {
|
match message {
|
||||||
Message::ChangeSong(song) => {
|
Message::ChangeSong(song) => {
|
||||||
self.song = Some(song.clone());
|
self.song = Some(song.clone());
|
||||||
|
self.song_slides = song.to_slides().ok().map(|v| {
|
||||||
|
v.into_par_iter()
|
||||||
|
.map(|mut s| {
|
||||||
|
text_svg::text_svg_generator(
|
||||||
|
&mut s,
|
||||||
|
Arc::clone(&self.font_db),
|
||||||
|
);
|
||||||
|
s
|
||||||
|
})
|
||||||
|
.collect::<Vec<Slide>>()
|
||||||
|
});
|
||||||
self.title = song.title;
|
self.title = song.title;
|
||||||
if let Some(font) = song.font {
|
if let Some(font) = song.font {
|
||||||
self.font = font;
|
self.font = font;
|
||||||
|
|
@ -317,46 +313,38 @@ impl SongEditor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn slide_preview(&self) -> Element<Message> {
|
fn slide_preview(&self) -> Element<Message> {
|
||||||
if let Some(song) = &self.song {
|
if let Some(slides) = &self.song_slides {
|
||||||
if let Ok(slides) = song.to_slides() {
|
let slides: Vec<Element<Message>> = slides
|
||||||
let slides: Vec<Element<Message>> = slides
|
.into_iter()
|
||||||
.into_iter()
|
.enumerate()
|
||||||
.enumerate()
|
.map(|(index, slide)| {
|
||||||
.map(|(index, mut slide)| {
|
container(
|
||||||
text_svg::text_svg_generator(
|
slide_view(
|
||||||
&mut slide,
|
slide.clone(),
|
||||||
Arc::clone(&self.font_db),
|
if index == 0 {
|
||||||
);
|
&self.video
|
||||||
container(
|
} else {
|
||||||
slide_view(
|
&None
|
||||||
slide,
|
},
|
||||||
if index == 0 {
|
false,
|
||||||
&self.video
|
false,
|
||||||
} else {
|
|
||||||
&None
|
|
||||||
},
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.map(|_| Message::None),
|
|
||||||
)
|
)
|
||||||
.height(250)
|
.map(|_| Message::None),
|
||||||
.center_x(Length::Fill)
|
)
|
||||||
.padding([0, 20])
|
.height(250)
|
||||||
.clip(true)
|
.center_x(Length::Fill)
|
||||||
.into()
|
.padding([0, 20])
|
||||||
})
|
.clip(true)
|
||||||
.collect();
|
.into()
|
||||||
scrollable(
|
})
|
||||||
cosmic::widget::column::with_children(slides)
|
.collect();
|
||||||
.spacing(theme::active().cosmic().space_l()),
|
scrollable(
|
||||||
)
|
cosmic::widget::column::with_children(slides)
|
||||||
.height(Length::Fill)
|
.spacing(theme::active().cosmic().space_l()),
|
||||||
.width(Length::Fill)
|
)
|
||||||
.into()
|
.height(Length::Fill)
|
||||||
} else {
|
.width(Length::Fill)
|
||||||
horizontal_space().into()
|
.into()
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
horizontal_space().into()
|
horizontal_space().into()
|
||||||
}
|
}
|
||||||
|
|
@ -450,6 +438,17 @@ order",
|
||||||
|
|
||||||
fn update_song(&mut self, song: Song) -> Action {
|
fn update_song(&mut self, song: Song) -> Action {
|
||||||
self.song = Some(song.clone());
|
self.song = Some(song.clone());
|
||||||
|
self.song_slides = song.to_slides().ok().map(|v| {
|
||||||
|
v.into_par_iter()
|
||||||
|
.map(|mut s| {
|
||||||
|
text_svg::text_svg_generator(
|
||||||
|
&mut s,
|
||||||
|
Arc::clone(&self.font_db),
|
||||||
|
);
|
||||||
|
s
|
||||||
|
})
|
||||||
|
.collect::<Vec<Slide>>()
|
||||||
|
});
|
||||||
Action::UpdateSong(song)
|
Action::UpdateSong(song)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue