feat: basic input field cycling

This commit is contained in:
electria 2026-06-25 15:29:08 -07:00
commit c28204bd9f
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -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,8 +179,35 @@ 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 {
fn drop(&mut self) {
@ -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 {