film-manager/src/main.rs

84 lines
2.5 KiB
Rust
Raw Normal View History

2023-05-30 12:50:16 -05:00
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
mod new_roll;
mod roll_view;
mod roll;
use eframe::egui;
use new_roll::NewRollWindow;
use roll::Roll;
use roll_view::RollViewWindow;
2023-05-30 12:50:16 -05:00
fn main() -> Result<(), eframe::Error> {
env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
let options = eframe::NativeOptions {
initial_window_size: Some(egui::vec2(320.0, 240.0)),
..Default::default()
};
eframe::run_native(
"Film Manager",
options,
Box::new(|cc| Box::new(MyApp::new(cc))),
)
}
pub struct AppState {
pub rolls: Vec<Roll>,
2023-05-30 12:50:16 -05:00
}
struct MyApp {
state: AppState,
roll_views: Vec<RollViewWindow>,
new_roll_window: Option<NewRollWindow>,
2023-05-30 12:50:16 -05:00
}
impl MyApp {
fn new(cc: &eframe::CreationContext<'_>) -> Self {
let rolls = eframe::get_value(cc.storage.unwrap(), "rolls").unwrap_or_else(|| {
vec![Roll::new(
"00001".into(),
"Test".into(),
"Testing".into(),
Local::now().date_naive(),
24,
)]
});
Self {
state: AppState { rolls },
roll_views: Vec::new(),
new_roll_window: None,
2023-05-30 12:50:16 -05:00
}
}
}
impl eframe::App for MyApp {
fn save(&mut self, storage: &mut dyn eframe::Storage) {
eframe::set_value(storage, "rolls", &self.state.rolls);
}
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::CentralPanel::default().show(ctx, |ui| {
ui.heading("Film Manager");
ui.label("Rolls:");
for (i, roll) in self.state.rolls.iter().enumerate() {
if ui.button(roll.short_str()).clicked()
&& self.roll_views.iter().find(|v| v.roll() == i).is_none()
{
self.roll_views.push(RollViewWindow::new(i));
2023-05-30 12:50:16 -05:00
}
}
if ui.button("Add").clicked() && self.new_roll_window.is_none() {
self.new_roll_window = Some(NewRollWindow::default());
2023-05-30 12:50:16 -05:00
}
2023-05-30 15:03:05 -05:00
self.roll_views.retain_mut(|win| {
!win.draw(ctx, &mut self.state)
});
if let Some(new_roll_window) = self.new_roll_window.as_mut() {
if new_roll_window.draw(ctx, &mut self.state) {
self.new_roll_window = None;
2023-05-30 12:50:16 -05:00
}
}
});
}
}