feat: basic input field cycling
This commit is contained in:
parent
d9c7807cca
commit
c28204bd9f
1 changed files with 35 additions and 3 deletions
38
src/main.rs
38
src/main.rs
|
|
@ -1,9 +1,11 @@
|
|||
use std::fs;
|
||||
|
||||
use iced::{
|
||||
Color, Element, Renderer, Theme,
|
||||
Color, Element, Renderer, Subscription, Task, Theme,
|
||||
alignment::{Horizontal, Vertical},
|
||||
color, widget,
|
||||
color, event,
|
||||
keyboard::{self, Key, key},
|
||||
widget,
|
||||
};
|
||||
|
||||
mod data;
|
||||
|
|
@ -42,6 +44,8 @@ enum Message {
|
|||
i_element: usize,
|
||||
new_value: String,
|
||||
},
|
||||
|
||||
Event(iced::Event),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
|
|
@ -134,7 +138,7 @@ impl State {
|
|||
.padding(15)
|
||||
.into()
|
||||
}
|
||||
fn update(&mut self, message: Message) {
|
||||
fn update(&mut self, message: Message) -> Task<Message> {
|
||||
match message {
|
||||
Message::AddCategory => {
|
||||
self.table.push(Default::default());
|
||||
|
|
@ -175,7 +179,34 @@ impl State {
|
|||
} => {
|
||||
self.table[i_category].elements[i_element] = new_value;
|
||||
}
|
||||
|
||||
Message::Event(iced::Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key,
|
||||
modifiers,
|
||||
..
|
||||
})) => match key.as_ref() {
|
||||
// input field cycling
|
||||
Key::Named(key::Named::Tab) => {
|
||||
if modifiers.shift() {
|
||||
return widget::operation::focus_previous();
|
||||
} else {
|
||||
return widget::operation::focus_next();
|
||||
}
|
||||
}
|
||||
|
||||
// ignore unused keys
|
||||
_ => {}
|
||||
},
|
||||
|
||||
// ignore unused events
|
||||
Message::Event(_) => {}
|
||||
}
|
||||
|
||||
Task::none()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
event::listen().map(Message::Event)
|
||||
}
|
||||
}
|
||||
impl Drop for State {
|
||||
|
|
@ -188,6 +219,7 @@ impl Drop for State {
|
|||
|
||||
fn main() -> Result<(), iced::Error> {
|
||||
iced::application(State::new, State::update, State::view)
|
||||
.subscription(State::subscription)
|
||||
.theme(Theme::custom(
|
||||
"custom",
|
||||
iced::theme::Palette {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue