Files
hcie-rust-v3.05/hcie-egui-app/crates/hcie-gui-egui/src/main.rs
T

107 lines
3.3 KiB
Rust

mod app;
mod brush_import;
mod canvas;
mod event_bus;
mod i18n;
mod manifest;
mod plugin;
mod plugins;
use eframe::egui;
fn main() -> eframe::Result<()> {
let _ = env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
.try_init();
let args: Vec<String> = std::env::args().collect();
let mut load_path: Option<std::path::PathBuf> = None;
let mut screenshot_panel: Option<String> = None;
let mut screenshot_out: Option<std::path::PathBuf> = None;
let mut toolbox_two_column = false;
{
let mut i = 1;
while i < args.len() {
match args[i].as_str() {
"--screenshot-panel" => {
if i + 2 >= args.len() {
eprintln!("Usage: --screenshot-panel <panel-name> <output.png>");
std::process::exit(1);
}
screenshot_panel = Some(args[i + 1].clone());
screenshot_out = Some(std::path::PathBuf::from(&args[i + 2]));
i += 3;
}
"--toolbox-two-column" => {
toolbox_two_column = true;
i += 1;
}
other => {
load_path = Some(std::path::PathBuf::from(other));
i += 1;
}
}
}
}
let screenshot_request = screenshot_panel
.and_then(|name| app::pane_from_name(&name))
.map(|pane| (pane, screenshot_out.unwrap()));
if screenshot_request.is_some() {
log::info!("Panel screenshot mode: {:?}", screenshot_request);
}
let icon = load_icon();
let tablet_state = std::sync::Arc::new(std::sync::Mutex::new(
app::shell::tablet_input::TabletState::new(),
));
app::shell::tablet_input::start_evdev_listener(tablet_state.clone());
let options = eframe::NativeOptions {
viewport: egui::ViewportBuilder::default()
.with_app_id("hcie-rust-v3")
.with_title("HCIE — Rust Edition v3")
.with_icon(icon)
.with_inner_size([1280.0, 800.0])
.with_min_inner_size([640.0, 480.0])
.with_resizable(true)
.with_decorations(false)
.with_maximized(false),
event_loop_builder: Some(Box::new(|_builder| {
// Reserved for future platform-specific event-loop configuration.
})),
..Default::default()
};
eframe::run_native(
"hcie-rust-v3",
options,
Box::new(move |cc| {
let mut app = app::HcieApp::new(cc, tablet_state, screenshot_request);
app.pending_load = load_path;
app.state.toolbox_two_column = toolbox_two_column;
Ok(Box::new(app))
}),
)
}
fn load_icon() -> std::sync::Arc<egui::IconData> {
let icon_bytes = include_bytes!("../../../assets/icons/hcie-icon.png");
match image::load_from_memory(icon_bytes) {
Ok(img) => {
let rgba = img.into_rgba8();
let (w, h) = rgba.dimensions();
std::sync::Arc::new(egui::IconData {
rgba: rgba.into_raw(),
width: w,
height: h,
})
}
Err(e) => {
log::warn!("Failed to load icon: {}", e);
std::sync::Arc::new(egui::IconData::default())
}
}
}