mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-28 16:25:33 +00:00
fixes
This commit is contained in:
@@ -1,13 +1,23 @@
|
||||
use core::sync::atomic::Ordering;
|
||||
|
||||
use crate::{
|
||||
BINARY_CH, display::FRAMEBUFFER, elf::load_binary, peripherals::keyboard, storage::FileName,
|
||||
usb::USB_ACTIVE,
|
||||
};
|
||||
use alloc::vec::Vec;
|
||||
use alloc::{str::FromStr, string::String, vec::Vec};
|
||||
use embassy_sync::{blocking_mutex::raw::CriticalSectionRawMutex, mutex::Mutex};
|
||||
use embedded_graphics::mono_font::ascii;
|
||||
use kolibri_embedded_gui::{label::Label, style::medsize_rgb565_style, ui::Ui};
|
||||
use embedded_graphics::{
|
||||
Drawable,
|
||||
mono_font::{MonoTextStyle, ascii::FONT_9X15},
|
||||
pixelcolor::Rgb565,
|
||||
prelude::{Dimensions, Point, RgbColor, Size},
|
||||
primitives::Rectangle,
|
||||
text::Text,
|
||||
};
|
||||
use embedded_layout::{
|
||||
align::{horizontal, vertical},
|
||||
layout::linear::LinearLayout,
|
||||
object_chain::Chain,
|
||||
prelude::*,
|
||||
};
|
||||
use embedded_text::TextBox;
|
||||
use shared::keyboard::{KeyCode, KeyState};
|
||||
|
||||
pub static SELECTIONS: Mutex<CriticalSectionRawMutex, SelectionList> =
|
||||
@@ -47,20 +57,54 @@ pub async fn ui_handler() {
|
||||
}
|
||||
|
||||
async fn draw_selection() {
|
||||
const NO_BINS: &str = "No Programs found on SD Card. Ensure programs end with '.bin', and are located in the root directory";
|
||||
let file_names: Vec<FileName> = {
|
||||
let guard = SELECTIONS.lock().await;
|
||||
guard.selections.clone()
|
||||
};
|
||||
|
||||
let mut ui = Ui::new_fullscreen(unsafe { &mut FRAMEBUFFER }, medsize_rgb565_style());
|
||||
let text_style = MonoTextStyle::new(&FONT_9X15, Rgb565::WHITE);
|
||||
let display_area = unsafe { FRAMEBUFFER.bounding_box() };
|
||||
|
||||
const NO_BINS: &str = "No Programs found on SD Card. Ensure programs end with '.bin', and are located in the root directory";
|
||||
let no_bins = String::from_str(NO_BINS).unwrap();
|
||||
|
||||
if file_names.is_empty() {
|
||||
ui.add(Label::new(NO_BINS).with_font(ascii::FONT_10X20));
|
||||
TextBox::new(
|
||||
&no_bins,
|
||||
Rectangle::new(
|
||||
Point::new(25, 25),
|
||||
Size::new(display_area.size.width - 50, display_area.size.width - 50),
|
||||
),
|
||||
text_style,
|
||||
)
|
||||
.draw(unsafe { &mut FRAMEBUFFER })
|
||||
.unwrap();
|
||||
} else {
|
||||
for file in file_names {
|
||||
ui.add(Label::new(&file.long_name).with_font(ascii::FONT_10X20));
|
||||
}
|
||||
let mut file_names = file_names.iter();
|
||||
let Some(first) = file_names.next() else {
|
||||
Text::new(NO_BINS, Point::zero(), text_style)
|
||||
.draw(unsafe { &mut FRAMEBUFFER })
|
||||
.unwrap();
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
let chain = Chain::new(Text::new(&first.long_name, Point::zero(), text_style));
|
||||
|
||||
// for _ in 0..file_names.len() {
|
||||
// let chain = chain.append(Text::new(
|
||||
// file_names.next().unwrap(),
|
||||
// Point::zero(),
|
||||
// text_style,
|
||||
// ));
|
||||
// }
|
||||
|
||||
LinearLayout::vertical(chain)
|
||||
.with_alignment(horizontal::Center)
|
||||
.arrange()
|
||||
.align_to(&display_area, horizontal::Center, vertical::Center)
|
||||
.draw(unsafe { &mut FRAMEBUFFER })
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let mut sel = SELECTIONS.lock().await;
|
||||
|
||||
Reference in New Issue
Block a user