From c730b2e54a47e7c255d6c19ba3c0bac6403fe7f1 Mon Sep 17 00:00:00 2001 From: mcitem Date: Thu, 12 Dec 2024 19:08:42 +0800 Subject: [PATCH] feat: Path Aliases --- .gitignore | 2 +- .vscode/settings.json | 7 +++++++ build.rs | 9 ++++++++- ui/app.slint | 14 +++++++------- ui/global.slint | 10 +++++----- ui/index.slint | 2 -- ui/views/index.slint | 6 ------ ui/views/main.slint | 27 ++++++++++++++------------- 8 files changed, 42 insertions(+), 35 deletions(-) create mode 100644 .vscode/settings.json delete mode 100644 ui/index.slint delete mode 100644 ui/views/index.slint diff --git a/.gitignore b/.gitignore index 6277c97..af15bf5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /target -.vscode +# .vscode .idea /packages **/.DS_Store \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..badaba2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "slint.libraryPaths": { + "ui": "ui\\", + "sui": "ui\\modules\\surrealism-ui\\", + "views": "ui\\views\\" + } +} diff --git a/build.rs b/build.rs index c19a7b8..86592c7 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,10 @@ fn main() { - slint_build::compile("ui/app.slint").unwrap(); + let manifest_dir = std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap()); + let library_paths = std::collections::HashMap::from([ + ("ui".into(), manifest_dir.join("ui")), + ("views".into(), manifest_dir.join("ui/views")), + ("sui".into(), manifest_dir.join("ui/modules/surrealism-ui")), + ]); + let config = slint_build::CompilerConfiguration::new().with_library_paths(library_paths); + slint_build::compile_with_config("ui/app.slint", config).unwrap(); } diff --git a/ui/app.slint b/ui/app.slint index 442fe2e..0d9868f 100644 --- a/ui/app.slint +++ b/ui/app.slint @@ -1,9 +1,9 @@ -import {MainView} from "./index.slint"; -import {ROOT_GLOBAL} from "./global.slint"; +import { MainView } from "@views/main.slint"; +import { ROOT_GLOBAL } from "@ui/global.slint"; export component App inherits Window { - height: ROOT-GLOBAL.window-height; - width: ROOT-GLOBAL.window-width; - title: @tr("Slint + SurrealismUI + Rust"); - MainView {} -} \ No newline at end of file + height: ROOT-GLOBAL.window-height; + width: ROOT-GLOBAL.window-width; + title: @tr("Slint + SurrealismUI + Rust"); + MainView { } +} diff --git a/ui/global.slint b/ui/global.slint index cf57fa2..7dfff9b 100644 --- a/ui/global.slint +++ b/ui/global.slint @@ -1,7 +1,7 @@ //! global styles export global ROOT_GLOBAL { - in-out property window-height : 600px; - in-out property window-width : 800px; - in-out property font-size : 16px; - in-out property padding : 0px; -} \ No newline at end of file + in-out property window-height: 600px; + in-out property window-width: 800px; + in-out property font-size: 16px; + in-out property padding: 0px; +} diff --git a/ui/index.slint b/ui/index.slint deleted file mode 100644 index 6e2fd86..0000000 --- a/ui/index.slint +++ /dev/null @@ -1,2 +0,0 @@ -//export views -export * from "./views/index.slint"; \ No newline at end of file diff --git a/ui/views/index.slint b/ui/views/index.slint deleted file mode 100644 index b2ee4f0..0000000 --- a/ui/views/index.slint +++ /dev/null @@ -1,6 +0,0 @@ -//! export views -//! you should export all views here - -import { MainView } from "./main.slint"; - -export { MainView } \ No newline at end of file diff --git a/ui/views/main.slint b/ui/views/main.slint index 03e1fd6..e7f440f 100644 --- a/ui/views/main.slint +++ b/ui/views/main.slint @@ -1,16 +1,17 @@ -import {Hello} from "../components/index.slint"; -import { SButton } from "../modules/surrealism-ui/index.slint"; +import { Hello } from "@ui/components/index.slint"; +import { SButton } from "@sui/index.slint"; export component MainView { - height: 100%; - width: 100%; - VerticalLayout { - Hello{} - Rectangle { - SButton { - theme:Dark; - text: "Click Me!"; - } + height: 100%; + width: 100%; + VerticalLayout { + Hello { } + + Rectangle { + SButton { + theme: Dark; + text: "Click Me!"; + } + } } - } -} \ No newline at end of file +}