Newer
Older
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
use bevy::prelude::*;
use kayak_ui::prelude::{widgets::*, *};
fn startup(
mut commands: Commands,
mut font_mapping: ResMut<FontMapping>,
asset_server: Res<AssetServer>,
) {
font_mapping.set_default(asset_server.load("roboto.kayak_font"));
// Camera 2D forces a clear pass in bevy.
// We do this because our scene is not rendering anything else.
commands.spawn(Camera2dBundle::default());
let mut widget_context = KayakRootContext::new();
widget_context.add_plugin(KayakWidgetsContextPlugin);
let parent_id = None;
rsx! {
<KayakAppBundle>
<WindowBundle
window={KWindow {
title: "Layout example".into(),
draggable: true,
initial_position: Vec2::new(10.0, 10.0),
size: Vec2::new(512.0, 512.0),
..KWindow::default()
}}
>
<ElementBundle
styles={KStyle{
layout_type: LayoutType::Grid.into(),
grid_rows: vec![Units::Stretch(1.0), Units::Stretch(2.0), Units::Stretch(5.0)].into(),
grid_cols: vec![Units::Stretch(1.0), Units::Stretch(1.0)].into(),
..default()
}}
>
<BackgroundBundle
styles={KStyle{
background_color: Color::rgb(0.4, 0.9, 0.4).into(),
color: Color::rgb(0.0, 0.0, 0.0).into(),
padding: Edge::all(Units::Pixels(5.0)).into(),
border_radius: Corner::all(10.0).into(),
row_index: 0.into(),
col_index: 0.into(),
col_span: 2.into(),
layout_type: LayoutType::Row.into(),
col_between: Units::Pixels(5.0).into(),
..default()
}}
>
<TextWidgetBundle
text={TextProps {
content: "A".into(),
..default()
}}
/>
<TextWidgetBundle
text={TextProps {
content: "B".into(),
..default()
}}
/>
<TextWidgetBundle
text={TextProps {
content: "C".into(),
..default()
}}
/>
<TextWidgetBundle
text={TextProps {
content: "D".into(),
..default()
}}
/>
<TextWidgetBundle
text={TextProps {
content: "E".into(),
..default()
}}
/>
</BackgroundBundle>
<TextWidgetBundle
text={TextProps {
content: "R1 C0".into(),
..default()
}}
styles={KStyle{
row_index: 1.into(),
col_index: 0.into(),
..default()
}}
/>
<TextWidgetBundle
text={TextProps {
content: "R1 C1".into(),
..default()
}}
styles={KStyle{
row_index: 1.into(),
col_index: 1.into(),
..default()
}}
/>
<TextWidgetBundle
text={TextProps {
content: "R2 C0".into(),
..default()
}}
styles={KStyle{
row_index: 2.into(),
col_index: 0.into(),
..default()
}}
/>
<TextWidgetBundle
text={TextProps {
content: "R2 C1".into(),
..default()
}}
styles={KStyle{
row_index: 2.into(),
col_index: 1.into(),
..default()
}}
/>
</ElementBundle>
</WindowBundle>
</KayakAppBundle>