53 lines
1.4 KiB
Rust
53 lines
1.4 KiB
Rust
// src/state/pages/intro.rs
|
|
use crate::movement::MovementAction;
|
|
|
|
#[derive(Default, Clone, Debug)]
|
|
pub struct IntroState {
|
|
pub focus_outside_canvas: bool,
|
|
pub focused_button_index: usize,
|
|
}
|
|
|
|
impl IntroState {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
focus_outside_canvas: true,
|
|
focused_button_index: 0,
|
|
}
|
|
}
|
|
|
|
pub fn next_option(&mut self) {
|
|
if self.focused_button_index < 3 {
|
|
self.focused_button_index += 1;
|
|
}
|
|
}
|
|
|
|
pub fn previous_option(&mut self) {
|
|
if self.focused_button_index > 0 {
|
|
self.focused_button_index -= 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
impl IntroState {
|
|
pub fn handle_movement(&mut self, action: MovementAction) -> bool {
|
|
match action {
|
|
MovementAction::Next | MovementAction::Right | MovementAction::Down => {
|
|
self.next_option();
|
|
true
|
|
}
|
|
MovementAction::Previous | MovementAction::Left | MovementAction::Up => {
|
|
self.previous_option();
|
|
true
|
|
}
|
|
MovementAction::Select => {
|
|
// Actual selection handled in event loop (UiContext::Intro)
|
|
false
|
|
}
|
|
MovementAction::Esc => {
|
|
// Nothing special for Intro, but could be used to quit
|
|
true
|
|
}
|
|
}
|
|
}
|
|
}
|