Compare commits

..
Author SHA1 Message Date
5f85338c72
feat: rudimentary keyboard scrolling
I want smooth scrolling :(
2026-08-09 22:12:49 -07:00
4a292a5834
fix: initial images not loading on opening new path 2026-08-09 21:53:06 -07:00

View file

@ -44,6 +44,8 @@ struct State {
columns: usize,
key: usize,
error: Option<String>,
}
@ -51,9 +53,10 @@ impl State {
fn new() -> (Self, Task<Message>) {
(
Self {
columns: 3,
error: None,
images: BTreeMap::new(),
columns: 3,
key: 0,
error: None,
},
Task::done(Message::OpenPath(Some(
env::args()
@ -107,7 +110,7 @@ impl State {
.arg(path)
.spawn()
.map_err(|e| e.to_string())
.err()
.err();
}
Message::OpenPath(opt_path) => {
@ -117,6 +120,7 @@ impl State {
};
if let Some(path) = opt_path {
self.key += 1;
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("=" | "+") => {
self.columns = (self.columns + 1).clamp(1, 10)
}
@ -164,6 +193,7 @@ impl State {
|| Element::from(widget::space()),
|handle| widget::image(handle).into(),
))
.key(self.key)
.anticipate(2000)
.on_show(|_size| Message::LoadImage(path.clone()))
.on_hide(Message::UnloadImage(path.clone())),
@ -185,6 +215,7 @@ impl State {
}))
.columns(self.columns),
)
.id("main")
.height(Length::Fill)
.into(),
self.error.as_ref().map_or_else(