-
Notifications
You must be signed in to change notification settings - Fork 32
/
tabview.rs
46 lines (44 loc) · 1.19 KB
/
tabview.rs
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
// examples/tabview.rs
// cargo run --example tabview
use belly::prelude::*;
use bevy::prelude::*;
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(BellyPlugin)
.add_systems(Startup, setup)
.run();
}
#[derive(Component, Default)]
struct TabController;
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
commands.add(StyleSheet::parse(
"
body {
flex-direction: column;
}
.hidden {
display: none;
}
",
));
commands.add(eml! {
<body s:padding="20px">
<buttongroup on:value_change=|ctx| {
let ev = ctx.event();
ctx.select(ev.old_value()).add_class("hidden");
ctx.select(ev.new_value()).remove_class("hidden");
}>
<button value=".tab1" pressed>"Tab 1"</button>
<button value=".tab2">"Tab 2"</button>
<button value=".tab3">"Tab 3"</button>
</buttongroup>
<div c:content>
<div c:tab1>"Tab 1 content"</div>
<div c:tab2 c:hidden>"Tab 2 content"</div>
<div c:tab3 c:hidden>"Tab 3 content"</div>
</div>
</body>
});
}