StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use anyhow::{anyhow, Result}; |
| 2 | use std::borrow::Cow; |
| 3 | pub mod root_view; |
| 4 | |
| 5 | extern crate strato_ui; |
| 6 | use rust_embed::RustEmbed; |
| 7 | use strato_ui::{platform, AssetProvider}; |
| 8 | |
| 9 | #[derive(Clone, Copy, RustEmbed)] |
| 10 | #[folder = "examples/assets"] |
| 11 | pub struct Assets; |
| 12 | |
| 13 | // The static assets we need to load in app. |
| 14 | pub static ASSETS: Assets = Assets; |
| 15 | |
| 16 | // Implement the AssetProvider trait here (required by App::new). |
| 17 | impl AssetProvider for Assets { |
| 18 | fn get(&self, path: &str) -> Result<Cow<'_, [u8]>> { |
| 19 | <Assets as RustEmbed>::get(path) |
| 20 | .map(|f| f.data) |
| 21 | .ok_or_else(|| anyhow!("no asset exists at path {}", path)) |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | fn main() -> Result<()> { |
| 26 | let app_builder = |
| 27 | platform::AppBuilder::new(platform::AppCallbacks::default(), Box::new(ASSETS), None); |
| 28 | let _ = app_builder.run(move |ctx| { |
| 29 | let view_handle = root_view::RootView::new; |
| 30 | ctx.add_window(strato_ui::AddWindowOptions::default(), view_handle); |
| 31 | }); |
| 32 | |
| 33 | Ok(()) |
| 34 | } |
| 35 |