Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
5f85338c72 |
|||
|
4a292a5834 |
1 changed files with 33 additions and 2 deletions
|
|
@ -44,6 +44,8 @@ struct State {
|
||||||
|
|
||||||
columns: usize,
|
columns: usize,
|
||||||
|
|
||||||
|
key: usize,
|
||||||
|
|
||||||
error: Option<String>,
|
error: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -51,9 +53,10 @@ impl State {
|
||||||
fn new() -> (Self, Task<Message>) {
|
fn new() -> (Self, Task<Message>) {
|
||||||
(
|
(
|
||||||
Self {
|
Self {
|
||||||
columns: 3,
|
|
||||||
error: None,
|
|
||||||
images: BTreeMap::new(),
|
images: BTreeMap::new(),
|
||||||
|
columns: 3,
|
||||||
|
key: 0,
|
||||||
|
error: None,
|
||||||
},
|
},
|
||||||
Task::done(Message::OpenPath(Some(
|
Task::done(Message::OpenPath(Some(
|
||||||
env::args()
|
env::args()
|
||||||
|
|
@ -107,7 +110,7 @@ impl State {
|
||||||
.arg(path)
|
.arg(path)
|
||||||
.spawn()
|
.spawn()
|
||||||
.map_err(|e| e.to_string())
|
.map_err(|e| e.to_string())
|
||||||
.err()
|
.err();
|
||||||
}
|
}
|
||||||
|
|
||||||
Message::OpenPath(opt_path) => {
|
Message::OpenPath(opt_path) => {
|
||||||
|
|
@ -117,6 +120,7 @@ impl State {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(path) = opt_path {
|
if let Some(path) = opt_path {
|
||||||
|
self.key += 1;
|
||||||
self.open_path(path);
|
self.open_path(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -138,6 +142,31 @@ impl State {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
keyboard::Key::Character("j")
|
||||||
|
| keyboard::Key::Named(
|
||||||
|
keyboard::key::Named::ArrowDown | keyboard::key::Named::PageDown,
|
||||||
|
) => {
|
||||||
|
return widget::operation::scroll_by(
|
||||||
|
"main",
|
||||||
|
widget::operation::AbsoluteOffset {
|
||||||
|
x: 0.,
|
||||||
|
y: if modifiers.shift() { 100. } else { 30. },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
keyboard::Key::Character("k")
|
||||||
|
| keyboard::Key::Named(
|
||||||
|
keyboard::key::Named::ArrowUp | keyboard::key::Named::PageUp,
|
||||||
|
) => {
|
||||||
|
return widget::operation::scroll_by(
|
||||||
|
"main",
|
||||||
|
widget::operation::AbsoluteOffset {
|
||||||
|
x: 0.,
|
||||||
|
y: if modifiers.shift() { -100. } else { -30. },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
keyboard::Key::Character("=" | "+") => {
|
keyboard::Key::Character("=" | "+") => {
|
||||||
self.columns = (self.columns + 1).clamp(1, 10)
|
self.columns = (self.columns + 1).clamp(1, 10)
|
||||||
}
|
}
|
||||||
|
|
@ -164,6 +193,7 @@ impl State {
|
||||||
|| Element::from(widget::space()),
|
|| Element::from(widget::space()),
|
||||||
|handle| widget::image(handle).into(),
|
|handle| widget::image(handle).into(),
|
||||||
))
|
))
|
||||||
|
.key(self.key)
|
||||||
.anticipate(2000)
|
.anticipate(2000)
|
||||||
.on_show(|_size| Message::LoadImage(path.clone()))
|
.on_show(|_size| Message::LoadImage(path.clone()))
|
||||||
.on_hide(Message::UnloadImage(path.clone())),
|
.on_hide(Message::UnloadImage(path.clone())),
|
||||||
|
|
@ -185,6 +215,7 @@ impl State {
|
||||||
}))
|
}))
|
||||||
.columns(self.columns),
|
.columns(self.columns),
|
||||||
)
|
)
|
||||||
|
.id("main")
|
||||||
.height(Length::Fill)
|
.height(Length::Fill)
|
||||||
.into(),
|
.into(),
|
||||||
self.error.as_ref().map_or_else(
|
self.error.as_ref().map_or_else(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue