feat: keybinds to change number of columns

This commit is contained in:
electria 2026-08-09 13:31:06 -07:00
commit 2eacdaeb8f
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -23,6 +23,8 @@ enum Message {
struct State {
images: HashMap<PathBuf, Option<widget::image::Handle>>,
columns: usize,
error: Option<String>,
}
@ -36,6 +38,7 @@ impl State {
builder.select("supportedImages");
Self {
columns: 3,
error: None,
images: WalkBuilder::new(
env::args()
@ -87,6 +90,13 @@ impl State {
};
}
keyboard::Key::Character("=" | "+") => {
self.columns = (self.columns + 1).clamp(1, 10)
}
keyboard::Key::Character("-" | "_") => {
self.columns = (self.columns - 1).clamp(1, 10)
}
keyboard::Key::Character("q") => {
return window::latest().and_then(window::close);
}
@ -98,8 +108,8 @@ impl State {
}
fn view(&self) -> Element<'_, Message, Theme, Renderer> {
widget::column([
widget::scrollable(widget::grid(self.images.iter().map(
|(path, opt_handle)| {
widget::scrollable(
widget::grid(self.images.iter().map(|(path, opt_handle)| {
widget::button(
widget::container(
widget::sensor(opt_handle.as_ref().map_or_else(
@ -114,8 +124,9 @@ impl State {
.style(widget::button::subtle)
.on_press(Message::OpenImage(path.clone()))
.into()
},
)))
}))
.columns(self.columns),
)
.height(Length::Fill)
.into(),
self.error