-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscroll_discrete.rs
50 lines (43 loc) · 1.38 KB
/
scroll_discrete.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
47
48
49
50
//! This showcases discrete scrolling.
use bevy::{prelude::*, diagnostic::FrameTimeDiagnosticsPlugin};
use bevy_rectray::{RectrayPlugin, widgets::scroll::ScrollDiscrete, util::RCommands};
pub fn main() {
App::new()
.add_plugins(DefaultPlugins.set(WindowPlugin {
primary_window: Some(Window {
present_mode: bevy::window::PresentMode::AutoNoVsync,
..Default::default()
}),
..Default::default()
}))
.add_plugins(FrameTimeDiagnosticsPlugin)
.add_systems(Startup, init)
.add_plugins(RectrayPlugin)
// classic macos stuff
.run();
}
pub fn init(mut commands: RCommands) {
use bevy_rectray::dsl::prelude::*;
commands.spawn_bundle(Camera2dBundle::default());
text!(commands {
anchor: TopRight,
text: "FPS: 0.00",
color: color!(gold),
system: |fps: Fps, text: Ac<Text>| {
let fps = fps.get().await;
text.set(move |text| format_widget!(text, "FPS: {:.2}", fps)).await?;
}
});
let s = "abcdefghijklmnopqrstuvwxyz".chars();
vstack! (commands {
dimension: [200, 60],
hitbox: Hitbox::rect(1),
event: EventFlags::MouseWheel,
children_range: 0..5,
font_size: em(4),
extra: ScrollDiscrete::new(),
child: #text! {
text: #s
}
});
}