Provide settings to customize photo path

This commit is contained in:
Jean-Loup Beaussart 2024-12-10 23:40:06 +01:00
parent cc0038c1cd
commit 3c0124bcd0
No known key found for this signature in database
GPG Key ID: 582B3C35EAFE46F8
4 changed files with 10 additions and 6 deletions

View File

@ -43,6 +43,7 @@ lto = "thin"
[dependencies]
anyhow = "1.0.93"
config = "0.14.1"
image = "0.25.4"
macroquad = { version = "0.4.13" }
walkdir = "2.5.0"

1
settings.yml Normal file
View File

@ -0,0 +1 @@
photo_path: "/mnt/c/Users/beaus/Downloads"

View File

@ -1,18 +1,18 @@
use crate::dimensions::{calculate_resize_dimensions, Dimensions};
use image::ImageReader;
use macroquad::texture::Texture2D;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use walkdir::WalkDir;
pub struct ImageProvider {
path: PathBuf,
pub struct ImageProvider<'a> {
path: &'a Path,
directory_it: Box<dyn Iterator<Item = Result<walkdir::DirEntry, walkdir::Error>>>,
texture: Option<Texture2D>,
screen_dimension: Dimensions,
}
impl ImageProvider {
pub fn new(screen_dimension: Dimensions, path: PathBuf) -> Self {
impl<'a> ImageProvider<'a> {
pub fn new(screen_dimension: Dimensions, path: &'a Path) -> Self {
Self {
directory_it: Box::new(WalkDir::new(&path).max_open(8).into_iter()),
texture: None,

View File

@ -8,6 +8,7 @@ use std::{
mod dimensions;
mod image_provider;
mod settings;
fn window_conf() -> Conf {
Conf {
@ -32,9 +33,10 @@ fn display_image_centered(texture: &Texture2D) {
#[macroquad::main(window_conf)]
async fn main() -> anyhow::Result<()> {
let settings = settings::Settings::new("settings.yml".into())?;
show_mouse(false);
let screen_dim = Dimensions::new(screen_width() as u32, screen_height() as u32);
let mut provider = ImageProvider::new(screen_dim, "/mnt/c/Users/beaus/Downloads".into());
let mut provider = ImageProvider::new(screen_dim, &settings.photo_path);
provider.load_next_image()?;
let mut time = Instant::now();