From aeb74c2dcf0a00b771c6dcfaf5f425f28553ad3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=8D=9A=E6=96=87?= Date: Sun, 21 Jul 2024 01:26:40 +0800 Subject: [PATCH] refactor: merge viewers --- viewer-egui/Cargo.toml | 15 ----------- viewer/src/bin.rs | 26 +++++++++++++++++++ viewer-egui/src/main.rs => viewer/src/egui.rs | 2 +- viewer/src/{main.rs => gtk4.rs} | 8 +++--- 4 files changed, 30 insertions(+), 21 deletions(-) delete mode 100644 viewer-egui/Cargo.toml create mode 100644 viewer/src/bin.rs rename viewer-egui/src/main.rs => viewer/src/egui.rs (97%) rename viewer/src/{main.rs => gtk4.rs} (98%) diff --git a/viewer-egui/Cargo.toml b/viewer-egui/Cargo.toml deleted file mode 100644 index 14360bf..0000000 --- a/viewer-egui/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "viewer-egui" -version = "0.1.0" -edition = "2021" - -[dependencies] -stc-rs = { path = "../lib", features = ["lalrpop_parser"] } -pretty_env_logger = "*" -log = "*" -once_cell = "*" -async-channel = "*" -quick-xml = { version = "*", features = ["serialize"] } -serde = { version = "*", features = ["derive"] } -eframe = { version = "*", features = ["default"] } -egui_extras = { version = "*", features = ["default", "image"] } \ No newline at end of file diff --git a/viewer/src/bin.rs b/viewer/src/bin.rs new file mode 100644 index 0000000..7a649cd --- /dev/null +++ b/viewer/src/bin.rs @@ -0,0 +1,26 @@ +mod storage; + +#[cfg(feature = "gui-egui")] +mod egui; + +#[cfg(feature = "gui-gtk4")] +mod column_object; +#[cfg(feature = "gui-gtk4")] +mod gtk4; +#[cfg(feature = "gui-gtk4")] +mod stc_viewer; + +#[cfg(all(feature = "gui-egui", feature = "gui-gtk4"))] +compile_error!( + "Feature gui-egui and gui-gtk4 are mutually exclusive and cannot be enabled together" +); + +#[cfg(feature = "gui-gtk4")] +fn main() { + gtk4::main() +} + +#[cfg(feature = "gui-egui")] +fn main() -> Result<(), eframe::Error> { + egui::main() +} diff --git a/viewer-egui/src/main.rs b/viewer/src/egui.rs similarity index 97% rename from viewer-egui/src/main.rs rename to viewer/src/egui.rs index 7cf6ab1..1d7b0e9 100644 --- a/viewer-egui/src/main.rs +++ b/viewer/src/egui.rs @@ -44,7 +44,7 @@ impl eframe::App for StcViewer { } } -fn main() -> Result<(), eframe::Error> { +pub fn main() -> Result<(), eframe::Error> { pretty_env_logger::init(); let options = eframe::NativeOptions { diff --git a/viewer/src/main.rs b/viewer/src/gtk4.rs similarity index 98% rename from viewer/src/main.rs rename to viewer/src/gtk4.rs index 7eb9e45..6847c96 100644 --- a/viewer/src/main.rs +++ b/viewer/src/gtk4.rs @@ -1,8 +1,6 @@ -mod column_object; -mod stc_viewer; -mod storage; - use crate::stc_viewer::{StcViewerApp, UIMessages, STC_VIEWER_COLUMN_NAME}; +use crate::storage; + use glib::MainContext; use gtk4::gdk::ffi::GDK_BUTTON_SECONDARY; use gtk4::gdk::Rectangle; @@ -16,7 +14,7 @@ use stc::prelude::*; use std::rc::Rc; use std::sync::Mutex; -fn main() { +pub fn main() { pretty_env_logger::init(); let mgr = UnitsManager::new();