Skip to main content

examples/reflection/
member_ranges.rs

1use crate::z_ignore_test_common::*;
2
3use flecs_ecs::prelude::*;
4
5#[derive(Component)]
6#[flecs(meta)]
7pub struct CpuUtilization {
8    pub value: f64,
9}
10
11fn main() {
12    let mut world = World::new();
13
14    world
15        .component::<CpuUtilization>()
16        .meta()
17        .range(0.0, 100.0) // Specifics values that the member can assume
18        .warning_range(0.0, 60.0) // Values outside this range are considered a warning
19        .error_range(0.0, 80.0); // Values outside this range are considered an error
20
21    world
22        .entity_named("MachineA")
23        .set(CpuUtilization { value: 50.0 });
24    world
25        .entity_named("MachineB")
26        .set(CpuUtilization { value: 75.0 });
27    world
28        .entity_named("MachineC")
29        .set(CpuUtilization { value: 90.0 });
30
31    // Uncomment this line and open
32    //   https://www.flecs.dev/explorer?show=query&query=CpuUtilization
33    // to see how ranges affect visualization:
34    // world.app().enable_rest(0).run();
35}