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/table-sample/main.rs
1use anyhow::{anyhow, Result};
2use pathfinder_geometry::vector::vec2f;
3use std::borrow::Cow;
4pub mod root_view;
5 
6extern crate strato_ui;
7use rust_embed::RustEmbed;
8use strato_ui::{platform, platform::WindowBounds, AssetProvider};
9 
10#[derive(Clone, Copy, RustEmbed)]
11#[folder = "examples/assets"]
12pub struct Assets;
13 
14pub static ASSETS: Assets = Assets;
15 
16impl AssetProvider for Assets {
17 fn get(&self, path: &str) -> Result<Cow<'_, [u8]>> {
18 <Assets as RustEmbed>::get(path)
19 .map(|f| f.data)
20 .ok_or_else(|| anyhow!("no asset exists at path {}", path))
21 }
22}
23 
24#[derive(Debug, Clone, Default)]
25pub struct CaptureConfig {
26 pub capture_screenshots: bool,
27 pub capture_baseline: bool,
28}
29 
30fn parse_args() -> CaptureConfig {
31 let args: Vec<String> = std::env::args().collect();
32 let mut config = CaptureConfig::default();
33 
34 for arg in args.iter() {
35 match arg.as_str() {
36 "--capture-screenshots" => config.capture_screenshots = true,
37 "--capture-baseline" => {
38 config.capture_screenshots = true;
39 config.capture_baseline = true;
40 }
41 "--help" | "-h" => {
42 println!("Table Sample Example - Screenshot Testing");
43 println!("\nUsage: table-sample [OPTIONS]");
44 println!("\nOptions:");
45 println!(" --capture-screenshots Capture screenshots of all demos");
46 println!(" --capture-baseline Capture and save as baseline screenshots");
47 println!(" --help, -h Show this help message");
48 std::process::exit(0);
49 }
50 _ => {}
51 }
52 }
53 
54 config
55}
56 
57fn main() -> Result<()> {
58 env_logger::builder().format_timestamp_millis().init();
59 let capture_config = parse_args();
60 
61 if capture_config.capture_screenshots {
62 println!("📸 Screenshot capture mode enabled");
63 if capture_config.capture_baseline {
64 println!("📁 Baseline mode: screenshots will be saved as reference images");
65 }
66 }
67 
68 let app_builder =
69 platform::AppBuilder::new(platform::AppCallbacks::default(), Box::new(ASSETS), None);
70 let _ = app_builder.run(move |ctx| {
71 root_view::init(ctx);
72 let window_options = strato_ui::AddWindowOptions {
73 window_bounds: WindowBounds::ExactSize(vec2f(1000.0, 800.0)),
74 window_style: if capture_config.capture_screenshots {
75 strato_ui::platform::WindowStyle::NotStealFocus
76 } else {
77 strato_ui::platform::WindowStyle::Normal
78 },
79 ..Default::default()
80 };
81 let config = capture_config.clone();
82 #[cfg_attr(not(target_os = "macos"), allow(unused_variables))]
83 let (window_id, _root) = ctx.add_window(window_options, move |view_ctx| {
84 root_view::RootView::new(view_ctx, config)
85 });
86 #[cfg(target_os = "macos")]
87 if capture_config.capture_screenshots {
88 // Make it visible for rendering but keep z-index
89 ctx.windows()
90 .show_window_and_focus_app_without_ordering_front(window_id);
91 }
92 });
93 
94 Ok(())
95}
96