Add the start of a UI with Iced
This commit is contained in:
parent
68c74ab234
commit
558b32ae28
2664
Cargo.lock
generated
2664
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,5 +6,12 @@ edition = "2021"
|
|||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
# Used for color palette generation
|
||||
exoquant = "0.2.0"
|
||||
|
||||
# Used for parsing album artwork
|
||||
image = "0.23.14"
|
||||
|
||||
# Display windows & graphics
|
||||
iced = "0.3.0"
|
||||
|
|
71
src/app/lyrics.rs
Normal file
71
src/app/lyrics.rs
Normal file
|
@ -0,0 +1,71 @@
|
|||
use crate::app::Message;
|
||||
use crate::app::Element;
|
||||
|
||||
use iced::widget::text_input::{self, TextInput};
|
||||
use iced::widget::scrollable::{self, Scrollable};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Lyrics {
|
||||
lines: Vec<Lyric>,
|
||||
scroll_state: scrollable::State,
|
||||
}
|
||||
|
||||
impl Lyrics {
|
||||
pub fn new() -> Self {
|
||||
Lyrics {
|
||||
lines: vec![Lyric::new(0)],
|
||||
scroll_state: scrollable::State::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: &Message) {
|
||||
self.lines.iter_mut()
|
||||
.for_each(|l| l.update(message));
|
||||
}
|
||||
|
||||
pub fn view(&mut self) -> Element<Message> {
|
||||
self.lines.iter_mut()
|
||||
.map(Lyric::view)
|
||||
.fold(Scrollable::new(&mut self.scroll_state), |s, l| s.push(l))
|
||||
.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Lyric {
|
||||
state: text_input::State,
|
||||
value: String,
|
||||
line_no: usize,
|
||||
}
|
||||
|
||||
impl Lyric {
|
||||
pub fn new(line_no: usize) -> Self {
|
||||
Lyric {
|
||||
state: text_input::State::new(),
|
||||
value: String::with_capacity(70),
|
||||
line_no,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn view(&mut self) -> Element<Message> {
|
||||
let line_no = self.line_no;
|
||||
TextInput::new(
|
||||
&mut self.state,
|
||||
"",
|
||||
&self.value,
|
||||
move|new_value| Message::LyricChanged { line_no, new_value },
|
||||
)
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn update(&mut self, message: &Message) {
|
||||
match message {
|
||||
Message::LyricChanged {
|
||||
line_no, new_value,
|
||||
} if *line_no == self.line_no => {
|
||||
self.value = new_value.clone();
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
}
|
45
src/app/mod.rs
Normal file
45
src/app/mod.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use iced::Container;
|
||||
use iced::Row;
|
||||
use iced::Element;
|
||||
use iced::Sandbox;
|
||||
|
||||
mod lyrics;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct DelyriumApp {
|
||||
lyrics_component: lyrics::Lyrics,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum Message {
|
||||
LyricChanged {
|
||||
line_no: usize,
|
||||
new_value: String,
|
||||
},
|
||||
}
|
||||
|
||||
impl Sandbox for DelyriumApp {
|
||||
type Message = Message;
|
||||
|
||||
fn new() -> Self {
|
||||
DelyriumApp {
|
||||
lyrics_component: lyrics::Lyrics::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Delyrium")
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) {
|
||||
self.lyrics_component.update(&message);
|
||||
}
|
||||
|
||||
fn view(&mut self) -> Element<Message> {
|
||||
Container::new(
|
||||
Row::new()
|
||||
.push(self.lyrics_component.view())
|
||||
)
|
||||
.into()
|
||||
}
|
||||
}
|
15
src/main.rs
15
src/main.rs
|
@ -1,14 +1,9 @@
|
|||
use iced::Sandbox;
|
||||
use iced::settings::Settings;
|
||||
|
||||
mod palette;
|
||||
mod app;
|
||||
|
||||
fn main() {
|
||||
let image = image::open("image.png")
|
||||
.expect("Failed to open image");
|
||||
|
||||
let colors = palette::Palette::generate(image);
|
||||
|
||||
println!("Dominant color: {:?}", colors.dominant_color());
|
||||
println!("All colors:");
|
||||
for color in &colors.raw_colors {
|
||||
println!("\t{:?}", color);
|
||||
}
|
||||
app::DelyriumApp::run(Settings::default());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue