pub struct WidgetDocUtility<'w, 's> { /* private fields */ }Expand description
High-level runtime API for document-driven UI workflows.
This system param keeps the editable document as the source of truth. A common flow is:
load_path- mutate the document with
with_widget_mut/with_style_mut spawn- optionally mutate live components with
with_live_widget_mut
§Example
use bevy::prelude::*;
use bevy_vista::runtime::prelude::*;
fn setup(
mut commands: Commands,
mut docs: WidgetDocUtility,
) {
let root = commands.spawn_empty().id();
let doc = docs.load_path("assets/ui/runtime_widget_doc_demo.vista.ron").unwrap();
let _instance = docs.spawn(doc, root).unwrap();
}Implementations§
Source§impl<'w, 's> WidgetDocUtility<'w, 's>
impl<'w, 's> WidgetDocUtility<'w, 's>
Sourcepub fn load_path(
&mut self,
path: impl AsRef<Path>,
) -> Result<WidgetDocId, WidgetDocError>
pub fn load_path( &mut self, path: impl AsRef<Path>, ) -> Result<WidgetDocId, WidgetDocError>
Loads a .vista.ron file into the internal document store.
Sourcepub fn load_and_spawn_path(
&mut self,
path: impl AsRef<Path>,
parent: Entity,
) -> Result<WidgetDocInstanceId, WidgetDocError>
pub fn load_and_spawn_path( &mut self, path: impl AsRef<Path>, parent: Entity, ) -> Result<WidgetDocInstanceId, WidgetDocError>
Loads a document from disk and immediately spawns it under parent.
Sourcepub fn insert_document(
&mut self,
document: WidgetBlueprintDocument,
) -> WidgetDocId
pub fn insert_document( &mut self, document: WidgetBlueprintDocument, ) -> WidgetDocId
Inserts an existing blueprint document into the runtime store.
Sourcepub fn source_path(&self, doc_id: WidgetDocId) -> Option<&Path>
pub fn source_path(&self, doc_id: WidgetDocId) -> Option<&Path>
Returns the persisted source path for a loaded document, if any.
Sourcepub fn document(&self, doc_id: WidgetDocId) -> Option<&WidgetBlueprintDocument>
pub fn document(&self, doc_id: WidgetDocId) -> Option<&WidgetBlueprintDocument>
Returns an immutable reference to a loaded document.
Sourcepub fn document_mut(
&mut self,
doc_id: WidgetDocId,
) -> Option<&mut WidgetBlueprintDocument>
pub fn document_mut( &mut self, doc_id: WidgetDocId, ) -> Option<&mut WidgetBlueprintDocument>
Returns a mutable reference to a loaded document.
pub fn apply( &mut self, doc_id: WidgetDocId, command: BlueprintCommand, ) -> Result<BlueprintNodeId, WidgetDocError>
Sourcepub fn query_first_by_name(
&self,
doc_id: WidgetDocId,
name: &str,
) -> Option<BlueprintNodeId>
pub fn query_first_by_name( &self, doc_id: WidgetDocId, name: &str, ) -> Option<BlueprintNodeId>
Finds the first node with the given name.
pub fn query_all_by_name( &self, doc_id: WidgetDocId, name: &str, ) -> Vec<BlueprintNodeId> ⓘ
pub fn query_first_by_widget_path( &self, doc_id: WidgetDocId, widget_path: &str, name: Option<&str>, ) -> Option<BlueprintNodeId>
pub fn query_first<T>(
&self,
doc_id: WidgetDocId,
name: Option<&str>,
) -> Result<Option<BlueprintNodeId>, WidgetDocError>where
T: Widget + 'static,
pub fn style( &self, doc_id: WidgetDocId, node_id: BlueprintNodeId, ) -> Option<&WidgetStyle>
Sourcepub fn with_style_mut(
&mut self,
doc_id: WidgetDocId,
node_id: BlueprintNodeId,
update: impl FnOnce(&mut WidgetStyle),
) -> Result<(), WidgetDocError>
pub fn with_style_mut( &mut self, doc_id: WidgetDocId, node_id: BlueprintNodeId, update: impl FnOnce(&mut WidgetStyle), ) -> Result<(), WidgetDocError>
Mutates the inline WidgetStyle of a node.
Sourcepub fn read_widget<T>(
&self,
doc_id: WidgetDocId,
node_id: BlueprintNodeId,
) -> Result<T, WidgetDocError>
pub fn read_widget<T>( &self, doc_id: WidgetDocId, node_id: BlueprintNodeId, ) -> Result<T, WidgetDocError>
Reads a typed widget definition from the document layer.
Sourcepub fn with_widget_mut<T>(
&mut self,
doc_id: WidgetDocId,
node_id: BlueprintNodeId,
update: impl FnOnce(&mut T),
) -> Result<(), WidgetDocError>
pub fn with_widget_mut<T>( &mut self, doc_id: WidgetDocId, node_id: BlueprintNodeId, update: impl FnOnce(&mut T), ) -> Result<(), WidgetDocError>
Mutates a typed widget definition in the document layer.
Changes made here affect future spawns or a later Self::flush call.
Sourcepub fn with_named_widget_mut<T>(
&mut self,
doc_id: WidgetDocId,
name: Option<&str>,
update: impl FnOnce(&mut T),
) -> Result<BlueprintNodeId, WidgetDocError>
pub fn with_named_widget_mut<T>( &mut self, doc_id: WidgetDocId, name: Option<&str>, update: impl FnOnce(&mut T), ) -> Result<BlueprintNodeId, WidgetDocError>
Finds a widget by name, reads it as T, and lets you mutate it.
Sourcepub fn spawn(
&mut self,
doc_id: WidgetDocId,
parent: Entity,
) -> Result<WidgetDocInstanceId, WidgetDocError>
pub fn spawn( &mut self, doc_id: WidgetDocId, parent: Entity, ) -> Result<WidgetDocInstanceId, WidgetDocError>
Spawns a loaded document under parent.
pub fn spawn_with_theme( &mut self, doc_id: WidgetDocId, parent: Entity, theme: Option<Theme>, ) -> Result<WidgetDocInstanceId, WidgetDocError>
Sourcepub fn flush(
&mut self,
instance_id: WidgetDocInstanceId,
) -> Result<(), WidgetDocError>
pub fn flush( &mut self, instance_id: WidgetDocInstanceId, ) -> Result<(), WidgetDocError>
Re-applies a document instance after document-side mutations.
This despawns the current live roots for the instance and rebuilds them from the stored document.
pub fn despawn( &mut self, instance_id: WidgetDocInstanceId, ) -> Result<(), WidgetDocError>
pub fn doc_for_instance( &self, instance_id: WidgetDocInstanceId, ) -> Option<WidgetDocId>
pub fn entity( &self, instance_id: WidgetDocInstanceId, node_id: BlueprintNodeId, ) -> Option<Entity>
pub fn entity_by_name( &self, instance_id: WidgetDocInstanceId, name: &str, ) -> Option<Entity>
pub fn entity_of<T>(
&self,
instance_id: WidgetDocInstanceId,
name: Option<&str>,
) -> Result<Option<Entity>, WidgetDocError>where
T: Widget + 'static,
Sourcepub fn read_live_widget<T>(
&self,
instance_id: WidgetDocInstanceId,
node_id: BlueprintNodeId,
widgets: &WidgetDocLiveRef<'_, '_, T>,
) -> Result<T, WidgetDocError>
pub fn read_live_widget<T>( &self, instance_id: WidgetDocInstanceId, node_id: BlueprintNodeId, widgets: &WidgetDocLiveRef<'_, '_, T>, ) -> Result<T, WidgetDocError>
Reads a typed live widget component from an existing instance.
pub fn read_named_live_widget<T>( &self, instance_id: WidgetDocInstanceId, name: Option<&str>, widgets: &WidgetDocLiveRef<'_, '_, T>, ) -> Result<T, WidgetDocError>
Sourcepub fn with_live_widget_mut<T>(
&self,
instance_id: WidgetDocInstanceId,
node_id: BlueprintNodeId,
widgets: &mut WidgetDocLiveMut<'_, '_, T>,
update: impl FnOnce(&mut T),
) -> Result<(), WidgetDocError>
pub fn with_live_widget_mut<T>( &self, instance_id: WidgetDocInstanceId, node_id: BlueprintNodeId, widgets: &mut WidgetDocLiveMut<'_, '_, T>, update: impl FnOnce(&mut T), ) -> Result<(), WidgetDocError>
Mutates a typed live widget component without touching the stored document.
Sourcepub fn with_named_live_widget_mut<T>(
&self,
instance_id: WidgetDocInstanceId,
name: Option<&str>,
widgets: &mut WidgetDocLiveMut<'_, '_, T>,
update: impl FnOnce(&mut T),
) -> Result<BlueprintNodeId, WidgetDocError>
pub fn with_named_live_widget_mut<T>( &self, instance_id: WidgetDocInstanceId, name: Option<&str>, widgets: &mut WidgetDocLiveMut<'_, '_, T>, update: impl FnOnce(&mut T), ) -> Result<BlueprintNodeId, WidgetDocError>
Finds a live widget by name and mutates its component directly.
Trait Implementations§
Source§impl SystemParam for WidgetDocUtility<'_, '_>
impl SystemParam for WidgetDocUtility<'_, '_>
Source§type Item<'w, 's> = WidgetDocUtility<'w, 's>
type Item<'w, 's> = WidgetDocUtility<'w, 's>
Self, instantiated with new lifetimes. Read moreSource§fn init_access(
state: &Self::State,
system_meta: &mut SystemMeta,
component_access_set: &mut FilteredAccessSet,
world: &mut World,
)
fn init_access( state: &Self::State, system_meta: &mut SystemMeta, component_access_set: &mut FilteredAccessSet, world: &mut World, )
World access used by this SystemParamSource§fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
fn apply(state: &mut Self::State, system_meta: &SystemMeta, world: &mut World)
SystemParam’s state.
This is used to apply Commands during ApplyDeferred.Source§fn queue(
state: &mut Self::State,
system_meta: &SystemMeta,
world: DeferredWorld<'_>,
)
fn queue( state: &mut Self::State, system_meta: &SystemMeta, world: DeferredWorld<'_>, )
ApplyDeferred.Source§unsafe fn validate_param<'w, 's>(
state: &'s mut Self::State,
_system_meta: &SystemMeta,
_world: UnsafeWorldCell<'w>,
) -> Result<(), SystemParamValidationError>
unsafe fn validate_param<'w, 's>( state: &'s mut Self::State, _system_meta: &SystemMeta, _world: UnsafeWorldCell<'w>, ) -> Result<(), SystemParamValidationError>
Source§unsafe fn get_param<'w, 's>(
state: &'s mut Self::State,
system_meta: &SystemMeta,
world: UnsafeWorldCell<'w>,
change_tick: Tick,
) -> Self::Item<'w, 's>
unsafe fn get_param<'w, 's>( state: &'s mut Self::State, system_meta: &SystemMeta, world: UnsafeWorldCell<'w>, change_tick: Tick, ) -> Self::Item<'w, 's>
SystemParamFunction. Read moreimpl<'w, 's> ReadOnlySystemParam for WidgetDocUtility<'w, 's>where
Commands<'w, 's>: ReadOnlySystemParam,
ResMut<'w, WidgetDocStore>: ReadOnlySystemParam,
Res<'w, WidgetRegistry>: ReadOnlySystemParam,
Res<'w, InspectorEditorRegistry>: ReadOnlySystemParam,
Res<'w, InspectorControlRegistry>: ReadOnlySystemParam,
Option<Res<'w, Theme>>: ReadOnlySystemParam,
Auto Trait Implementations§
impl<'w, 's> Freeze for WidgetDocUtility<'w, 's>
impl<'w, 's> !RefUnwindSafe for WidgetDocUtility<'w, 's>
impl<'w, 's> Send for WidgetDocUtility<'w, 's>
impl<'w, 's> Sync for WidgetDocUtility<'w, 's>
impl<'w, 's> Unpin for WidgetDocUtility<'w, 's>
impl<'w, 's> UnsafeUnpin for WidgetDocUtility<'w, 's>
impl<'w, 's> !UnwindSafe for WidgetDocUtility<'w, 's>
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more