feat: keybinds to change number of columns
This commit is contained in:
parent
d1056e9fbe
commit
2eacdaeb8f
1 changed files with 15 additions and 4 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue