dioxus/examples/dynamic_asset.rs

26 lines
647 B
Rust
Raw Normal View History

2023-12-17 23:14:55 +00:00
use dioxus::prelude::*;
2024-01-06 02:08:04 +00:00
use dioxus_desktop::{use_asset_handler, wry::http::Response};
2023-12-17 23:14:55 +00:00
fn main() {
launch_desktop(app);
2023-12-17 23:14:55 +00:00
}
fn app() -> Element {
use_asset_handler("logos", |request, response| {
2024-01-06 02:08:04 +00:00
// Note that the "logos" prefix is stripped from the URI
//
// However, the asset is absolute to its "virtual folder" - meaning it starts with a leading slash
if request.uri().path() != "/logo.png" {
return;
2023-12-17 23:14:55 +00:00
}
2024-01-06 02:08:04 +00:00
response.respond(Response::new(include_bytes!("./assets/logo.png").to_vec()));
2023-12-17 23:14:55 +00:00
});
2024-01-16 19:18:46 +00:00
rsx! {
2023-12-17 23:14:55 +00:00
div {
img { src: "/logos/logo.png" }
2023-12-17 23:14:55 +00:00
}
}
2023-12-17 23:14:55 +00:00
}