Provide settings to customize photo path and display duration
This commit is contained in:
parent
cc0038c1cd
commit
f1fbba405b
@ -43,6 +43,7 @@ lto = "thin"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.93"
|
anyhow = "1.0.93"
|
||||||
|
config = "0.14.1"
|
||||||
image = "0.25.4"
|
image = "0.25.4"
|
||||||
macroquad = { version = "0.4.13" }
|
macroquad = { version = "0.4.13" }
|
||||||
walkdir = "2.5.0"
|
walkdir = "2.5.0"
|
||||||
|
|||||||
2
settings.yml
Normal file
2
settings.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
photo_path: "/mnt/c/Users/beaus/Downloads"
|
||||||
|
duration: 30
|
||||||
@ -1,18 +1,18 @@
|
|||||||
use crate::dimensions::{calculate_resize_dimensions, Dimensions};
|
use crate::dimensions::{calculate_resize_dimensions, Dimensions};
|
||||||
use image::ImageReader;
|
use image::ImageReader;
|
||||||
use macroquad::texture::Texture2D;
|
use macroquad::texture::Texture2D;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
pub struct ImageProvider {
|
pub struct ImageProvider<'a> {
|
||||||
path: PathBuf,
|
path: &'a Path,
|
||||||
directory_it: Box<dyn Iterator<Item = Result<walkdir::DirEntry, walkdir::Error>>>,
|
directory_it: Box<dyn Iterator<Item = Result<walkdir::DirEntry, walkdir::Error>>>,
|
||||||
texture: Option<Texture2D>,
|
texture: Option<Texture2D>,
|
||||||
screen_dimension: Dimensions,
|
screen_dimension: Dimensions,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ImageProvider {
|
impl<'a> ImageProvider<'a> {
|
||||||
pub fn new(screen_dimension: Dimensions, path: PathBuf) -> Self {
|
pub fn new(screen_dimension: Dimensions, path: &'a Path) -> Self {
|
||||||
Self {
|
Self {
|
||||||
directory_it: Box::new(WalkDir::new(&path).max_open(8).into_iter()),
|
directory_it: Box::new(WalkDir::new(&path).max_open(8).into_iter()),
|
||||||
texture: None,
|
texture: None,
|
||||||
|
|||||||
@ -8,6 +8,7 @@ use std::{
|
|||||||
|
|
||||||
mod dimensions;
|
mod dimensions;
|
||||||
mod image_provider;
|
mod image_provider;
|
||||||
|
mod settings;
|
||||||
|
|
||||||
fn window_conf() -> Conf {
|
fn window_conf() -> Conf {
|
||||||
Conf {
|
Conf {
|
||||||
@ -32,9 +33,10 @@ fn display_image_centered(texture: &Texture2D) {
|
|||||||
|
|
||||||
#[macroquad::main(window_conf)]
|
#[macroquad::main(window_conf)]
|
||||||
async fn main() -> anyhow::Result<()> {
|
async fn main() -> anyhow::Result<()> {
|
||||||
|
let settings = settings::Settings::new("settings.yml".into())?;
|
||||||
show_mouse(false);
|
show_mouse(false);
|
||||||
let screen_dim = Dimensions::new(screen_width() as u32, screen_height() as u32);
|
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()?;
|
provider.load_next_image()?;
|
||||||
let mut time = Instant::now();
|
let mut time = Instant::now();
|
||||||
|
|
||||||
@ -45,7 +47,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
display_frame(&provider)?;
|
display_frame(&provider)?;
|
||||||
|
|
||||||
if time.elapsed().as_secs() > 5 {
|
if time.elapsed() > settings.duration {
|
||||||
provider.load_next_image()?;
|
provider.load_next_image()?;
|
||||||
time = Instant::now();
|
time = Instant::now();
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/settings.rs
Normal file
22
src/settings.rs
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
use config::{Config, File};
|
||||||
|
use std::{path::PathBuf, time::Duration};
|
||||||
|
pub struct Settings {
|
||||||
|
pub photo_path: PathBuf,
|
||||||
|
pub duration: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Settings {
|
||||||
|
pub fn new(settings_file: PathBuf) -> anyhow::Result<Self> {
|
||||||
|
let settings = Config::builder()
|
||||||
|
.add_source(File::from(settings_file))
|
||||||
|
.build()?;
|
||||||
|
|
||||||
|
let photo_path = settings.get_string("photo_path")?.try_into()?;
|
||||||
|
let duration = settings.get_int("duration")?;
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
|
photo_path,
|
||||||
|
duration: Duration::from_secs(duration as u64),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user