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 {
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue