Seregon/StratoSDK

StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.

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