Split Lyrics -> Editor + Lyrics
This commit is contained in:
parent
9b2a6ffde3
commit
02fbd15f44
|
@ -1,5 +1,5 @@
|
||||||
use crate::load_song::load_song;
|
use crate::load_song::load_song;
|
||||||
use crate::lyrics::Lyrics;
|
use crate::editor::Editor;
|
||||||
use crate::file_select::FileSelector;
|
use crate::file_select::FileSelector;
|
||||||
use rfd::AsyncFileDialog;
|
use rfd::AsyncFileDialog;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -17,7 +17,7 @@ use iced_native::window;
|
||||||
use iced_native::event::Event;
|
use iced_native::event::Event;
|
||||||
|
|
||||||
pub struct DelyriumApp {
|
pub struct DelyriumApp {
|
||||||
lyrics_component: Option<Lyrics>,
|
lyrics_component: Option<Editor>,
|
||||||
file_selector: FileSelector,
|
file_selector: FileSelector,
|
||||||
size: (u32, u32),
|
size: (u32, u32),
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ impl Application for DelyriumApp {
|
||||||
Message::FileOpened(path) => {
|
Message::FileOpened(path) => {
|
||||||
println!("File opened! {}", path.display());
|
println!("File opened! {}", path.display());
|
||||||
let song = load_song(&path).unwrap().format;
|
let song = load_song(&path).unwrap().format;
|
||||||
self.lyrics_component = Some(Lyrics::new(song, self.size));
|
self.lyrics_component = Some(Editor::new(song, self.size));
|
||||||
},
|
},
|
||||||
Message::PromptForFile => {
|
Message::PromptForFile => {
|
||||||
let task = async {
|
let task = async {
|
||||||
|
|
81
src/editor.rs
Normal file
81
src/editor.rs
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
use crate::lyrics::Lyric;
|
||||||
|
use crate::lyrics::Lyrics;
|
||||||
|
use crate::app::Message;
|
||||||
|
use iced::Element;
|
||||||
|
use crate::styles::Theme;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use iced::Container;
|
||||||
|
use iced::Row;
|
||||||
|
use crate::palette::Palette;
|
||||||
|
use crate::load_song::extract_cover;
|
||||||
|
use crate::peripheries::Periphery;
|
||||||
|
use iced::Length;
|
||||||
|
use iced::Align;
|
||||||
|
|
||||||
|
use symphonia::core::formats::FormatReader;
|
||||||
|
|
||||||
|
use image::GenericImageView;
|
||||||
|
pub struct Editor {
|
||||||
|
lyrics: Lyrics,
|
||||||
|
theme: Theme,
|
||||||
|
song: Box<dyn FormatReader>,
|
||||||
|
left_peri: Periphery,
|
||||||
|
rite_peri: Periphery,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Editor {
|
||||||
|
pub fn new(mut song: Box<dyn FormatReader>, size: (u32, u32)) -> Self {
|
||||||
|
let cover = extract_cover(song.as_mut());
|
||||||
|
|
||||||
|
let theme = cover.as_ref()
|
||||||
|
.map(|cover| {
|
||||||
|
Theme::from_palette(
|
||||||
|
Palette::generate(&cover)
|
||||||
|
)
|
||||||
|
}).unwrap_or_else(|| Theme::default());
|
||||||
|
|
||||||
|
let cover = cover.expect("TODO");
|
||||||
|
let cover = Arc::new(cover.blur((cover.width() / 50) as f32));
|
||||||
|
|
||||||
|
let left_peri = Periphery::new(cover.clone(), true, size);
|
||||||
|
let rite_peri = Periphery::new(cover, false, size);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
lyrics: Lyrics::new(),
|
||||||
|
song, theme, left_peri, rite_peri,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: work on untangling this mess
|
||||||
|
pub fn insert_text(&mut self, text: String) {
|
||||||
|
self.lyrics.insert_text(text);
|
||||||
|
}
|
||||||
|
pub fn update_line(&mut self, new_content: String, line_no: usize) {
|
||||||
|
self.lyrics.update_line(new_content, line_no);
|
||||||
|
}
|
||||||
|
pub fn advance_line(&mut self, current_line: usize) {
|
||||||
|
self.lyrics.advance_line(current_line);
|
||||||
|
}
|
||||||
|
pub fn current_line_mut(&mut self) -> (usize, &mut Lyric) {
|
||||||
|
self.lyrics.current_line_mut()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn notify_resized(&mut self, w: u32, h: u32) {
|
||||||
|
self.left_peri.notify_resized(w, h);
|
||||||
|
self.rite_peri.notify_resized(w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn view(&mut self) -> Element<Message> {
|
||||||
|
|
||||||
|
Container::new(
|
||||||
|
Row::new()
|
||||||
|
.push(self.left_peri.view())
|
||||||
|
.push(self.lyrics.view(self.theme))
|
||||||
|
.push(self.rite_peri.view())
|
||||||
|
)
|
||||||
|
.align_y(Align::Center)
|
||||||
|
.style(self.theme)
|
||||||
|
.height(Length::Fill)
|
||||||
|
.into()
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,56 +1,25 @@
|
||||||
use std::sync::Arc;
|
use iced::Length;
|
||||||
use iced::Container;
|
|
||||||
use iced::Row;
|
|
||||||
use crate::palette::Palette;
|
|
||||||
use crate::load_song::extract_cover;
|
|
||||||
use iced::Element;
|
use iced::Element;
|
||||||
use crate::styles::Theme;
|
use crate::styles::Theme;
|
||||||
use crate::app::Message;
|
use crate::app::Message;
|
||||||
use crate::peripheries::Periphery;
|
|
||||||
|
|
||||||
use iced::Align;
|
|
||||||
use iced::Length;
|
|
||||||
use iced::widget::text_input::{self, TextInput};
|
use iced::widget::text_input::{self, TextInput};
|
||||||
use iced::widget::scrollable::{self, Scrollable};
|
use iced::widget::scrollable::{self, Scrollable};
|
||||||
|
use iced::Align;
|
||||||
use symphonia::core::formats::FormatReader;
|
|
||||||
|
|
||||||
use image::GenericImageView;
|
|
||||||
|
|
||||||
pub struct Lyrics {
|
pub struct Lyrics {
|
||||||
lines: Vec<Lyric>,
|
lines: Vec<Lyric>,
|
||||||
scroll_state: scrollable::State,
|
scroll_state: scrollable::State,
|
||||||
theme: Theme,
|
|
||||||
song: Box<dyn FormatReader>,
|
|
||||||
left_peri: Periphery,
|
|
||||||
rite_peri: Periphery,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Lyrics {
|
impl Lyrics {
|
||||||
pub fn new(mut song: Box<dyn FormatReader>, size: (u32, u32)) -> Self {
|
pub fn new() -> Lyrics {
|
||||||
|
|
||||||
let mut lyric = Lyric::new();
|
let mut lyric = Lyric::new();
|
||||||
lyric.select();
|
lyric.select();
|
||||||
|
|
||||||
let cover = extract_cover(song.as_mut());
|
Self {
|
||||||
|
|
||||||
let theme = cover.as_ref()
|
|
||||||
.map(|cover| {
|
|
||||||
Theme::from_palette(
|
|
||||||
Palette::generate(&cover)
|
|
||||||
)
|
|
||||||
}).unwrap_or_else(|| Theme::default());
|
|
||||||
|
|
||||||
let cover = cover.expect("TODO");
|
|
||||||
let cover = Arc::new(cover.blur((cover.width() / 50) as f32));
|
|
||||||
|
|
||||||
let left_peri = Periphery::new(cover.clone(), true, size);
|
|
||||||
let rite_peri = Periphery::new(cover, false, size);
|
|
||||||
|
|
||||||
Lyrics {
|
|
||||||
lines: vec![lyric],
|
lines: vec![lyric],
|
||||||
scroll_state: scrollable::State::new(),
|
scroll_state: scrollable::State::new(),
|
||||||
song, theme, left_peri, rite_peri,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,11 +67,6 @@ impl Lyrics {
|
||||||
.deselect();
|
.deselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn notify_resized(&mut self, w: u32, h: u32) {
|
|
||||||
self.left_peri.notify_resized(w, h);
|
|
||||||
self.rite_peri.notify_resized(w, h);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn insert_line(&mut self, index: usize, content: Option<String>) -> &mut Lyric {
|
pub fn insert_line(&mut self, index: usize, content: Option<String>) -> &mut Lyric {
|
||||||
self.lines.insert(index, match content {
|
self.lines.insert(index, match content {
|
||||||
Some(content) => Lyric::new_with_value(content),
|
Some(content) => Lyric::new_with_value(content),
|
||||||
|
@ -120,29 +84,20 @@ impl Lyrics {
|
||||||
.expect("no line currently selected")
|
.expect("no line currently selected")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&mut self) -> Element<Message> {
|
pub fn view(&mut self, theme: Theme) -> Element<Message> {
|
||||||
let is_sole_line = self.lines.len() == 1;
|
let is_sole_line = self.lines.len() == 1;
|
||||||
|
|
||||||
let lyrics = self.lines.iter_mut()
|
self.lines.iter_mut()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, l)| l.view(is_sole_line, i, self.theme))
|
.map(|(i, l)| l.view(is_sole_line, i, theme))
|
||||||
.fold(Scrollable::new(&mut self.scroll_state), |s, l| s.push(l))
|
.fold(Scrollable::new(&mut self.scroll_state), |s, l| s.push(l))
|
||||||
.width(Length::Fill)
|
.width(Length::Fill)
|
||||||
.align_items(Align::Center);
|
.align_items(Align::Center)
|
||||||
|
|
||||||
Container::new(
|
|
||||||
Row::new()
|
|
||||||
.push(self.left_peri.view())
|
|
||||||
.push(lyrics)
|
|
||||||
.push(self.rite_peri.view())
|
|
||||||
)
|
|
||||||
.align_y(Align::Center)
|
|
||||||
.style(self.theme)
|
|
||||||
.height(Length::Fill)
|
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Lyric {
|
pub struct Lyric {
|
||||||
state: text_input::State,
|
state: text_input::State,
|
||||||
|
|
|
@ -8,6 +8,7 @@ mod styles;
|
||||||
mod file_select;
|
mod file_select;
|
||||||
mod load_song;
|
mod load_song;
|
||||||
mod peripheries;
|
mod peripheries;
|
||||||
|
mod editor;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
app::DelyriumApp::run(Settings::default()).unwrap();
|
app::DelyriumApp::run(Settings::default()).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue