Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
c4738ad2c8 |
|||
|
e32c18e304 |
|||
|
60717d639c |
1 changed files with 28 additions and 27 deletions
55
src/main.rs
55
src/main.rs
|
|
@ -79,9 +79,13 @@ impl State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Key::Character("o") => {
|
Key::Character("o") => match self.pick_and_load_image() {
|
||||||
return self.pick_and_load_image();
|
Ok(task) => {
|
||||||
}
|
self.error = None;
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
Err(e) => self.error = Some(e),
|
||||||
|
},
|
||||||
|
|
||||||
Key::Character("r") => {
|
Key::Character("r") => {
|
||||||
match self.image.as_ref() {
|
match self.image.as_ref() {
|
||||||
|
|
@ -115,9 +119,13 @@ impl State {
|
||||||
},
|
},
|
||||||
|
|
||||||
Message::Event(iced::Event::Window(window_event)) => match window_event {
|
Message::Event(iced::Event::Window(window_event)) => match window_event {
|
||||||
window::Event::FileDropped(file) => {
|
window::Event::FileDropped(file) => match self.load_image(file) {
|
||||||
return self.load_image(file);
|
Ok(task) => {
|
||||||
}
|
self.error = None;
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
Err(e) => self.error = Some(e),
|
||||||
|
},
|
||||||
|
|
||||||
// ignore unused window events
|
// ignore unused window events
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
@ -130,28 +138,14 @@ impl State {
|
||||||
Task::none()
|
Task::none()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[must_use]
|
fn load_image(&mut self, path: impl AsRef<Path>) -> Result<Task<Message>, String> {
|
||||||
fn load_image(&mut self, path: impl AsRef<Path>) -> Task<Message> {
|
utils::load_image(path).and_then(|image| {
|
||||||
let task;
|
self.image = Some(image);
|
||||||
(self.error, task) = match utils::load_image(path) {
|
Ok(self.allocate_image())
|
||||||
Ok(image) => {
|
})
|
||||||
self.image = Some(image);
|
|
||||||
(None, self.allocate_image())
|
|
||||||
}
|
|
||||||
Err(e) => (Some(e), Task::none()),
|
|
||||||
};
|
|
||||||
|
|
||||||
task
|
|
||||||
}
|
}
|
||||||
#[must_use]
|
fn pick_and_load_image(&mut self) -> Result<Task<Message>, String> {
|
||||||
fn pick_and_load_image(&mut self) -> Task<Message> {
|
utils::pick_image().and_then(|path| self.load_image(path))
|
||||||
let task;
|
|
||||||
(self.error, task) = match utils::pick_image() {
|
|
||||||
Ok(path) => (None, self.load_image(path)),
|
|
||||||
Err(e) => (Some(e), Task::none()),
|
|
||||||
};
|
|
||||||
|
|
||||||
task
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_image(&mut self) {
|
fn save_image(&mut self) {
|
||||||
|
|
@ -176,11 +170,18 @@ impl State {
|
||||||
fn subscription(&self) -> Subscription<Message> {
|
fn subscription(&self) -> Subscription<Message> {
|
||||||
event::listen().map(Message::Event)
|
event::listen().map(Message::Event)
|
||||||
}
|
}
|
||||||
|
fn title(&self) -> String {
|
||||||
|
match self.image.as_ref() {
|
||||||
|
Some(image) => format!("imagey {}x{}", image.width(), image.height()),
|
||||||
|
None => format!("imagey"),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), iced::Error> {
|
fn main() -> Result<(), iced::Error> {
|
||||||
iced::application(State::new, State::update, State::view)
|
iced::application(State::new, State::update, State::view)
|
||||||
.subscription(State::subscription)
|
.subscription(State::subscription)
|
||||||
|
.title(State::title)
|
||||||
.theme(Theme::custom(
|
.theme(Theme::custom(
|
||||||
"custom",
|
"custom",
|
||||||
theme::Palette {
|
theme::Palette {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue