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/image/root_view.rs
1use pathfinder_color::ColorU;
2use strato_ui::{
3 elements::{
4 CacheOption, ConstrainedBox, Flex, Icon, Image, MainAxisAlignment, MainAxisSize,
5 ParentElement, Rect, Stack,
6 },
7 AppContext, Element, Entity, TypedActionView, View,
8};
9 
10pub struct RootView {}
11 
12impl RootView {
13 pub fn new() -> Self {
14 RootView {}
15 }
16}
17 
18impl Default for RootView {
19 fn default() -> Self {
20 Self::new()
21 }
22}
23 
24impl Entity for RootView {
25 type Event = ();
26}
27impl View for RootView {
28 fn ui_name() -> &'static str {
29 "RootView"
30 }
31 
32 fn render(&self, _: &AppContext) -> Box<dyn Element> {
33 let asset_source = strato_ui::assets::asset_cache::AssetSource::LocalFile {
34 path: "./crates/strato-ui-core/test_data/local.png".to_string(),
35 };
36 
37 Stack::new()
38 .with_child(Rect::new().with_background_color(ColorU::white()).finish())
39 .with_child(
40 Flex::column()
41 .with_main_axis_alignment(MainAxisAlignment::Center)
42 .with_main_axis_size(MainAxisSize::Max)
43 .with_child(
44 Flex::row()
45 .with_main_axis_alignment(MainAxisAlignment::Center)
46 .with_main_axis_size(MainAxisSize::Max)
47 .with_child(
48 ConstrainedBox::new(
49 Image::new(asset_source, CacheOption::BySize)
50 .before_load(
51 Icon::new(
52 "ui/examples/image/loading.svg",
53 ColorU::black(),
54 )
55 .finish(),
56 )
57 .finish(),
58 )
59 .with_height(500.)
60 .with_width(500.)
61 .finish(),
62 )
63 .finish(),
64 )
65 .finish(),
66 )
67 .finish()
68 }
69}
70 
71impl TypedActionView for RootView {
72 type Action = ();
73}
74