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