#bevy #derive #inspector #bevy-plugin #webserver #contrib

archived macro bevy-contrib-inspector-derive

Implementation detail of the bevy-contrib-inspector crate

5 releases (breaking)

0.5.0 Dec 21, 2020
0.4.0 Dec 20, 2020
0.3.0 Nov 4, 2020
0.2.0 Sep 19, 2020
0.1.0 Sep 5, 2020
Download history 50/week @ 2022-06-02 4/week @ 2022-06-09 8/week @ 2022-06-16 10/week @ 2022-06-23 22/week @ 2022-06-30 12/week @ 2022-07-07 10/week @ 2022-07-14 19/week @ 2022-07-21 10/week @ 2022-07-28 15/week @ 2022-08-04 12/week @ 2022-08-11 6/week @ 2022-08-18 9/week @ 2022-08-25 8/week @ 2022-09-01 25/week @ 2022-09-08 10/week @ 2022-09-15

52 downloads per month
Used in bevy-contrib-inspector

MIT license

15KB
388 lines

bevy-contrib-inspector


DISCLAIMER: you probably want to use bevy-inspector-egui instead

This crate provides the ability to annotate structs with a #[derive(Inspectable)], which opens a web interface (by default on port 5676) where you can visually edit the values of your struct live.

Your struct will then be available to you as a bevy resource.

Your image title

Example

use bevy_contrib_inspector::Inspectable;

#[derive(Inspectable, Default)]
struct Data {
    should_render: bool,
    text: String,
    #[inspectable(min = 42.0, max = 100.0)]
    size: f32,
}

Add the InspectorPlugin to your App.

use bevy_contrib_inspector::InspectorPlugin;

fn main() {
    App::build()
        .add_default_plugins()
        .add_plugin(InspectorPlugin::<Data>::new())
        .add_system(your_system.system())
        // ...
        .run();
}

fn your_system(data: ChangedRes<Data>, mut query: Query<...>) { /* */ }

To automatically open the webbrowser when starting, run your program using BEVY_INSPECTOR_OPEN=1 cargo run.

Attributes

When deriving the Inspectable trait, you can set options such like the port the server will run on like so:

#[derive(Inspectable, Default)]
#[inspectable(port = 1234)]
struct Data {
   #[inspectable(a = 1, b = 2, c = 3)]
   field: Type,
}

The attribute on the struct will accept fields of the type InspectableOptions, while the attributes on the fields accept those of their <Type as AsHtml>::Options.

Features

native: Instead of opening the inspector window in a browser, start a webkit2gtk window.

On ubuntu, the feature requires sudo apt install libwebkit2gtk-4.0-dev

Dependencies

~225–630KB
~15K SLoC