From 833dc9ed3c4f26544dcd474ac74c40344cf9d4be Mon Sep 17 00:00:00 2001 From: fluo10 Date: Fri, 13 Jun 2025 22:32:16 +0900 Subject: [PATCH] Add examples --- .gitattributes | 1 + Cargo.toml | 5 ++-- examples/core/Cargo.toml | 10 +++++++ examples/core/assets/favicon.ico | 3 ++ examples/core/assets/header.svg | 20 ++++++++++++++ examples/core/assets/main.css | 46 +++++++++++++++++++++++++++++++ examples/core/src/lib.rs | 1 + examples/core/src/ui/mod.rs | 1 + examples/core/src/ui/plain/mod.rs | 33 ++++++++++++++++++++++ examples/desktop/Cargo.toml | 16 +++++++++++ examples/desktop/Dioxus.toml | 21 ++++++++++++++ examples/desktop/README.md | 25 +++++++++++++++++ examples/desktop/clippy.toml | 8 ++++++ examples/desktop/src/main.rs | 3 ++ examples/mobile/Cargo.toml | 17 ++++++++++++ examples/mobile/Dioxus.toml | 21 ++++++++++++++ examples/mobile/README.md | 25 +++++++++++++++++ examples/mobile/clippy.toml | 8 ++++++ examples/mobile/src/main.rs | 3 ++ 19 files changed, 265 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 examples/core/Cargo.toml create mode 100644 examples/core/assets/favicon.ico create mode 100644 examples/core/assets/header.svg create mode 100644 examples/core/assets/main.css create mode 100644 examples/core/src/lib.rs create mode 100644 examples/core/src/ui/mod.rs create mode 100644 examples/core/src/ui/plain/mod.rs create mode 100644 examples/desktop/Cargo.toml create mode 100644 examples/desktop/Dioxus.toml create mode 100644 examples/desktop/README.md create mode 100644 examples/desktop/clippy.toml create mode 100644 examples/desktop/src/main.rs create mode 100644 examples/mobile/Cargo.toml create mode 100644 examples/mobile/Dioxus.toml create mode 100644 examples/mobile/README.md create mode 100644 examples/mobile/clippy.toml create mode 100644 examples/mobile/src/main.rs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..361484f --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +*.ico filter=lfs diff=lfs merge=lfs -text diff --git a/Cargo.toml b/Cargo.toml index 2049214..b8a6b5c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = [ "lazy-supplements-*" ] +members = [ "lazy-supplements-*", "examples/*" ] resolver = "3" [workspace.package] @@ -10,9 +10,10 @@ license = "MIT OR Apache-2.0" repository = "https://forgejo.fireturlte.net/lazy-supplements" [workspace.dependencies] +dioxus = { version = "0.6.0", features = [] } lazy-supplements-core.path = "lazy-supplements-core" libp2p = { version = "0.55.0", features = ["macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux" ] } sea-orm-migration = { version = "1.1.0", features = ["runtime-tokio-rustls", "sqlx-postgres"] } serde = { version = "1.0.219", features = ["derive"] } thiserror = "2.0.12" -tokio = { version = "1.45.0", features = ["macros", "rt", "rt-multi-thread"] } \ No newline at end of file +tokio = { version = "1.45.0", features = ["macros", "rt", "rt-multi-thread"] } diff --git a/examples/core/Cargo.toml b/examples/core/Cargo.toml new file mode 100644 index 0000000..e33a06a --- /dev/null +++ b/examples/core/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "lazy-supplements-examples-core" +edition.workspace = true +version.workspace = true +description.workspace = true +license.workspace = true +repository.workspace = true + +[dependencies] +dioxus.workspace = true \ No newline at end of file diff --git a/examples/core/assets/favicon.ico b/examples/core/assets/favicon.ico new file mode 100644 index 0000000..c3c83af --- /dev/null +++ b/examples/core/assets/favicon.ico @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1c02a89f3d27fede4fa7f8c3702a58ab10caccc0a5ac5a4b8d7476053bb99049 +size 132770 diff --git a/examples/core/assets/header.svg b/examples/core/assets/header.svg new file mode 100644 index 0000000..59c96f2 --- /dev/null +++ b/examples/core/assets/header.svg @@ -0,0 +1,20 @@ + \ No newline at end of file diff --git a/examples/core/assets/main.css b/examples/core/assets/main.css new file mode 100644 index 0000000..90c0fc1 --- /dev/null +++ b/examples/core/assets/main.css @@ -0,0 +1,46 @@ +/* App-wide styling */ +body { + background-color: #0f1116; + color: #ffffff; + font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; + margin: 20px; +} + +#hero { + margin: 0; + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +#links { + width: 400px; + text-align: left; + font-size: x-large; + color: white; + display: flex; + flex-direction: column; +} + +#links a { + color: white; + text-decoration: none; + margin-top: 20px; + margin: 10px 0px; + border: white 1px solid; + border-radius: 5px; + padding: 10px; +} + +#links a:hover { + background-color: #1f1f1f; + cursor: pointer; +} + +#header { + max-width: 1200px; +} + + + diff --git a/examples/core/src/lib.rs b/examples/core/src/lib.rs new file mode 100644 index 0000000..b71b381 --- /dev/null +++ b/examples/core/src/lib.rs @@ -0,0 +1 @@ +pub mod ui; \ No newline at end of file diff --git a/examples/core/src/ui/mod.rs b/examples/core/src/ui/mod.rs new file mode 100644 index 0000000..d76e31c --- /dev/null +++ b/examples/core/src/ui/mod.rs @@ -0,0 +1 @@ +pub mod plain; \ No newline at end of file diff --git a/examples/core/src/ui/plain/mod.rs b/examples/core/src/ui/plain/mod.rs new file mode 100644 index 0000000..dc5fd57 --- /dev/null +++ b/examples/core/src/ui/plain/mod.rs @@ -0,0 +1,33 @@ +use dioxus::prelude::*; + +const FAVICON: Asset = asset!("/assets/favicon.ico"); +const MAIN_CSS: Asset = asset!("/assets/main.css"); +const HEADER_SVG: Asset = asset!("/assets/header.svg"); + +#[component] +pub fn App() -> Element { + rsx! { + document::Link { rel: "icon", href: FAVICON } + document::Link { rel: "stylesheet", href: MAIN_CSS } + Hero {} + + } +} + +#[component] +pub fn Hero() -> Element { + rsx! { + div { + id: "hero", + img { src: HEADER_SVG, id: "header" } + div { id: "links", + a { href: "https://dioxuslabs.com/learn/0.6/", "📚 Learn Dioxus" } + a { href: "https://dioxuslabs.com/awesome", "🚀 Awesome Dioxus" } + a { href: "https://github.com/dioxus-community/", "📡 Community Libraries" } + a { href: "https://github.com/DioxusLabs/sdk", "⚙️ Dioxus Development Kit" } + a { href: "https://marketplace.visualstudio.com/items?itemName=DioxusLabs.dioxus", "💫 VSCode Extension" } + a { href: "https://discord.gg/XgGxMSkvUM", "👋 Community Discord" } + } + } + } +} diff --git a/examples/desktop/Cargo.toml b/examples/desktop/Cargo.toml new file mode 100644 index 0000000..a8eb816 --- /dev/null +++ b/examples/desktop/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "lazy-supplements-examples-desktop" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dioxus.workspace = true +lazy-supplements-examples-core.path = "../core" + +[features] +default = ["desktop"] +web = ["dioxus/web"] +desktop = ["dioxus/desktop"] +mobile = ["dioxus/mobile"] diff --git a/examples/desktop/Dioxus.toml b/examples/desktop/Dioxus.toml new file mode 100644 index 0000000..659b7b6 --- /dev/null +++ b/examples/desktop/Dioxus.toml @@ -0,0 +1,21 @@ +[application] + +[web.app] + +# HTML title tag content +title = "desktop" + +# include `assets` in web platform +[web.resource] + +# Additional CSS style files +style = [] + +# Additional JavaScript files +script = [] + +[web.resource.dev] + +# Javascript code file +# serve: [dev-server] only +script = [] diff --git a/examples/desktop/README.md b/examples/desktop/README.md new file mode 100644 index 0000000..1e629b6 --- /dev/null +++ b/examples/desktop/README.md @@ -0,0 +1,25 @@ +# Development + +Your new bare-bones project includes minimal organization with a single `main.rs` file and a few assets. + +``` +project/ +├─ assets/ # Any assets that are used by the app should be placed here +├─ src/ +│ ├─ main.rs # main.rs is the entry point to your application and currently contains all components for the app +├─ Cargo.toml # The Cargo.toml file defines the dependencies and feature flags for your project +``` + +### Serving Your App + +Run the following command in the root of your project to start developing with the default platform: + +```bash +dx serve +``` + +To run for a different platform, use the `--platform platform` flag. E.g. +```bash +dx serve --platform desktop +``` + diff --git a/examples/desktop/clippy.toml b/examples/desktop/clippy.toml new file mode 100644 index 0000000..40456af --- /dev/null +++ b/examples/desktop/clippy.toml @@ -0,0 +1,8 @@ +await-holding-invalid-types = [ + "generational_box::GenerationalRef", + { path = "generational_box::GenerationalRef", reason = "Reads should not be held over an await point. This will cause any writes to fail while the await is pending since the read borrow is still active." }, + "generational_box::GenerationalRefMut", + { path = "generational_box::GenerationalRefMut", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." }, + "dioxus_signals::Write", + { path = "dioxus_signals::Write", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." }, +] diff --git a/examples/desktop/src/main.rs b/examples/desktop/src/main.rs new file mode 100644 index 0000000..e9fdd69 --- /dev/null +++ b/examples/desktop/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + dioxus::launch(lazy_supplements_examples_core::ui::plain::App); +} diff --git a/examples/mobile/Cargo.toml b/examples/mobile/Cargo.toml new file mode 100644 index 0000000..0b29f7b --- /dev/null +++ b/examples/mobile/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "lazy-supplements-examples-mobile" +version = "0.1.0" +authors = ["fluo10 "] +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +dioxus.workspace = true +lazy-supplements-examples-core.path = "../core" + +[features] +default = ["mobile"] +web = ["dioxus/web"] +desktop = ["dioxus/desktop"] +mobile = ["dioxus/mobile"] diff --git a/examples/mobile/Dioxus.toml b/examples/mobile/Dioxus.toml new file mode 100644 index 0000000..5938343 --- /dev/null +++ b/examples/mobile/Dioxus.toml @@ -0,0 +1,21 @@ +[application] + +[web.app] + +# HTML title tag content +title = "mobile" + +# include `assets` in web platform +[web.resource] + +# Additional CSS style files +style = [] + +# Additional JavaScript files +script = [] + +[web.resource.dev] + +# Javascript code file +# serve: [dev-server] only +script = [] diff --git a/examples/mobile/README.md b/examples/mobile/README.md new file mode 100644 index 0000000..1e629b6 --- /dev/null +++ b/examples/mobile/README.md @@ -0,0 +1,25 @@ +# Development + +Your new bare-bones project includes minimal organization with a single `main.rs` file and a few assets. + +``` +project/ +├─ assets/ # Any assets that are used by the app should be placed here +├─ src/ +│ ├─ main.rs # main.rs is the entry point to your application and currently contains all components for the app +├─ Cargo.toml # The Cargo.toml file defines the dependencies and feature flags for your project +``` + +### Serving Your App + +Run the following command in the root of your project to start developing with the default platform: + +```bash +dx serve +``` + +To run for a different platform, use the `--platform platform` flag. E.g. +```bash +dx serve --platform desktop +``` + diff --git a/examples/mobile/clippy.toml b/examples/mobile/clippy.toml new file mode 100644 index 0000000..40456af --- /dev/null +++ b/examples/mobile/clippy.toml @@ -0,0 +1,8 @@ +await-holding-invalid-types = [ + "generational_box::GenerationalRef", + { path = "generational_box::GenerationalRef", reason = "Reads should not be held over an await point. This will cause any writes to fail while the await is pending since the read borrow is still active." }, + "generational_box::GenerationalRefMut", + { path = "generational_box::GenerationalRefMut", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." }, + "dioxus_signals::Write", + { path = "dioxus_signals::Write", reason = "Write should not be held over an await point. This will cause any reads or writes to fail while the await is pending since the write borrow is still active." }, +] diff --git a/examples/mobile/src/main.rs b/examples/mobile/src/main.rs new file mode 100644 index 0000000..08bf13e --- /dev/null +++ b/examples/mobile/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + dioxus::launch(lazy_supplements_examples_core::ui::plain::App); +} \ No newline at end of file