Skip to main content

Inspector

Struct Inspector 

Source
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 Color a 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, through Reflect::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: 0 for 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 write Inspector::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

Source

pub fn new() -> Self

An inspector with nothing selected and no filter.

Source

pub fn selected(&self) -> Option<Entity>

The entity whose components it shows, if one was clicked; it may have been despawned since.

Source

pub fn select(&mut self, entity: Option<Entity>)

Shows entity’s components, or none. An edit not yet applied is dropped.

Source

pub fn prefab_name(&self) -> &str

The name typed for a prefab, which “Save as prefab” saves the selected entity as.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for Inspector

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.