pub struct Inspector { /* private fields */ }Expand description
The inspector’s window: a list of the world’s entities, a page at a
time, filtered by their numbers and the names of their components, and
the components of the one clicked, which Inspector::show edits
through their Reflect impls. It finds the component types in the
world’s TypeRegistry, a resource.
- The list: each entity as its slot and generation,
3v1, then the names of its registered components. The filter keeps the entities that match each of its words, ignoring case: a word matches an entity’s number, or the name of a component it has. - Editing: a struct’s fields are rows, a struct inside one a tree
node; a list’s elements and an object’s members (a value reflected
whole, such as a sprite) are rows under a node; a boolean is a
checkbox; a float a drag; a whole number, a string or an asset’s path a
text field, applied on Enter or a press elsewhere, dropped on Escape;
a
Colora color edit, as is a string that writes a color among the members of a value reflected whole; an enum’s variant a combo; a pair of numbers a row of two. A change is applied to the component at once, throughReflect::apply_value; one it refuses is not set, and the note says why, as the log does in full. - Changes of structure go through the world’s commands, and so show
after the next tick or frame: “Despawn”, “Add” (a component of a type
it lacks, made from the JSONC typed beside it,
{}at first:0for a number’s newtype,[0, 0]for a position’s,"Down"for an enum; one the type refuses is not added, and the note says why), and each component’s “Remove”. - Save as prefab: with a name the prefab reader takes, lowercase
letters, digits and
_, it asks the caller to writeInspector::prefab.
A frame with no component open allocates nothing once its buffers have
grown; an open one builds its values (Reflect::to_value) each frame.
Implementations§
Source§impl Inspector
impl Inspector
Sourcepub fn selected(&self) -> Option<Entity>
pub fn selected(&self) -> Option<Entity>
The entity whose components it shows, if one was clicked; it may have been despawned since.
Sourcepub fn select(&mut self, entity: Option<Entity>)
pub fn select(&mut self, entity: Option<Entity>)
Shows entity’s components, or none. An edit not yet applied is
dropped.
Sourcepub fn prefab_name(&self) -> &str
pub fn prefab_name(&self) -> &str
The name typed for a prefab, which “Save as prefab” saves the selected entity as.
Sourcepub fn set_note(&mut self, note: impl Display)
pub fn set_note(&mut self, note: impl Display)
Shows note under the selected entity’s buttons, until the next:
where a prefab was written, say, or why not.
Sourcepub fn show(
&mut self,
world: &World,
ui: &mut Ui<'_>,
cx: &mut ReflectContext<'_>,
) -> InspectorResponse
pub fn show( &mut self, world: &World, ui: &mut Ui<'_>, cx: &mut ReflectContext<'_>, ) -> InspectorResponse
Fills a window with the entity list and the selected entity’s
components, from the world’s TypeRegistry. cx reads and
writes the values: one that can write and read asset handles, and
that has the resources the game’s components need, such as the
facade’s loading_context. Its errors and warnings name the
component and the field, under cx’s source.
§Panics
If a registered type is not registered with world, or its
components or the registry are borrowed mutably elsewhere.
Sourcepub fn prefab(
&self,
world: &World,
leave_out: &[&str],
cx: &mut ReflectContext<'_>,
) -> Option<String>
pub fn prefab( &self, world: &World, leave_out: &[&str], cx: &mut ReflectContext<'_>, ) -> Option<String>
The selected entity as the prefab Inspector::prefab_name, as
JSONC text: a comment line, then {"name": ..., "components": {...}}, each component of a type in the world’s TypeRegistry
that it has, in the registry’s order, as Reflect::to_value
writes it with cx, but those whose names leave_out lists. None
if no entity alive is selected, or the world has no registry.
cx writes the values: one that writes asset handles as their
paths, and has the resources the game’s components need, such as
the facade’s reflect_context.