1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
use raui_app::app::declarative::DeclarativeApp;
use raui_core::{
make_widget, pre_hooks,
widget::{
component::{
containers::{
scroll_box::{SideScrollbarsProps, nav_scroll_box, nav_scroll_box_side_scrollbars},
size_box::{SizeBoxProps, size_box},
vertical_box::{VerticalBoxProps, vertical_box},
wrap_box::{WrapBoxProps, wrap_box},
},
image_box::{ImageBoxProps, image_box},
interactive::{
navigation::{NavItemActive, use_nav_container_active},
scroll_view::ScrollViewRange,
},
text_box::{TextBoxProps, text_box},
},
context::WidgetContext,
node::WidgetNode,
unit::{
flex::FlexBoxItemLayout,
image::{
ImageBoxAspectRatio, ImageBoxColor, ImageBoxImage, ImageBoxMaterial,
ImageBoxSizeValue,
},
size::SizeBoxSizeValue,
text::{TextBoxFont, TextBoxSizeValue},
},
utils::{Color, Rect},
},
};
#[pre_hooks(use_nav_container_active)]
fn app(mut ctx: WidgetContext) -> WidgetNode {
make_widget!(wrap_box)
.with_props(WrapBoxProps {
margin: Rect {
left: 100.0,
right: 50.0,
top: 75.0,
bottom: 25.0,
},
..Default::default()
})
.named_slot(
"content",
make_widget!(nav_scroll_box)
.with_props(NavItemActive)
.with_props(ScrollViewRange::default())
.named_slot(
"content",
make_widget!(size_box)
.with_props(SizeBoxProps {
width: SizeBoxSizeValue::Fill,
// first we make sure to put content in size box that
// uses content height to make it take minimal space.
height: SizeBoxSizeValue::Content,
..Default::default()
})
.named_slot(
"content",
make_widget!(vertical_box)
.with_props(VerticalBoxProps {
// we need to make sure all items are not
// growing and shrinking to let size box
// calculate correct content size. growing
// and shrinking would make items take all
// available space, filling all container.
override_slots_layout: Some(
FlexBoxItemLayout::no_growing_and_shrinking(),
),
..Default::default()
})
.listed_slot(make_widget!(image_box).with_props(ImageBoxProps {
height: ImageBoxSizeValue::Exact(300.0),
material: ImageBoxMaterial::Image(ImageBoxImage {
id: "./crates/_/examples/resources/map.png".to_owned(),
..Default::default()
}),
content_keep_aspect_ratio: Some(ImageBoxAspectRatio {
horizontal_alignment: 0.5,
vertical_alignment: 0.5,
outside: false,
}),
..Default::default()
}))
.listed_slot(make_widget!(text_box).with_props(TextBoxProps {
text: include_str!("./resources/long_text.txt").to_owned(),
font: TextBoxFont {
name:
"./demos/hello-world/resources/verdana.ttf".to_owned(),
size: 64.0,
},
color: Color {
r: 0.0,
g: 0.0,
b: 0.5,
a: 1.0,
},
height: TextBoxSizeValue::Content,
..Default::default()
})),
),
)
.named_slot(
"scrollbars",
make_widget!(nav_scroll_box_side_scrollbars).with_props(SideScrollbarsProps {
size: 20.0,
back_material: Some(ImageBoxMaterial::Color(ImageBoxColor {
color: Color {
r: 0.15,
g: 0.15,
b: 0.15,
a: 1.0,
},
..Default::default()
})),
front_material: ImageBoxMaterial::Color(ImageBoxColor {
color: Color {
r: 0.85,
g: 0.85,
b: 0.85,
a: 1.0,
},
..Default::default()
}),
}),
),
)
.into()
}
fn main() {
DeclarativeApp::simple("Scroll Box - Adaptive content size", make_widget!(app));
}