clide/src/gui.rs

40 lines
1.2 KiB
Rust
Raw Normal View History

2026-01-31 08:02:16 -05:00
// SPDX-FileCopyrightText: 2026, Shaun Reed <shaunrd0@gmail.com>
//
// SPDX-License-Identifier: GNU General Public License v3.0 or later
2026-01-31 04:25:14 +00:00
use crate::AppContext;
2026-01-25 20:57:36 +00:00
use anyhow::Result;
2026-01-31 04:25:14 +00:00
use cxx_qt_lib::{QMapPair, QMapPair_QString_QVariant, QString, QVariant};
2026-01-25 20:57:36 +00:00
use log::trace;
pub mod colors;
pub mod filesystem;
2026-01-31 04:25:14 +00:00
pub fn run(app_context: AppContext) -> Result<()> {
trace!(target:"gui::run()", "Starting the GUI editor at {:?}", app_context.path);
2026-01-25 20:57:36 +00:00
use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl};
let mut app = QGuiApplication::new();
let mut engine = QQmlApplicationEngine::new();
2026-01-31 04:25:14 +00:00
// Set QML property for the directory provided to the CLI.
let path = QString::from(app_context.path.to_string_lossy().to_string());
let mut map = QMapPair_QString_QVariant::default();
map.insert(QString::from("appContextPath"), QVariant::from(&path));
engine.as_mut().unwrap().set_initial_properties(&map);
2026-01-25 20:57:36 +00:00
if let Some(engine) = engine.as_mut() {
engine.add_import_path(&QString::from("qml/"));
}
if let Some(engine) = engine.as_mut() {
engine.load(&QUrl::from("qml/main.qml"));
}
if let Some(app) = app.as_mut() {
app.exec();
}
Ok(())
}