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/manual-scrolling/main.rs
1use anyhow::{anyhow, Result};
2use std::borrow::Cow;
3pub mod root_view;
4 
5extern crate strato_ui;
6use rust_embed::RustEmbed;
7use strato_ui::{platform, AssetProvider};
8 
9#[derive(Clone, Copy, RustEmbed)]
10#[folder = "examples/assets"]
11pub struct Assets;
12 
13// The static assets we need to load in app.
14pub static ASSETS: Assets = Assets;
15 
16// Implement the AssetProvider trait here (required by App::new).
17impl 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 
25fn 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 root_view::init(ctx);
30 ctx.add_window(
31 strato_ui::AddWindowOptions::default(),
32 root_view::RootView::new,
33 );
34 });
35 
36 Ok(())
37}
38