This commit is contained in:
2025-11-04 16:50:57 -07:00
parent 375b5d1d47
commit 513042b561
2 changed files with 18 additions and 17 deletions

View File

@@ -4,9 +4,9 @@ extern crate alloc;
use abi::{
display::Display,
fs::{Entries, FileName},
get_key,
keyboard::{KeyCode, KeyState},
print, sleep,
};
use alloc::vec::Vec;
use embedded_graphics::{
@@ -26,13 +26,13 @@ use embedded_text::TextBox;
pub struct SelectionUi<'a> {
selection: usize,
items: &'a Entries,
items: &'a [&'a str],
error: &'a str,
last_bounds: Option<Rectangle>,
}
impl<'a> SelectionUi<'a> {
pub fn new(items: &'a Entries, error: &'a str) -> Self {
pub fn new(items: &'a [&'a str], error: &'a str) -> Self {
Self {
selection: 0,
items,
@@ -47,6 +47,7 @@ impl<'a> SelectionUi<'a> {
loop {
let key = get_key();
if key.state == KeyState::Pressed {
print!("Got Key press: {:?}", key.key);
if let Some(s) = self.update(display, key.key)? {
selection = Some(s);
break;
@@ -61,13 +62,13 @@ impl<'a> SelectionUi<'a> {
pub fn update(&mut self, display: &mut Display, key: KeyCode) -> Result<Option<usize>, ()> {
match key {
KeyCode::JoyUp => {
let _ = self.selection.saturating_sub(1);
self.selection = self.selection.saturating_sub(1);
}
KeyCode::JoyDown => {
let _ = self.selection.saturating_add(1);
self.selection = self.selection.saturating_add(1);
}
KeyCode::Enter | KeyCode::JoyRight => return Ok(Some(self.selection)),
_ => (),
_ => return Ok(Some(self.selection)),
};
self.draw(display)?;
Ok(None)
@@ -77,9 +78,7 @@ impl<'a> SelectionUi<'a> {
let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);
let display_area = display.bounding_box();
let entries = self.items.entries();
if entries.is_empty() {
if self.items.is_empty() {
TextBox::new(
&self.error,
Rectangle::new(
@@ -94,8 +93,8 @@ impl<'a> SelectionUi<'a> {
let mut views: Vec<Text<MonoTextStyle<Rgb565>>> = Vec::new();
for i in &entries {
views.push(Text::new(i.full_name(), Point::zero(), text_style));
for i in self.items {
views.push(Text::new(i, Point::zero(), text_style));
}
let views_group = Views::new(views.as_mut_slice());