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 std::fs;
|
||||||
|
|
||||||
use iced::{
|
use iced::{
|
||||||
Color, Element, Renderer, Theme,
|
Color, Element, Renderer, Subscription, Task, Theme,
|
||||||
alignment::{Horizontal, Vertical},
|
alignment::{Horizontal, Vertical},
|
||||||
color, widget,
|
color, event,
|
||||||
|
keyboard::{self, Key, key},
|
||||||
|
widget,
|
||||||
};
|
};
|
||||||
|
|
||||||
mod data;
|
mod data;
|
||||||
|
|
@ -42,6 +44,8 @@ enum Message {
|
||||||
i_element: usize,
|
i_element: usize,
|
||||||
new_value: String,
|
new_value: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Event(iced::Event),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default)]
|
#[derive(Clone, Debug, Default)]
|
||||||
|
|
@ -134,7 +138,7 @@ impl State {
|
||||||
.padding(15)
|
.padding(15)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
fn update(&mut self, message: Message) {
|
fn update(&mut self, message: Message) -> Task<Message> {
|
||||||
match message {
|
match message {
|
||||||
Message::AddCategory => {
|
Message::AddCategory => {
|
||||||
self.table.push(Default::default());
|
self.table.push(Default::default());
|
||||||
|
|
@ -175,7 +179,34 @@ impl State {
|
||||||
} => {
|
} => {
|
||||||
self.table[i_category].elements[i_element] = new_value;
|
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 {
|
impl Drop for State {
|
||||||
|
|
@ -188,6 +219,7 @@ impl Drop for State {
|
||||||
|
|
||||||
fn main() -> Result<(), iced::Error> {
|
fn main() -> Result<(), iced::Error> {
|
||||||
iced::application(State::new, State::update, State::view)
|
iced::application(State::new, State::update, State::view)
|
||||||
|
.subscription(State::subscription)
|
||||||
.theme(Theme::custom(
|
.theme(Theme::custom(
|
||||||
"custom",
|
"custom",
|
||||||
iced::theme::Palette {
|
iced::theme::Palette {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue