mirror of
https://github.com/LegitCamper/picocalc-os-rs.git
synced 2025-12-27 15:55:25 +00:00
init
This commit is contained in:
@@ -5,12 +5,12 @@
|
||||
extern crate alloc;
|
||||
use abi::{
|
||||
display::{Display, SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
fs::{list_dir, read_file},
|
||||
fs::{Entries, list_dir, read_file},
|
||||
get_key,
|
||||
keyboard::{KeyCode, KeyState},
|
||||
print,
|
||||
};
|
||||
use alloc::{format, string::ToString, vec};
|
||||
use alloc::{format, vec};
|
||||
use core::panic::PanicInfo;
|
||||
use embedded_graphics::{
|
||||
Drawable, image::Image, mono_font::MonoTextStyle, mono_font::ascii::FONT_6X10,
|
||||
@@ -34,7 +34,6 @@ pub fn main() {
|
||||
let mut bmp_buf = vec![0_u8; 100_000];
|
||||
let mut display = Display;
|
||||
|
||||
// Grid parameters
|
||||
let grid_cols = 3;
|
||||
let grid_rows = 3;
|
||||
let cell_width = SCREEN_WIDTH as i32 / grid_cols;
|
||||
@@ -42,50 +41,44 @@ pub fn main() {
|
||||
|
||||
let mut images_drawn = 0;
|
||||
|
||||
let mut files = [const { None }; 18];
|
||||
let files_num = list_dir("/images", &mut files);
|
||||
let mut entries = Entries::new();
|
||||
let files_num = list_dir("/images", &mut entries);
|
||||
|
||||
for file in &files[2..files_num] {
|
||||
for file in &entries.entries()[2..files_num] {
|
||||
if images_drawn >= grid_cols * grid_rows {
|
||||
break; // only draw 3x3
|
||||
}
|
||||
|
||||
if let Some(f) = file {
|
||||
print!("file: {}", f.name);
|
||||
if f.name.extension() == b"bmp" || f.name.extension() == b"BMP" {
|
||||
let file = format!("/images/{}", f.name);
|
||||
print!("file: {}", file);
|
||||
if file.extension().unwrap_or("") == "bmp" || file.extension().unwrap_or("") == "BMP" {
|
||||
let file_path = format!("/images/{}", file);
|
||||
|
||||
let read = read_file(&file, 0, &mut &mut bmp_buf[..]);
|
||||
if read > 0 {
|
||||
let bmp = Bmp::from_slice(&bmp_buf).expect("failed to parse bmp");
|
||||
let read = read_file(&file_path, 0, &mut &mut bmp_buf[..]);
|
||||
if read > 0 {
|
||||
let bmp = Bmp::from_slice(&bmp_buf).expect("failed to parse bmp");
|
||||
|
||||
let row = images_drawn / grid_cols;
|
||||
let col = images_drawn % grid_cols;
|
||||
let cell_x = col * cell_width;
|
||||
let cell_y = row * cell_height;
|
||||
let row = images_drawn / grid_cols;
|
||||
let col = images_drawn % grid_cols;
|
||||
let cell_x = col * cell_width;
|
||||
let cell_y = row * cell_height;
|
||||
|
||||
// Center image inside cell
|
||||
let bmp_w = bmp.size().width as i32;
|
||||
let bmp_h = bmp.size().height as i32;
|
||||
let x = cell_x + (cell_width - bmp_w) / 2;
|
||||
let y = cell_y + 5; // 5px top margin
|
||||
// Center image inside cell
|
||||
let bmp_w = bmp.size().width as i32;
|
||||
let bmp_h = bmp.size().height as i32;
|
||||
let x = cell_x + (cell_width - bmp_w) / 2;
|
||||
let y = cell_y + 5; // 5px top margin
|
||||
|
||||
Image::new(&bmp, Point::new(x, y))
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
let text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
||||
let text_y = y + bmp_h + 2; // 2px gap under image
|
||||
Text::new(
|
||||
f.name.to_string().as_str(),
|
||||
Point::new(cell_x + 2, text_y),
|
||||
text_style,
|
||||
)
|
||||
Image::new(&bmp, Point::new(x, y))
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
images_drawn += 1;
|
||||
}
|
||||
let text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
|
||||
let text_y = y + bmp_h + 2; // 2px gap under image
|
||||
Text::new(&file.base(), Point::new(cell_x + 2, text_y), text_style)
|
||||
.draw(&mut display)
|
||||
.unwrap();
|
||||
|
||||
images_drawn += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user