WIP: menu

This commit is contained in:
2026-01-25 21:37:53 +01:00
parent 250e359fc5
commit 6efcabd32d
14 changed files with 635 additions and 335 deletions

View File

@@ -4,35 +4,87 @@ pub enum Page {
Main,
Patterns,
Audio,
Doc,
Help,
Dict,
}
impl Page {
/// All pages for iteration
pub const ALL: &'static [Page] = &[
Page::Main,
Page::Patterns,
Page::Audio,
Page::Help,
Page::Dict,
];
/// Grid dimensions (cols, rows)
pub const GRID_SIZE: (i8, i8) = (3, 2);
/// Grid position (col, row) for each page
/// Layout:
/// col 0 col 1 col 2
/// row 0 Patterns Help
/// row 1 Dict Sequencer Audio
pub const fn grid_pos(self) -> (i8, i8) {
match self {
Page::Dict => (0, 1),
Page::Main => (1, 1),
Page::Patterns => (1, 0),
Page::Audio => (2, 1),
Page::Help => (2, 0),
}
}
/// Find page at grid position, if any
pub fn at_pos(col: i8, row: i8) -> Option<Page> {
Self::ALL.iter().copied().find(|p| p.grid_pos() == (col, row))
}
/// Display name for the page
pub const fn name(self) -> &'static str {
match self {
Page::Main => "Sequencer",
Page::Patterns => "Patterns",
Page::Audio => "Audio",
Page::Help => "Help",
Page::Dict => "Dict",
}
}
pub fn left(&mut self) {
*self = match self {
Page::Main | Page::Patterns => Page::Doc,
Page::Audio => Page::Main,
Page::Doc => Page::Audio,
let (col, row) = self.grid_pos();
for offset in 1..=Self::GRID_SIZE.0 {
let new_col = (col - offset).rem_euclid(Self::GRID_SIZE.0);
if let Some(page) = Self::at_pos(new_col, row) {
*self = page;
return;
}
}
}
pub fn right(&mut self) {
*self = match self {
Page::Main | Page::Patterns => Page::Audio,
Page::Audio => Page::Doc,
Page::Doc => Page::Main,
let (col, row) = self.grid_pos();
for offset in 1..=Self::GRID_SIZE.0 {
let new_col = (col + offset).rem_euclid(Self::GRID_SIZE.0);
if let Some(page) = Self::at_pos(new_col, row) {
*self = page;
return;
}
}
}
pub fn up(&mut self) {
if *self == Page::Main {
*self = Page::Patterns;
let (col, row) = self.grid_pos();
if let Some(page) = Self::at_pos(col, row - 1) {
*self = page;
}
}
pub fn down(&mut self) {
if *self == Page::Patterns {
*self = Page::Main;
let (col, row) = self.grid_pos();
if let Some(page) = Self::at_pos(col, row + 1) {
*self = page;
}
}
}