Extract Roll & Exposure to a separate file
This commit is contained in:
parent
77503b4ffb
commit
41d8dac6ec
60
src/main.rs
60
src/main.rs
@ -2,12 +2,12 @@
|
||||
|
||||
mod new_roll;
|
||||
mod roll_view;
|
||||
mod roll;
|
||||
|
||||
use eframe::egui;
|
||||
use egui_datepicker::{Local, NaiveDate};
|
||||
use new_roll::NewRollWindow;
|
||||
use roll::Roll;
|
||||
use roll_view::RollViewWindow;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
fn main() -> Result<(), eframe::Error> {
|
||||
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||
@ -22,62 +22,6 @@ fn main() -> Result<(), eframe::Error> {
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Exposure {
|
||||
num: u8,
|
||||
#[serde(default)]
|
||||
printed: bool,
|
||||
#[serde(default)]
|
||||
damaged: bool,
|
||||
#[serde(default)]
|
||||
paper: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct Roll {
|
||||
id: String,
|
||||
name: String,
|
||||
#[serde(default)]
|
||||
desc: String,
|
||||
date: NaiveDate,
|
||||
exposures: Vec<Exposure>,
|
||||
}
|
||||
|
||||
impl Roll {
|
||||
fn new(id: String, name: String, desc: String, date: NaiveDate, num_exposures: u8) -> Self {
|
||||
let mut exposures = Vec::new();
|
||||
for num in 1..=num_exposures {
|
||||
exposures.push(Exposure {
|
||||
num,
|
||||
printed: false,
|
||||
damaged: false,
|
||||
paper: None,
|
||||
})
|
||||
}
|
||||
Self {
|
||||
id,
|
||||
name,
|
||||
desc,
|
||||
date,
|
||||
exposures,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn short_str(&self) -> String {
|
||||
format!(
|
||||
"{}{} on {}, {} exp",
|
||||
self.id,
|
||||
if self.name.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(" - {}", self.name)
|
||||
},
|
||||
self.date.format("%m/%d/%Y"),
|
||||
self.exposures.len()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
pub rolls: Vec<Roll>,
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use eframe::{
|
||||
};
|
||||
use egui_datepicker::DatePicker;
|
||||
|
||||
use crate::{AppState, Roll};
|
||||
use crate::{AppState, roll::Roll};
|
||||
|
||||
pub struct NewRollWindow {
|
||||
id: String,
|
||||
|
Loading…
x
Reference in New Issue
Block a user