| 1 | //! Desktop status shell for the Paperdoll Renderer foundation. |
| 2 | //! |
| 3 | //! The window lists what this build does not do. It is not a 3D viewport and |
| 4 | //! it is not a paperdoll preview. |
| 5 | |
| 6 | use std::process::ExitCode; |
| 7 | |
| 8 | use eframe::egui; |
| 9 | use paperdoll_renderer::foundation::{ |
| 10 | availability, capabilities, dutch_label, dutch_state, dutch_summary, help_text, parse_cli, |
| 11 | report, CliError, CliRequest, |
| 12 | }; |
| 13 | |
| 14 | fn main() -> ExitCode { |
| 15 | let args: Vec<String> = std::env::args().skip(1).collect(); |
| 16 | let borrowed: Vec<&str> = args.iter().map(String::as_str).collect(); |
| 17 | match parse_cli(borrowed) { |
| 18 | Ok(CliRequest::PrintHelp) => { |
| 19 | println!("{}", help_text()); |
| 20 | ExitCode::SUCCESS |
| 21 | } |
| 22 | Ok(CliRequest::PrintStatus) => { |
| 23 | println!("{}", report()); |
| 24 | ExitCode::SUCCESS |
| 25 | } |
| 26 | Ok(CliRequest::OpenWindow) => { |
| 27 | if let Some(message) = window_preflight() { |
| 28 | eprintln!("paperdoll-renderer: {message}"); |
| 29 | return ExitCode::from(1); |
| 30 | } |
| 31 | match run_window() { |
| 32 | Ok(()) => ExitCode::SUCCESS, |
| 33 | Err(err) => { |
| 34 | eprintln!("paperdoll-renderer: het statusvenster openen is mislukt: {err}"); |
| 35 | ExitCode::from(1) |
| 36 | } |
| 37 | } |
| 38 | } |
| 39 | Err(CliError::UnknownArgument(arg)) => { |
| 40 | eprintln!("paperdoll-renderer: onbekend argument '{arg}'."); |
| 41 | eprintln!("Import en render zijn niet gebouwd. Gebruik --help."); |
| 42 | ExitCode::from(2) |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | fn window_preflight() -> Option<String> { |
| 48 | #[cfg(target_os = "linux")] |
| 49 | { |
| 50 | let missing = paperdoll_renderer::foundation::missing_window_libraries(); |
| 51 | if missing.is_empty() { |
| 52 | None |
| 53 | } else { |
| 54 | Some(paperdoll_renderer::foundation::missing_library_message( |
| 55 | &missing, |
| 56 | )) |
| 57 | } |
| 58 | } |
| 59 | #[cfg(not(target_os = "linux"))] |
| 60 | { |
| 61 | None |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | fn run_window() -> eframe::Result<()> { |
| 66 | let options = eframe::NativeOptions { |
| 67 | viewport: egui::ViewportBuilder::default() |
| 68 | .with_title("Paperdoll Renderer") |
| 69 | .with_inner_size([480.0, 560.0]) |
| 70 | .with_min_inner_size([320.0, 280.0]), |
| 71 | ..Default::default() |
| 72 | }; |
| 73 | eframe::run_native( |
| 74 | "Paperdoll Renderer", |
| 75 | options, |
| 76 | Box::new(|_creation| Ok(Box::new(StatusApp))), |
| 77 | ) |
| 78 | } |
| 79 | |
| 80 | struct StatusApp; |
| 81 | |
| 82 | impl eframe::App for StatusApp { |
| 83 | fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { |
| 84 | egui::CentralPanel::default().show(ctx, |ui| { |
| 85 | egui::ScrollArea::vertical().show(ui, |ui| { |
| 86 | ui.heading("Paperdoll Renderer"); |
| 87 | ui.label("Projectbasis. Nog geen paperdoll-renderer."); |
| 88 | ui.add_space(8.0); |
| 89 | ui.label(dutch_summary()); |
| 90 | ui.add_space(12.0); |
| 91 | ui.strong("Status van deze build"); |
| 92 | for capability in capabilities() { |
| 93 | ui.label(format!( |
| 94 | "{}: {}", |
| 95 | dutch_label(*capability), |
| 96 | dutch_state(availability(*capability)) |
| 97 | )); |
| 98 | } |
| 99 | ui.add_space(12.0); |
| 100 | if ui.button("Sluiten").clicked() { |
| 101 | ctx.send_viewport_cmd(egui::ViewportCommand::Close); |
| 102 | } |
| 103 | }); |
| 104 | }); |
| 105 | } |
| 106 | } |