Make it feel a little more lyric-editory
This commit is contained in:
parent
66daa5bd0e
commit
5a4992c419
|
@ -1,6 +1,9 @@
|
||||||
|
use crate::app::Theme;
|
||||||
use crate::app::Message;
|
use crate::app::Message;
|
||||||
use crate::app::Element;
|
use crate::app::Element;
|
||||||
|
|
||||||
|
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};
|
||||||
|
|
||||||
|
@ -12,8 +15,10 @@ pub struct Lyrics {
|
||||||
|
|
||||||
impl Lyrics {
|
impl Lyrics {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
let mut lyric = Lyric::new();
|
||||||
|
lyric.select();
|
||||||
Lyrics {
|
Lyrics {
|
||||||
lines: vec![Lyric::new()],
|
lines: vec![lyric],
|
||||||
scroll_state: scrollable::State::new()
|
scroll_state: scrollable::State::new()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,11 +42,14 @@ impl Lyrics {
|
||||||
.deselect();
|
.deselect();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&mut self) -> Element<Message> {
|
pub fn view(&mut self, theme: Theme) -> Element<Message> {
|
||||||
|
let is_sole_line = self.lines.len() == 1;
|
||||||
self.lines.iter_mut()
|
self.lines.iter_mut()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, l)| l.view(i))
|
.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)
|
||||||
|
.align_items(Align::Center)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,13 +68,25 @@ impl Lyric {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn view(&mut self, line_no: usize) -> Element<Message> {
|
pub fn view(&mut self, show_placeholder: bool, line_no: usize, theme: Theme) -> Element<Message> {
|
||||||
|
|
||||||
|
let placeholder = if show_placeholder {
|
||||||
|
"Paste some lyrics to get started"
|
||||||
|
} else if self.state.is_focused() {
|
||||||
|
"..."
|
||||||
|
} else { "" };
|
||||||
|
|
||||||
|
let size = if self.state.is_focused() { 30 } else { 20 };
|
||||||
|
|
||||||
TextInput::new(
|
TextInput::new(
|
||||||
&mut self.state,
|
&mut self.state,
|
||||||
"",
|
placeholder,
|
||||||
&self.value,
|
&self.value,
|
||||||
move|new_value| Message::LyricChanged { line_no, new_value },
|
move|new_value| Message::LyricChanged { line_no, new_value },
|
||||||
)
|
)
|
||||||
|
.style(theme)
|
||||||
|
.size(size)
|
||||||
|
.width(Length::Units(300))
|
||||||
.on_submit(Message::LineAdvanced(line_no))
|
.on_submit(Message::LineAdvanced(line_no))
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
@ -77,6 +97,7 @@ impl Lyric {
|
||||||
|
|
||||||
pub fn select(&mut self) {
|
pub fn select(&mut self) {
|
||||||
self.state.focus();
|
self.state.focus();
|
||||||
|
self.state.move_cursor_to_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deselect(&mut self) {
|
pub fn deselect(&mut self) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ use iced::Row;
|
||||||
use iced::Element;
|
use iced::Element;
|
||||||
use iced::Sandbox;
|
use iced::Sandbox;
|
||||||
use iced::Length;
|
use iced::Length;
|
||||||
|
use iced::Align;
|
||||||
|
|
||||||
mod lyrics;
|
mod lyrics;
|
||||||
mod styles;
|
mod styles;
|
||||||
|
@ -52,8 +53,9 @@ impl Sandbox for DelyriumApp {
|
||||||
fn view(&mut self) -> Element<Message> {
|
fn view(&mut self) -> Element<Message> {
|
||||||
Container::new(
|
Container::new(
|
||||||
Row::new()
|
Row::new()
|
||||||
.push(self.lyrics_component.view())
|
.push(self.lyrics_component.view(self.theme))
|
||||||
)
|
)
|
||||||
|
.align_y(Align::Center)
|
||||||
.style(self.theme)
|
.style(self.theme)
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.into()
|
.into()
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
use iced::Background;
|
use iced::Background;
|
||||||
use iced::Color;
|
use iced::Color;
|
||||||
use iced::widget::container;
|
use iced::widget::container;
|
||||||
|
use iced::widget::text_input;
|
||||||
|
|
||||||
|
const TRANSPARENT: Color = Color { r: 0., g: 0., b: 0., a: 0. };
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct Theme {
|
pub struct Theme {
|
||||||
|
@ -26,3 +29,32 @@ impl container::StyleSheet for Theme {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl text_input::StyleSheet for Theme {
|
||||||
|
fn active(&self) -> text_input::Style {
|
||||||
|
text_input::Style {
|
||||||
|
background: Background::Color(self.base_color),
|
||||||
|
border_radius: 0.,
|
||||||
|
border_width: 0.,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn focused(&self) -> text_input::Style {
|
||||||
|
self.active()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn placeholder_color(&self) -> Color {
|
||||||
|
let mut color = self.text_color;
|
||||||
|
color.a = 0.5;
|
||||||
|
color
|
||||||
|
}
|
||||||
|
|
||||||
|
fn value_color(&self) -> Color {
|
||||||
|
self.text_color
|
||||||
|
}
|
||||||
|
|
||||||
|
fn selection_color(&self) -> Color {
|
||||||
|
self.text_color
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue