previews: run previews as notedeck apps

This allows ./preview to be a notedeck app runner. I am currently
using it for the ProfilePic app (which will because notedeck_viz)

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2024-12-20 15:39:26 -08:00
parent 475314da75
commit fcac49a0a5
19 changed files with 222 additions and 238 deletions

View File

@@ -1,5 +1,5 @@
use crate::AppContext;
pub trait App {
fn update(&mut self, ctx: &mut AppContext<'_>);
fn update(&mut self, ctx: &mut AppContext<'_>, ui: &mut egui::Ui);
}

View File

@@ -15,5 +15,4 @@ pub struct AppContext<'a> {
pub path: &'a DataPath,
pub args: &'a Args,
pub theme: &'a mut ThemeHandler,
pub egui: &'a egui::Context,
}

View File

@@ -22,18 +22,12 @@ impl DataPath {
pub fn default_base() -> Option<PathBuf> {
dirs::data_local_dir().map(|pb| pb.join("notedeck"))
}
}
pub enum DataPathType {
Log,
Setting,
Keys,
SelectedKey,
Db,
Cache,
}
pub fn default_base_or_cwd() -> PathBuf {
use std::str::FromStr;
Self::default_base().unwrap_or_else(|| PathBuf::from_str(".").unwrap())
}
impl DataPath {
pub fn rel_path(&self, typ: DataPathType) -> PathBuf {
match typ {
DataPathType::Log => PathBuf::from("logs"),
@@ -50,6 +44,21 @@ impl DataPath {
}
}
impl Default for DataPath {
fn default() -> Self {
Self::new(Self::default_base_or_cwd())
}
}
pub enum DataPathType {
Log,
Setting,
Keys,
SelectedKey,
Db,
Cache,
}
#[derive(Debug, PartialEq)]
pub struct Directory {
pub file_path: PathBuf,