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/shadows/root_view.rs
1use pathfinder_geometry::vector::vec2f;
2use strato_ui::elements::{
3 Align, ConstrainedBox, Container, CornerRadius, DropShadow, Radius, Shrinkable,
4};
5use strato_ui::{
6 elements::{Flex, ParentElement, Rect},
7 AppContext, Element, Entity, TypedActionView, View,
8};
9 
10use strato_ui::color::ColorU;
11 
12pub struct RootView;
13 
14impl Entity for RootView {
15 type Event = ();
16}
17 
18fn rect_with_shadow(shadow: DropShadow, corner_radius: CornerRadius) -> Box<dyn Element> {
19 Shrinkable::new(
20 1.,
21 Container::new(
22 ConstrainedBox::new(
23 Rect::new()
24 .with_background_color(ColorU::new(255, 255, 255, 255))
25 .with_corner_radius(corner_radius)
26 .with_drop_shadow(shadow)
27 .finish(),
28 )
29 .with_width(200.)
30 .with_height(100.)
31 .finish(),
32 )
33 .with_uniform_margin(30.)
34 .finish(),
35 )
36 .finish()
37}
38 
39impl View for RootView {
40 fn ui_name() -> &'static str {
41 "RootView"
42 }
43 
44 fn render(&self, _: &AppContext) -> Box<dyn Element> {
45 Container::new(
46 Align::new(
47 Flex::column()
48 .with_children([
49 rect_with_shadow(
50 DropShadow {
51 color: ColorU::black(),
52 offset: vec2f(0., 10.),
53 blur_radius: 10.,
54 spread_radius: 30.,
55 },
56 CornerRadius::default(),
57 ),
58 rect_with_shadow(
59 DropShadow {
60 color: ColorU::new(255, 0, 0, 255),
61 offset: vec2f(10., 10.),
62 blur_radius: 5.,
63 spread_radius: 20.,
64 },
65 CornerRadius::with_all(Radius::Pixels(8.)),
66 ),
67 rect_with_shadow(
68 DropShadow {
69 color: ColorU::new(0, 255, 0, 255),
70 offset: vec2f(-10., -20.),
71 blur_radius: 20.,
72 spread_radius: 10.,
73 },
74 CornerRadius::with_all(Radius::Percentage(30.)),
75 ),
76 rect_with_shadow(
77 DropShadow {
78 color: ColorU::new(0, 0, 255, 255),
79 offset: vec2f(30., 0.),
80 blur_radius: 30.,
81 spread_radius: 40.,
82 },
83 CornerRadius::with_right(Radius::Pixels(40.)),
84 ),
85 ConstrainedBox::new(
86 Rect::new()
87 .with_background_color(ColorU::white())
88 .with_corner_radius(CornerRadius::with_all(Radius::Percentage(50.)))
89 .with_drop_shadow(DropShadow {
90 color: ColorU::black(),
91 offset: vec2f(-0.5, 2.),
92 blur_radius: 20.,
93 spread_radius: 0.,
94 })
95 .finish(),
96 )
97 .with_width(30.)
98 .with_height(30.)
99 .finish(),
100 ConstrainedBox::new(
101 Rect::new()
102 .with_background_color(ColorU::white())
103 .with_corner_radius(CornerRadius::with_all(Radius::Pixels(10.)))
104 .with_drop_shadow(DropShadow {
105 color: ColorU::black(),
106 offset: vec2f(50.5, 2.),
107 blur_radius: 2.,
108 spread_radius: 0.,
109 })
110 .finish(),
111 )
112 .with_width(30.)
113 .with_height(30.)
114 .finish(),
115 ])
116 .finish(),
117 )
118 .finish(),
119 )
120 .with_background_color(ColorU::new(128, 128, 128, 255))
121 .finish()
122 }
123}
124 
125impl TypedActionView for RootView {
126 type Action = ();
127}
128