mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
unified naming for field fetching via reflection
- previous approach with `ComponentProvider` trait was quite misleading, it didn't return a "component" - it simply returned marked fieds - the new approach is more explicit - method names tells exactly what they do
This commit is contained in:
@@ -437,7 +437,7 @@ impl AssetPreviewGenerator for ModelPreview {
|
||||
.graph
|
||||
.pair_iter_mut()
|
||||
.filter(|(h, _)| *h != preview_camera)
|
||||
.filter_map(|(_, n)| n.component_mut::<Camera>())
|
||||
.filter_map(|(_, n)| n.self_or_field_mut::<Camera>())
|
||||
{
|
||||
camera.set_enabled(false);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ impl Control for Item {
|
||||
fn update(&mut self, _dt: f32, ui: &mut UserInterface) {
|
||||
if self.need_request_preview.get() {
|
||||
let parent_container_bounds = ui
|
||||
.find_up(self.parent, &mut |n| n.has_component::<ListView>())
|
||||
.find_up(self.parent, &mut |n| n.is_or_has_field::<ListView>())
|
||||
.map(|(_, node)| node.screen_bounds())
|
||||
.unwrap_or_default();
|
||||
|
||||
|
||||
@@ -191,7 +191,10 @@ pub struct AudioPanel {
|
||||
}
|
||||
|
||||
fn item_bus(item: Handle<UiNode>, ui: &UserInterface) -> Handle<AudioBus> {
|
||||
ui.node(item).query_component::<AudioBusView>().unwrap().bus
|
||||
ui.node(item)
|
||||
.self_or_field_ref::<AudioBusView>()
|
||||
.unwrap()
|
||||
.bus
|
||||
}
|
||||
|
||||
fn fetch_possible_parent_buses(
|
||||
@@ -427,7 +430,7 @@ impl AudioPanel {
|
||||
.user_interfaces
|
||||
.first()
|
||||
.node(message.destination())
|
||||
.query_component::<AudioBusView>()
|
||||
.self_or_field_ref::<AudioBusView>()
|
||||
.unwrap();
|
||||
|
||||
let child = audio_bus_view_ref.bus;
|
||||
@@ -545,7 +548,7 @@ impl AudioPanel {
|
||||
for audio_bus_view in ui[self.audio_buses].items() {
|
||||
let audio_bus_view_ref = ui
|
||||
.node(*audio_bus_view)
|
||||
.query_component::<AudioBusView>()
|
||||
.self_or_field_ref::<AudioBusView>()
|
||||
.unwrap();
|
||||
|
||||
ui.send_sync(
|
||||
|
||||
@@ -39,25 +39,25 @@ pub mod panel;
|
||||
pub trait CommandContext: Reflect {}
|
||||
|
||||
impl dyn CommandContext + '_ {
|
||||
pub fn component_ref<T>(&self) -> Option<&T>
|
||||
pub fn self_or_field_ref<T>(&self) -> Option<&T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
(self as &dyn Reflect).self_or_field_ref_of_type()
|
||||
(self as &dyn Reflect).self_or_field_ref()
|
||||
}
|
||||
|
||||
pub fn component_mut<T>(&mut self) -> Option<&mut T>
|
||||
pub fn self_or_field_mut<T>(&mut self) -> Option<&mut T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
(self as &mut dyn Reflect).self_or_field_mut_of_type()
|
||||
(self as &mut dyn Reflect).self_or_field_mut()
|
||||
}
|
||||
|
||||
pub fn get<T>(&self) -> &T
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
self.component_ref().unwrap_or_else(|| {
|
||||
self.self_or_field_ref().unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Unable to downcast command context to {} type",
|
||||
type_name::<T>()
|
||||
@@ -69,7 +69,7 @@ impl dyn CommandContext + '_ {
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
self.component_mut().unwrap_or_else(|| {
|
||||
self.self_or_field_mut().unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Unable to downcast command context to {} type",
|
||||
type_name::<T>()
|
||||
|
||||
+2
-2
@@ -226,7 +226,7 @@ impl MeshControlPanel {
|
||||
} else if message.destination() == self.add_convex_collider {
|
||||
for (mesh_handle, _) in meshes_iter(selection, scene) {
|
||||
if let Some((ancestor_rigid_body, _)) =
|
||||
scene.graph.find_component_up::<RigidBody>(mesh_handle)
|
||||
scene.graph.find_self_or_field_up::<RigidBody>(mesh_handle)
|
||||
{
|
||||
let collider =
|
||||
ColliderBuilder::new(BaseBuilder::new().with_name("ConvexCollider"))
|
||||
@@ -244,7 +244,7 @@ impl MeshControlPanel {
|
||||
} else if message.destination() == self.add_trimesh_collider {
|
||||
for (mesh_handle, _) in meshes_iter(selection, scene) {
|
||||
if let Some((ancestor_rigid_body, _)) =
|
||||
scene.graph.find_component_up::<RigidBody>(mesh_handle)
|
||||
scene.graph.find_self_or_field_up::<RigidBody>(mesh_handle)
|
||||
{
|
||||
let collider =
|
||||
ColliderBuilder::new(BaseBuilder::new().with_name("TrimeshCollider"))
|
||||
|
||||
@@ -163,7 +163,7 @@ impl AbsmCanvas {
|
||||
for &child in self
|
||||
.children()
|
||||
.iter()
|
||||
.filter(|n| ui.node(**n).query_component::<Selectable>().is_some())
|
||||
.filter(|n| ui.node(**n).self_or_field_ref::<Selectable>().is_some())
|
||||
{
|
||||
ui.send_handled(
|
||||
child,
|
||||
@@ -198,16 +198,16 @@ impl AbsmCanvas {
|
||||
if ui
|
||||
.try_get_node(node_handle)
|
||||
.ok()
|
||||
.is_some_and(|n| n.has_component::<T>())
|
||||
.is_some_and(|n| n.is_or_has_field::<T>())
|
||||
{
|
||||
return node_handle;
|
||||
}
|
||||
|
||||
if node_handle == self.handle() {
|
||||
self.find_by_criteria_up(ui, |n| n.has_component::<T>())
|
||||
self.find_by_criteria_up(ui, |n| n.is_or_has_field::<T>())
|
||||
} else {
|
||||
ui.node(node_handle)
|
||||
.find_by_criteria_up(ui, |n| n.has_component::<T>())
|
||||
.find_by_criteria_up(ui, |n| n.is_or_has_field::<T>())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ impl AbsmCanvas {
|
||||
for connection in self
|
||||
.children()
|
||||
.iter()
|
||||
.filter_map(|c| ui.node(*c).query_component::<Connection>())
|
||||
.filter_map(|c| ui.node(*c).self_or_field_ref::<Connection>())
|
||||
{
|
||||
if connection.source_node == moved_node || force {
|
||||
let source_pos = self
|
||||
@@ -241,7 +241,7 @@ impl AbsmCanvas {
|
||||
for transition in self
|
||||
.children()
|
||||
.iter()
|
||||
.filter_map(|c| ui.node(*c).query_component::<TransitionView>())
|
||||
.filter_map(|c| ui.node(*c).self_or_field_ref::<TransitionView>())
|
||||
{
|
||||
if force
|
||||
|| moved_node == transition.segment.source
|
||||
@@ -253,7 +253,7 @@ impl AbsmCanvas {
|
||||
.iter()
|
||||
.filter_map(|c| {
|
||||
ui.node(*c)
|
||||
.query_component::<TransitionView>()
|
||||
.self_or_field_ref::<TransitionView>()
|
||||
.and_then(|t| {
|
||||
if t.segment.source == transition.segment.source
|
||||
&& t.segment.dest == transition.segment.dest
|
||||
@@ -474,11 +474,11 @@ impl Control for AbsmCanvas {
|
||||
|
||||
if dest_socket_handle.is_some() {
|
||||
let source_socket_ref =
|
||||
ui.node(source).query_component::<Socket>().unwrap();
|
||||
ui.node(source).self_or_field_ref::<Socket>().unwrap();
|
||||
|
||||
let dest_socket_ref = ui
|
||||
.node(dest_socket_handle)
|
||||
.query_component::<Socket>()
|
||||
.self_or_field_ref::<Socket>()
|
||||
.unwrap();
|
||||
|
||||
// Do not allow to create connections between sockets of the same node.
|
||||
@@ -572,7 +572,7 @@ impl Control for AbsmCanvas {
|
||||
if message.direction() == MessageDirection::FromWidget {
|
||||
let socket_ref = ui
|
||||
.node(message.destination())
|
||||
.query_component::<Socket>()
|
||||
.self_or_field_ref::<Socket>()
|
||||
.unwrap();
|
||||
|
||||
ui.send(
|
||||
@@ -587,7 +587,7 @@ impl Control for AbsmCanvas {
|
||||
} else if let Some(WidgetMessage::DesiredPosition(_)) = message.data() {
|
||||
if ui
|
||||
.node(message.destination())
|
||||
.has_component::<AbsmBaseNode>()
|
||||
.is_or_has_field::<AbsmBaseNode>()
|
||||
{
|
||||
let moved_node = message.destination();
|
||||
self.sync_connections_ends(moved_node, ui, false);
|
||||
|
||||
@@ -195,17 +195,17 @@ pub fn fetch_machine<N: Reflect>(
|
||||
// with Polonius.
|
||||
let context2 = unsafe { &mut *(context as *mut dyn CommandContext) };
|
||||
|
||||
if let Some(game_scene) = context.component_mut::<GameSceneContext>() {
|
||||
if let Some(game_scene) = context.self_or_field_mut::<GameSceneContext>() {
|
||||
game_scene
|
||||
.scene
|
||||
.graph
|
||||
.node_mut(ErasedHandle::from(node_handle).into())
|
||||
.component_mut::<InheritableVariable<Machine<Handle<N>>>>()
|
||||
.self_or_field_mut::<InheritableVariable<Machine<Handle<N>>>>()
|
||||
.unwrap()
|
||||
} else if let Some(ui) = context2.component_mut::<UiSceneContext>() {
|
||||
} else if let Some(ui) = context2.self_or_field_mut::<UiSceneContext>() {
|
||||
ui.ui
|
||||
.node_mut(ErasedHandle::from(node_handle).into())
|
||||
.component_mut::<InheritableVariable<Machine<Handle<N>>>>()
|
||||
.self_or_field_mut::<InheritableVariable<Machine<Handle<N>>>>()
|
||||
.unwrap()
|
||||
} else {
|
||||
panic!("Unsupported container!")
|
||||
|
||||
@@ -141,7 +141,7 @@ where
|
||||
graph
|
||||
.try_get_node_mut(handle)
|
||||
.ok()
|
||||
.and_then(|n| n.component_mut::<InheritableVariable<Machine<Handle<N>>>>())
|
||||
.and_then(|n| n.self_or_field_mut::<InheritableVariable<Machine<Handle<N>>>>())
|
||||
.map(|v| v.get_value_mut_silent())
|
||||
}
|
||||
|
||||
@@ -156,13 +156,13 @@ where
|
||||
let animation_player_handle = *graph
|
||||
.try_get_node(handle)
|
||||
.ok()
|
||||
.and_then(|n| n.component_ref::<InheritableVariable<Handle<N>>>())
|
||||
.and_then(|n| n.self_or_field_ref::<InheritableVariable<Handle<N>>>())
|
||||
.cloned()?;
|
||||
|
||||
graph
|
||||
.try_get_node_mut(animation_player_handle)
|
||||
.ok()
|
||||
.and_then(|n| n.component_mut::<InheritableVariable<AnimationContainer<Handle<N>>>>())
|
||||
.and_then(|n| n.self_or_field_mut::<InheritableVariable<AnimationContainer<Handle<N>>>>())
|
||||
.map(|ac| (animation_player_handle, ac.get_value_mut_silent()))
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ where
|
||||
graph
|
||||
.try_get_node(handle)
|
||||
.ok()
|
||||
.and_then(|n| n.component_ref::<InheritableVariable<Machine<Handle<N>>>>())
|
||||
.and_then(|n| n.self_or_field_ref::<InheritableVariable<Machine<Handle<N>>>>())
|
||||
.map(|v| v.get_value_ref())
|
||||
}
|
||||
|
||||
@@ -189,13 +189,13 @@ where
|
||||
graph
|
||||
.try_get_node(handle)
|
||||
.ok()
|
||||
.and_then(|n| n.component_ref::<InheritableVariable<Handle<N>>>())
|
||||
.and_then(|n| n.self_or_field_ref::<InheritableVariable<Handle<N>>>())
|
||||
.and_then(|ap| {
|
||||
graph
|
||||
.try_get_node(**ap)
|
||||
.ok()
|
||||
.and_then(|n| {
|
||||
n.component_ref::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
n.self_or_field_ref::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
})
|
||||
.map(|ac| (**ap, &**ac))
|
||||
})
|
||||
@@ -655,7 +655,7 @@ impl AbsmEditor {
|
||||
AbsmNodeMessage::Enter => {
|
||||
if let Some(node) = ui
|
||||
.node(message.destination())
|
||||
.query_component::<AbsmNode<State<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<State<Handle<N>>>>()
|
||||
{
|
||||
if let Some(layer_index) = selection.layer {
|
||||
self.state_viewer.set_state(
|
||||
@@ -671,7 +671,7 @@ impl AbsmEditor {
|
||||
AbsmNodeMessage::Edit => {
|
||||
if let Some(node) = ui
|
||||
.node(message.destination())
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
{
|
||||
if let Some(layer_index) = selection.layer {
|
||||
let model_ref =
|
||||
@@ -686,7 +686,7 @@ impl AbsmEditor {
|
||||
AbsmNodeMessage::AddInput => {
|
||||
if let Some(node) = ui
|
||||
.node(message.destination())
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
{
|
||||
if let Some(layer_index) = selection.layer {
|
||||
let model_ref =
|
||||
|
||||
@@ -144,12 +144,12 @@ pub fn get_machine_ref<'a, N: Reflect>(
|
||||
scene_container[game_scene.scene]
|
||||
.graph
|
||||
.node(ErasedHandle::from(node_handle).into())
|
||||
.component_ref::<InheritableVariable<Machine<Handle<N>>>>()
|
||||
.self_or_field_ref::<InheritableVariable<Machine<Handle<N>>>>()
|
||||
.map(|v| v.deref())
|
||||
} else if let Some(ui) = controller.downcast_ref::<UiScene>() {
|
||||
ui.ui
|
||||
.node(ErasedHandle::from(node_handle).into())
|
||||
.component_ref::<InheritableVariable<Machine<Handle<N>>>>()
|
||||
.self_or_field_ref::<InheritableVariable<Machine<Handle<N>>>>()
|
||||
.map(|v| v.deref())
|
||||
} else {
|
||||
None
|
||||
|
||||
@@ -334,7 +334,7 @@ impl NodeContextMenu {
|
||||
layer: layer_index,
|
||||
entry: ui
|
||||
.node(self.placement_target)
|
||||
.query_component::<AbsmNode<State<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<State<Handle<N>>>>()
|
||||
.unwrap()
|
||||
.model_handle,
|
||||
});
|
||||
@@ -346,7 +346,7 @@ impl NodeContextMenu {
|
||||
.children()
|
||||
.iter()
|
||||
.cloned()
|
||||
.filter(|c| ui.node(*c).has_component::<AbsmNode<State<Handle<N>>>>())
|
||||
.filter(|c| ui.node(*c).is_or_has_field::<AbsmNode<State<Handle<N>>>>())
|
||||
.collect::<Vec<_>>();
|
||||
ui.post(
|
||||
self.canvas,
|
||||
@@ -418,7 +418,7 @@ impl TransitionContextMenu {
|
||||
|
||||
let transition_ref = ui
|
||||
.node(self.placement_target)
|
||||
.query_component::<TransitionView>()
|
||||
.self_or_field_ref::<TransitionView>()
|
||||
.unwrap();
|
||||
|
||||
let group = vec![
|
||||
|
||||
@@ -73,7 +73,7 @@ where
|
||||
N: Reflect,
|
||||
{
|
||||
ui.node(handle)
|
||||
.query_component::<AbsmNode<State<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<State<Handle<N>>>>()
|
||||
.unwrap()
|
||||
.model_handle
|
||||
}
|
||||
@@ -134,7 +134,7 @@ impl StateGraphViewer {
|
||||
{
|
||||
if let Some(view_handle) = ui[self.canvas].children().iter().cloned().find(|c| {
|
||||
ui.node(*c)
|
||||
.query_component::<TransitionView>()
|
||||
.self_or_field_ref::<TransitionView>()
|
||||
.is_some_and(|transition_view_ref| {
|
||||
transition
|
||||
== Handle::<Transition<Handle<N>>>::from(transition_view_ref.model_handle)
|
||||
@@ -151,7 +151,7 @@ impl StateGraphViewer {
|
||||
for (state_view_handle, state_view_ref) in
|
||||
ui[self.canvas].children().iter().cloned().filter_map(|c| {
|
||||
ui.node(c)
|
||||
.query_component::<AbsmNode<State<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<State<Handle<N>>>>()
|
||||
.map(|state_view_ref| (c, state_view_ref))
|
||||
})
|
||||
{
|
||||
@@ -222,11 +222,11 @@ impl StateGraphViewer {
|
||||
let node_ref = ui.node(*n);
|
||||
|
||||
if let Some(state_node) =
|
||||
node_ref.query_component::<AbsmNode<State<Handle<N>>>>()
|
||||
node_ref.self_or_field_ref::<AbsmNode<State<Handle<N>>>>()
|
||||
{
|
||||
Some(SelectedEntity::State(state_node.model_handle))
|
||||
} else {
|
||||
node_ref.query_component::<TransitionView>().map(
|
||||
node_ref.self_or_field_ref::<TransitionView>().map(
|
||||
|state_node| {
|
||||
SelectedEntity::Transition(
|
||||
state_node.model_handle.into(),
|
||||
@@ -319,7 +319,7 @@ impl StateGraphViewer {
|
||||
.children()
|
||||
.iter()
|
||||
.cloned()
|
||||
.filter(|c| ui.node(*c).has_component::<AbsmNode<State<Handle<N>>>>())
|
||||
.filter(|c| ui.node(*c).is_or_has_field::<AbsmNode<State<Handle<N>>>>())
|
||||
.map(|c| c.to_variant::<AbsmNode<State<Handle<N>>>>())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@@ -327,7 +327,7 @@ impl StateGraphViewer {
|
||||
.children()
|
||||
.iter()
|
||||
.cloned()
|
||||
.filter(|c| ui.node(*c).has_component::<TransitionView>())
|
||||
.filter(|c| ui.node(*c).is_or_has_field::<TransitionView>())
|
||||
.map(|c| c.to_variant::<TransitionView>())
|
||||
.collect::<Vec<_>>();
|
||||
}
|
||||
|
||||
@@ -304,7 +304,7 @@ impl NodeContextMenu {
|
||||
} else if message.destination() == self.set_as_root {
|
||||
let root = ui
|
||||
.node(self.placement_target)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.unwrap()
|
||||
.model_handle;
|
||||
|
||||
@@ -373,12 +373,12 @@ impl ConnectionContextMenu {
|
||||
if message.destination == self.remove {
|
||||
let connection_ref = ui
|
||||
.node(self.placement_target)
|
||||
.query_component::<Connection>()
|
||||
.self_or_field_ref::<Connection>()
|
||||
.unwrap();
|
||||
|
||||
let dest_node_ref = ui
|
||||
.node(connection_ref.dest_node)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.unwrap();
|
||||
|
||||
let index = dest_node_ref
|
||||
|
||||
@@ -108,7 +108,7 @@ fn fetch_pose_node_model_handle<N: Reflect>(
|
||||
ui: &UserInterface,
|
||||
) -> Handle<PoseNode<Handle<N>>> {
|
||||
ui.node(handle)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.unwrap()
|
||||
.model_handle
|
||||
}
|
||||
@@ -118,7 +118,7 @@ fn fetch_socket_pose_node_model_handle<N: Reflect>(
|
||||
ui: &UserInterface,
|
||||
) -> Handle<PoseNode<Handle<N>>> {
|
||||
ui.node(handle)
|
||||
.query_component::<Socket>()
|
||||
.self_or_field_ref::<Socket>()
|
||||
.unwrap()
|
||||
.parent_node
|
||||
.into()
|
||||
@@ -318,7 +318,7 @@ impl StateViewer {
|
||||
let node_ref = ui.node(*n);
|
||||
|
||||
node_ref
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.map(|state_node| {
|
||||
SelectedEntity::PoseNode(state_node.model_handle)
|
||||
})
|
||||
@@ -338,7 +338,7 @@ impl StateViewer {
|
||||
fetch_socket_pose_node_model_handle(*source_socket, ui);
|
||||
|
||||
let dest_socket_ref =
|
||||
ui.node(*dest_socket).query_component::<Socket>().unwrap();
|
||||
ui.node(*dest_socket).self_or_field_ref::<Socket>().unwrap();
|
||||
let dest_node = fetch_socket_pose_node_model_handle(*dest_socket, ui);
|
||||
|
||||
let dest_node_ref = &layer.nodes()[dest_node];
|
||||
@@ -437,7 +437,7 @@ impl StateViewer {
|
||||
.filter(|h| {
|
||||
if let Some(pose_node) = ui
|
||||
.node(*h)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
{
|
||||
if machine_layer
|
||||
.nodes()
|
||||
@@ -480,7 +480,7 @@ impl StateViewer {
|
||||
for &pose_definition in models.iter() {
|
||||
if views.iter().all(|v| {
|
||||
ui.node(*v)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.unwrap()
|
||||
.model_handle
|
||||
!= pose_definition
|
||||
@@ -556,7 +556,7 @@ impl StateViewer {
|
||||
for &view in views.clone().iter() {
|
||||
let view_ref = ui
|
||||
.node(view)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.unwrap();
|
||||
|
||||
if machine_layer
|
||||
@@ -578,7 +578,7 @@ impl StateViewer {
|
||||
for &view in &views {
|
||||
let view_ref = ui
|
||||
.node(view)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.unwrap();
|
||||
let model_handle = view_ref.model_handle;
|
||||
let model_ref = &machine_layer.nodes()[model_handle];
|
||||
@@ -631,7 +631,7 @@ impl StateViewer {
|
||||
// for connection we can't find which connection has changed and sync only it, instead we
|
||||
// removing every connection and create new.
|
||||
for child in ui[self.canvas].children().iter().cloned() {
|
||||
if ui.node(child).has_component::<Connection>() {
|
||||
if ui.node(child).is_or_has_field::<Connection>() {
|
||||
ui.send_sync(child, WidgetMessage::Remove);
|
||||
}
|
||||
}
|
||||
@@ -641,7 +641,7 @@ impl StateViewer {
|
||||
.iter()
|
||||
.filter_map(|v| {
|
||||
ui.node(*v)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
})
|
||||
.find(|v| v.model_handle == model)
|
||||
.unwrap();
|
||||
@@ -658,7 +658,7 @@ impl StateViewer {
|
||||
.iter()
|
||||
.filter_map(|v| {
|
||||
ui.node(*v)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
})
|
||||
.find(|v| v.model_handle == child)
|
||||
.unwrap();
|
||||
@@ -690,7 +690,7 @@ impl StateViewer {
|
||||
}
|
||||
SelectedEntity::PoseNode(pose_node) => views.iter().cloned().find(|s| {
|
||||
ui.node(*s)
|
||||
.query_component::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.self_or_field_ref::<AbsmNode<PoseNode<Handle<N>>>>()
|
||||
.unwrap()
|
||||
.model_handle
|
||||
== *pose_node
|
||||
|
||||
@@ -55,17 +55,17 @@ pub fn fetch_animations_container<N: Reflect>(
|
||||
// with Polonius.
|
||||
let context2 = unsafe { &mut *(context as *mut dyn CommandContext) };
|
||||
|
||||
if let Some(game_scene) = context.component_mut::<GameSceneContext>() {
|
||||
if let Some(game_scene) = context.self_or_field_mut::<GameSceneContext>() {
|
||||
game_scene
|
||||
.scene
|
||||
.graph
|
||||
.node_mut(ErasedHandle::from(handle).into())
|
||||
.component_mut::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
.self_or_field_mut::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
.unwrap()
|
||||
} else if let Some(ui) = context2.component_mut::<UiSceneContext>() {
|
||||
} else if let Some(ui) = context2.self_or_field_mut::<UiSceneContext>() {
|
||||
ui.ui
|
||||
.node_mut(ErasedHandle::from(handle).into())
|
||||
.component_mut::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
.self_or_field_mut::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
.unwrap()
|
||||
} else {
|
||||
panic!("Unsupported container!")
|
||||
|
||||
@@ -213,7 +213,7 @@ where
|
||||
graph
|
||||
.try_get_node_mut(handle)
|
||||
.ok()
|
||||
.and_then(|n| n.component_mut::<InheritableVariable<AnimationContainer<Handle<N>>>>())
|
||||
.and_then(|n| n.self_or_field_mut::<InheritableVariable<AnimationContainer<Handle<N>>>>())
|
||||
.map(|v| v.get_value_mut_silent())
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ where
|
||||
.ok()
|
||||
.and_then(|n| {
|
||||
(n as &dyn Reflect)
|
||||
.first_field_ref_of_type::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
.first_field_ref::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
})
|
||||
.map(|v| v.get_value_ref())
|
||||
}
|
||||
@@ -485,7 +485,7 @@ impl AnimationEditor {
|
||||
|
||||
// HACK. This is unreliable to just use `bool` here. It should be wrapped into
|
||||
// newtype or something.
|
||||
if let Some(auto_apply) = animation_player_node.component_mut::<bool>() {
|
||||
if let Some(auto_apply) = animation_player_node.self_or_field_mut::<bool>() {
|
||||
*auto_apply = true;
|
||||
} else {
|
||||
Log::warn("No `auto_apply` component in animation player!")
|
||||
|
||||
@@ -104,11 +104,11 @@ pub fn get_animations_container<'a, N: Reflect>(
|
||||
scenes[game_scene.scene]
|
||||
.graph
|
||||
.node(ErasedHandle::from(handle).into())
|
||||
.component_ref::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
.self_or_field_ref::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
} else if let Some(ui) = controller.downcast_ref::<UiScene>() {
|
||||
ui.ui
|
||||
.node(ErasedHandle::from(handle).into())
|
||||
.component_ref::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
.self_or_field_ref::<InheritableVariable<AnimationContainer<Handle<N>>>>()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -999,8 +999,8 @@ impl TrackList {
|
||||
{
|
||||
let filter_text = text.to_lowercase();
|
||||
utils::apply_visibility_filter(self.tree_root.to_base(), ui, |node| {
|
||||
if let Some(tree) = node.query_component::<Tree>() {
|
||||
if let Some(tree_text) = ui.node(tree.content).query_component::<Text>() {
|
||||
if let Some(tree) = node.self_or_field_ref::<Tree>() {
|
||||
if let Some(tree_text) = ui.node(tree.content).self_or_field_ref::<Text>() {
|
||||
return Some(tree_text.text().to_lowercase().contains(&filter_text));
|
||||
}
|
||||
}
|
||||
@@ -1152,7 +1152,7 @@ impl TrackList {
|
||||
.iter()
|
||||
.filter_map(|s| {
|
||||
let selected_widget = ui.node(s.to_base());
|
||||
if let Some(track_data) = selected_widget.query_component::<TrackView>() {
|
||||
if let Some(track_data) = selected_widget.self_or_field_ref::<TrackView>() {
|
||||
Some(SelectedEntity::Track(track_data.id))
|
||||
} else if let Some(curve_data) =
|
||||
selected_widget.user_data_cloned::<CurveViewData>()
|
||||
@@ -1250,7 +1250,7 @@ impl TrackList {
|
||||
if let Some(animation) = selected_animation {
|
||||
if let Some(track_view_ref) = ui
|
||||
.node(message.destination())
|
||||
.query_component::<TrackView>()
|
||||
.self_or_field_ref::<TrackView>()
|
||||
{
|
||||
if animation.track_bindings().contains_key(&track_view_ref.id) {
|
||||
sender.do_command(SetTrackEnabledCommand {
|
||||
|
||||
@@ -404,15 +404,16 @@ impl InteractionMode for ColliderShapeInteractionMode {
|
||||
.unwrap_or_default();
|
||||
let collider_node = &scene.graph[self.collider];
|
||||
|
||||
let initial_shape = if let Some(collider) = collider_node.component_ref::<Collider>() {
|
||||
ColliderInitialShape::ThreeD(collider.shape().clone())
|
||||
} else if let Some(collider_2d) =
|
||||
collider_node.component_ref::<dim2::collider::Collider>()
|
||||
{
|
||||
ColliderInitialShape::TwoD(collider_2d.shape().clone())
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
let initial_shape =
|
||||
if let Some(collider) = collider_node.self_or_field_ref::<Collider>() {
|
||||
ColliderInitialShape::ThreeD(collider.shape().clone())
|
||||
} else if let Some(collider_2d) =
|
||||
collider_node.self_or_field_ref::<dim2::collider::Collider>()
|
||||
{
|
||||
ColliderInitialShape::TwoD(collider_2d.shape().clone())
|
||||
} else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
let handle = result.node.to_variant();
|
||||
if let Some(handle_value) =
|
||||
|
||||
@@ -253,7 +253,7 @@ impl SettingsWindow {
|
||||
// matching search criteria.
|
||||
let mut inner_match = false;
|
||||
let sub_inspector = ui.find_handle(entry.property_editor, &mut |node| {
|
||||
node.has_component::<Inspector>()
|
||||
node.is_or_has_field::<Inspector>()
|
||||
});
|
||||
if sub_inspector.is_some() {
|
||||
inner_match |= apply_recursive(filter_text, sub_inspector, ui);
|
||||
|
||||
@@ -607,7 +607,7 @@ impl TileMapEditorPlugin {
|
||||
let game_scene = entry.controller.downcast_mut::<GameScene>()?;
|
||||
let scene = &mut editor.engine.scenes[game_scene.scene];
|
||||
let node = scene.graph.try_get_node_mut(self.tile_map).ok()?;
|
||||
node.component_mut::<TileMap>()
|
||||
node.self_or_field_mut::<TileMap>()
|
||||
}
|
||||
fn open_panel_for_tile_set(
|
||||
&mut self,
|
||||
@@ -895,7 +895,7 @@ impl EditorPlugin for TileMapEditorPlugin {
|
||||
.graph
|
||||
.try_get_node_mut(self.tile_map)
|
||||
.ok()
|
||||
.and_then(|n| n.component_mut::<TileMap>())
|
||||
.and_then(|n| n.self_or_field_mut::<TileMap>())
|
||||
{
|
||||
tile_map.before_effects.clear();
|
||||
tile_map.after_effects.clear();
|
||||
|
||||
@@ -353,21 +353,21 @@ impl GameScene {
|
||||
if settings.debugging.show_tbn {
|
||||
node.debug_draw(ctx);
|
||||
}
|
||||
} else if node.component_ref::<Camera>().is_some() {
|
||||
} else if node.self_or_field_ref::<Camera>().is_some() {
|
||||
if settings.debugging.show_camera_bounds {
|
||||
node.debug_draw(ctx);
|
||||
}
|
||||
} else if node.component_ref::<PointLight>().is_some()
|
||||
|| node.component_ref::<SpotLight>().is_some()
|
||||
} else if node.self_or_field_ref::<PointLight>().is_some()
|
||||
|| node.self_or_field_ref::<SpotLight>().is_some()
|
||||
{
|
||||
if settings.debugging.show_light_bounds {
|
||||
node.debug_draw(ctx);
|
||||
}
|
||||
} else if node.component_ref::<Terrain>().is_some() {
|
||||
} else if node.self_or_field_ref::<Terrain>().is_some() {
|
||||
if settings.debugging.show_terrains {
|
||||
node.debug_draw(ctx);
|
||||
}
|
||||
} else if let Some(navmesh) = node.component_ref::<NavigationalMesh>() {
|
||||
} else if let Some(navmesh) = node.self_or_field_ref::<NavigationalMesh>() {
|
||||
if settings.navmesh.draw_all {
|
||||
let selection = editor_selection.as_navmesh();
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ fn apply_filter_recursive(node: Handle<UiNode>, filter: &str, ui: &UserInterface
|
||||
}
|
||||
|
||||
if let Some(data) = node_ref
|
||||
.query_component::<Tree>()
|
||||
.self_or_field_ref::<Tree>()
|
||||
.and_then(|n| n.user_data_cloned::<PropertyDescriptorData>())
|
||||
{
|
||||
is_any_match |= data.name.to_lowercase().contains(filter);
|
||||
@@ -319,7 +319,7 @@ impl PropertySelector {
|
||||
while let Some(node_handle) = stack.pop() {
|
||||
let node = ui.node(node_handle);
|
||||
|
||||
if let Some(tree) = node.query_component::<Tree>() {
|
||||
if let Some(tree) = node.self_or_field_ref::<Tree>() {
|
||||
if self.selected_property_paths.iter().any(|path| {
|
||||
path.path
|
||||
== tree
|
||||
|
||||
@@ -231,7 +231,7 @@ fn apply_filter_recursive(node: Handle<UiNode>, filter: &str, ui: &UserInterface
|
||||
}
|
||||
|
||||
if let Some(data) = node_ref
|
||||
.query_component::<Tree>()
|
||||
.self_or_field_ref::<Tree>()
|
||||
.and_then(|n| n.user_data_cloned::<TreeData>())
|
||||
{
|
||||
is_any_match |= data.name.to_lowercase().contains(filter);
|
||||
@@ -314,7 +314,7 @@ impl NodeSelector {
|
||||
while let Some(node_handle) = stack.pop() {
|
||||
let node = ui.node(node_handle);
|
||||
|
||||
if let Some(tree) = node.query_component::<Tree>() {
|
||||
if let Some(tree) = node.self_or_field_ref::<Tree>() {
|
||||
if self.selected.iter().any(|selected| {
|
||||
let tree_data = tree.user_data_cloned::<TreeData>().unwrap();
|
||||
tree_data.handle == selected.handle
|
||||
|
||||
@@ -722,7 +722,7 @@ impl WorldViewer {
|
||||
} else if let Some(TreeMessage::Expand { expand, .. }) = message.data() {
|
||||
if let Some(scene_view_item) = ui
|
||||
.node(message.destination())
|
||||
.query_component::<SceneItem>()
|
||||
.self_or_field_ref::<SceneItem>()
|
||||
{
|
||||
if let Some(path) = data_provider.path() {
|
||||
settings
|
||||
|
||||
@@ -449,7 +449,7 @@ pub enum PoolError {
|
||||
InvalidGeneration(u32),
|
||||
InvalidType(ErasedHandle),
|
||||
Empty(ErasedHandle),
|
||||
NoSuchComponent(ErasedHandle),
|
||||
NoSuchField(ErasedHandle),
|
||||
MutablyBorrowed(ErasedHandle),
|
||||
ImmutablyBorrowed(ErasedHandle),
|
||||
UnknownDependentObject(ErasedHandle),
|
||||
@@ -489,7 +489,7 @@ impl Display for PoolError {
|
||||
is invalid!"
|
||||
)
|
||||
}
|
||||
Self::NoSuchComponent(handle) => write!(
|
||||
Self::NoSuchField(handle) => write!(
|
||||
f,
|
||||
"An object at {handle} handle does not have such component.",
|
||||
),
|
||||
@@ -1427,30 +1427,27 @@ where
|
||||
{
|
||||
/// Tries to mutably borrow an object and fetch its component of specified type.
|
||||
#[inline]
|
||||
pub fn try_get_component_of_type<C>(&self, handle: Handle<T>) -> Result<&C, PoolError>
|
||||
pub fn try_get_or_field_ref<C>(&self, handle: Handle<T>) -> Result<&C, PoolError>
|
||||
where
|
||||
C: Reflect,
|
||||
{
|
||||
self.try_borrow(handle).and_then(|n| {
|
||||
(n as &dyn Reflect)
|
||||
.self_or_field_ref_of_type::<C>()
|
||||
.ok_or(PoolError::NoSuchComponent(handle.into()))
|
||||
.self_or_field_ref::<C>()
|
||||
.ok_or(PoolError::NoSuchField(handle.into()))
|
||||
})
|
||||
}
|
||||
|
||||
/// Tries to mutably borrow an object and fetch its component of specified type.
|
||||
#[inline]
|
||||
pub fn try_get_component_of_type_mut<C>(
|
||||
&mut self,
|
||||
handle: Handle<T>,
|
||||
) -> Result<&mut C, PoolError>
|
||||
pub fn try_get_or_field_mut<C>(&mut self, handle: Handle<T>) -> Result<&mut C, PoolError>
|
||||
where
|
||||
C: Reflect,
|
||||
{
|
||||
self.try_borrow_mut(handle).and_then(|n| {
|
||||
(n as &mut dyn Reflect)
|
||||
.self_or_field_mut_of_type::<C>()
|
||||
.ok_or(PoolError::NoSuchComponent(handle.into()))
|
||||
.self_or_field_mut::<C>()
|
||||
.ok_or(PoolError::NoSuchField(handle.into()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ where
|
||||
{
|
||||
/// Tries to mutably borrow an object and fetch its component of specified type.
|
||||
#[inline]
|
||||
pub fn try_get_component_of_type<'b: 'a, C>(
|
||||
pub fn try_get_or_field_ref<'b: 'a, C>(
|
||||
&'b self,
|
||||
handle: Handle<T>,
|
||||
) -> Result<Ref<'a, 'b, C>, PoolError>
|
||||
@@ -342,14 +342,14 @@ where
|
||||
{
|
||||
self.try_get_internal(handle, move |obj| {
|
||||
(obj as &dyn Reflect)
|
||||
.self_or_field_ref_of_type::<C>()
|
||||
.ok_or(PoolError::NoSuchComponent(handle.into()))
|
||||
.self_or_field_ref::<C>()
|
||||
.ok_or(PoolError::NoSuchField(handle.into()))
|
||||
})
|
||||
}
|
||||
|
||||
/// Tries to mutably borrow an object and fetch its component of specified type.
|
||||
#[inline]
|
||||
pub fn try_get_component_of_type_mut<'b: 'a, C>(
|
||||
pub fn try_get_or_field_mut<'b: 'a, C>(
|
||||
&'b self,
|
||||
handle: Handle<T>,
|
||||
) -> Result<RefMut<'a, 'b, C>, PoolError>
|
||||
@@ -358,8 +358,8 @@ where
|
||||
{
|
||||
self.try_get_mut_internal(handle, move |obj| {
|
||||
(obj as &mut dyn Reflect)
|
||||
.self_or_field_mut_of_type::<C>()
|
||||
.ok_or(PoolError::NoSuchComponent(handle.into()))
|
||||
.self_or_field_mut::<C>()
|
||||
.ok_or(PoolError::NoSuchField(handle.into()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ impl dyn Reflect {
|
||||
/// Tries to find the first field of the given type. This method internally uses
|
||||
/// [`Reflect::field_direct_ref`] with all of its limitations.
|
||||
#[inline]
|
||||
pub fn first_field_ref_of_type<T: Reflect>(&self) -> Option<&T> {
|
||||
pub fn first_field_ref<T: Reflect>(&self) -> Option<&T> {
|
||||
let count = self.as_reflect_direct().fields_count();
|
||||
|
||||
for i in 0..count {
|
||||
@@ -341,7 +341,7 @@ impl dyn Reflect {
|
||||
/// Tries to find the first field of the given type. This method internally uses
|
||||
/// [`Reflect::field_direct_ref`] with all of its limitations.
|
||||
#[inline]
|
||||
pub fn first_field_mut_of_type<T: Reflect>(&mut self) -> Option<&mut T> {
|
||||
pub fn first_field_mut<T: Reflect>(&mut self) -> Option<&mut T> {
|
||||
let count = self.as_reflect_direct().fields_count();
|
||||
|
||||
for i in 0..count {
|
||||
@@ -363,23 +363,23 @@ impl dyn Reflect {
|
||||
|
||||
/// Tries to downcast self to the specified type, or if it is not possible, tries to find a
|
||||
/// field of the specified type.
|
||||
pub fn self_or_field_ref_of_type<T: Reflect>(&self) -> Option<&T> {
|
||||
pub fn self_or_field_ref<T: Reflect>(&self) -> Option<&T> {
|
||||
if let Some(value) = (self.as_reflect_direct() as &dyn Any).downcast_ref::<T>() {
|
||||
Some(value)
|
||||
} else {
|
||||
self.first_field_ref_of_type()
|
||||
self.first_field_ref()
|
||||
}
|
||||
}
|
||||
|
||||
/// Tries to downcast self to the specified type, or if it is not possible, tries to find a
|
||||
/// field of the specified type.
|
||||
pub fn self_or_field_mut_of_type<T: Reflect>(&mut self) -> Option<&mut T> {
|
||||
pub fn self_or_field_mut<T: Reflect>(&mut self) -> Option<&mut T> {
|
||||
// SAFETY: See the comment in `first_field_mut_of_type` method.
|
||||
let this = unsafe { &mut *(self as *mut Self) };
|
||||
if let Some(value) = (self.as_reflect_mut_direct() as &mut dyn Any).downcast_mut::<T>() {
|
||||
Some(value)
|
||||
} else {
|
||||
this.first_field_mut_of_type()
|
||||
this.first_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1100,9 +1100,7 @@ mod test {
|
||||
assert_eq!(foo.fields_count(), 5);
|
||||
|
||||
assert_eq!(
|
||||
(&foo as &dyn Reflect)
|
||||
.first_field_ref_of_type::<f32>()
|
||||
.unwrap(),
|
||||
(&foo as &dyn Reflect).first_field_ref::<f32>().unwrap(),
|
||||
&baz
|
||||
);
|
||||
}
|
||||
|
||||
+14
-14
@@ -629,20 +629,20 @@ pub trait SceneGraphNode: Reflect + NameProvider + Clone + 'static {
|
||||
|
||||
/// Tries to borrow a component of given type.
|
||||
#[inline]
|
||||
fn component_ref<T: Reflect>(&self) -> Option<&T> {
|
||||
(self as &dyn Reflect).self_or_field_ref_of_type::<T>()
|
||||
fn self_or_field_ref<T: Reflect>(&self) -> Option<&T> {
|
||||
(self as &dyn Reflect).self_or_field_ref::<T>()
|
||||
}
|
||||
|
||||
/// Tries to borrow a component of given type.
|
||||
#[inline]
|
||||
fn component_mut<T: Reflect>(&mut self) -> Option<&mut T> {
|
||||
(self as &mut dyn Reflect).self_or_field_mut_of_type::<T>()
|
||||
fn self_or_field_mut<T: Reflect>(&mut self) -> Option<&mut T> {
|
||||
(self as &mut dyn Reflect).self_or_field_mut::<T>()
|
||||
}
|
||||
|
||||
/// Checks if the node has a component of given type.
|
||||
#[inline]
|
||||
fn has_component<T: Reflect>(&self) -> bool {
|
||||
self.component_ref::<T>().is_some()
|
||||
fn is_or_has_field<T: Reflect>(&self) -> bool {
|
||||
self.self_or_field_ref::<T>().is_some()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -886,8 +886,8 @@ pub trait SceneGraph: 'static {
|
||||
{
|
||||
self.try_get_node(handle).and_then(|n| {
|
||||
(n as &dyn Reflect)
|
||||
.self_or_field_ref_of_type()
|
||||
.ok_or(PoolError::NoSuchComponent(handle.into()))
|
||||
.self_or_field_ref()
|
||||
.ok_or(PoolError::NoSuchField(handle.into()))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -899,8 +899,8 @@ pub trait SceneGraph: 'static {
|
||||
{
|
||||
self.try_get_node_mut(handle).and_then(|n| {
|
||||
(n as &mut dyn Reflect)
|
||||
.self_or_field_mut_of_type()
|
||||
.ok_or(PoolError::NoSuchComponent(handle.into()))
|
||||
.self_or_field_mut()
|
||||
.ok_or(PoolError::NoSuchField(handle.into()))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -974,7 +974,7 @@ pub trait SceneGraph: 'static {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn find_component_up<T>(
|
||||
fn find_self_or_field_up<T>(
|
||||
&self,
|
||||
node_handle: Handle<impl ObjectOrVariant<Self::Node>>,
|
||||
) -> Option<(Handle<Self::Node>, &T)>
|
||||
@@ -982,12 +982,12 @@ pub trait SceneGraph: 'static {
|
||||
T: Reflect,
|
||||
{
|
||||
self.find_up_map(node_handle, &mut |node| {
|
||||
(node as &dyn Reflect).self_or_field_ref_of_type::<T>()
|
||||
(node as &dyn Reflect).self_or_field_ref::<T>()
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn find_component<T>(
|
||||
fn find_self_or_field<T>(
|
||||
&self,
|
||||
node_handle: Handle<impl ObjectOrVariant<Self::Node>>,
|
||||
) -> Option<(Handle<Self::Node>, &T)>
|
||||
@@ -995,7 +995,7 @@ pub trait SceneGraph: 'static {
|
||||
T: Reflect,
|
||||
{
|
||||
self.find_map(node_handle, &mut |node| {
|
||||
(node as &dyn Reflect).self_or_field_ref_of_type::<T>()
|
||||
(node as &dyn Reflect).self_or_field_ref::<T>()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -912,7 +912,7 @@ impl RenderDataBundleStorage {
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(reflection_probe) = node.component_ref::<ReflectionProbe>() {
|
||||
if let Some(reflection_probe) = node.self_or_field_ref::<ReflectionProbe>() {
|
||||
if (reflection_probe as &dyn NodeTrait)
|
||||
.world_bounding_box()
|
||||
.is_contains_point(observer_position.translation)
|
||||
@@ -922,7 +922,7 @@ impl RenderDataBundleStorage {
|
||||
}
|
||||
|
||||
if options.collect_lights {
|
||||
if let Some(base_light) = node.component_ref::<BaseLight>() {
|
||||
if let Some(base_light) = node.self_or_field_ref::<BaseLight>() {
|
||||
if frustum.is_intersects_aabb(&node.world_bounding_box())
|
||||
&& base_light.global_visibility()
|
||||
&& base_light.is_globally_enabled()
|
||||
|
||||
@@ -243,7 +243,7 @@ pub trait AnimationSource {
|
||||
let model_graph = self.inner_graph();
|
||||
for src_node_ref in model_graph.linear_iter() {
|
||||
if let Some(src_animations) = src_node_ref
|
||||
.component_ref::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
|
||||
.self_or_field_ref::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
|
||||
{
|
||||
for src_anim in src_animations.iter() {
|
||||
let mut anim_copy = src_anim.clone();
|
||||
@@ -316,7 +316,7 @@ pub trait AnimationSource {
|
||||
|
||||
let dest_animations = graph
|
||||
.node_mut(dest_animation_player)
|
||||
.component_mut::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
|
||||
.self_or_field_mut::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
|
||||
.unwrap();
|
||||
|
||||
for animation in animations {
|
||||
@@ -340,7 +340,7 @@ pub trait AnimationSource {
|
||||
self_kind: ResourceKind,
|
||||
) -> Vec<Handle<fyrox_animation::Animation<Handle<Self::Node>>>> {
|
||||
if let Some((animation_player, _)) = graph.find(root, &mut |n| {
|
||||
n.component_ref::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
|
||||
n.self_or_field_ref::<InheritableVariable<AnimationContainer<Handle<Self::Node>>>>()
|
||||
.is_some()
|
||||
}) {
|
||||
self.retarget_animations_to_player(root, animation_player, graph, self_kind)
|
||||
|
||||
@@ -1003,7 +1003,7 @@ impl Base {
|
||||
{
|
||||
self.scripts
|
||||
.iter()
|
||||
.find_map(|s| s.as_ref().and_then(|s| s.query_component_ref::<C>()))
|
||||
.find_map(|s| s.as_ref().and_then(|s| s.self_or_field_ref::<C>()))
|
||||
}
|
||||
|
||||
/// Tries find a component of the given type `C` across **all** available scripts of the node.
|
||||
@@ -1016,7 +1016,7 @@ impl Base {
|
||||
{
|
||||
self.scripts
|
||||
.iter_mut()
|
||||
.find_map(|s| s.as_mut().and_then(|s| s.query_component_mut::<C>()))
|
||||
.find_map(|s| s.as_mut().and_then(|s| s.self_or_field_mut::<C>()))
|
||||
}
|
||||
|
||||
/// Returns total count of scripts assigned to the node.
|
||||
|
||||
@@ -371,7 +371,7 @@ fn tile_map_to_collider_shape(
|
||||
let tile_map = nodes
|
||||
.try_borrow(tile_map.0)
|
||||
.ok()?
|
||||
.component_ref::<TileMap>()?;
|
||||
.self_or_field_ref::<TileMap>()?;
|
||||
|
||||
let tile_set_resource = tile_map.tile_set()?.data_ref();
|
||||
let tile_set = tile_set_resource.as_loaded_ref()?;
|
||||
@@ -842,7 +842,10 @@ impl PhysicsWorld {
|
||||
let h = Handle::decode_from_u128(self.colliders.get(handle).unwrap().user_data);
|
||||
pred(
|
||||
h,
|
||||
graph.node(h).component_ref::<collider::Collider>().unwrap(),
|
||||
graph
|
||||
.node(h)
|
||||
.self_or_field_ref::<collider::Collider>()
|
||||
.unwrap(),
|
||||
)
|
||||
} else {
|
||||
true
|
||||
@@ -1180,7 +1183,7 @@ impl PhysicsWorld {
|
||||
}
|
||||
}
|
||||
} else if let Ok(parent_body) =
|
||||
nodes.try_get_component_of_type::<dim2::rigidbody::RigidBody>(collider_node.parent())
|
||||
nodes.try_get_or_field_ref::<dim2::rigidbody::RigidBody>(collider_node.parent())
|
||||
{
|
||||
if parent_body.native.get() != RigidBodyHandle::invalid() {
|
||||
let rigid_body_native = parent_body.native.get();
|
||||
|
||||
@@ -525,7 +525,7 @@ fn make_trimesh(
|
||||
let root_inv_transform = owner_inv_transform;
|
||||
|
||||
for &source in sources {
|
||||
if let Ok(mesh) = nodes.try_get_component_of_type::<Mesh>(source.0) {
|
||||
if let Ok(mesh) = nodes.try_get_or_field_ref::<Mesh>(source.0) {
|
||||
let global_transform = root_inv_transform * mesh.global_transform();
|
||||
|
||||
for surface in mesh.surfaces() {
|
||||
@@ -810,11 +810,11 @@ fn collider_shape_into_native_shape(
|
||||
}
|
||||
}
|
||||
ColliderShape::Heightfield(heightfield) => pool
|
||||
.try_get_component_of_type::<Terrain>(heightfield.geometry_source.0)
|
||||
.try_get_or_field_ref::<Terrain>(heightfield.geometry_source.0)
|
||||
.ok()
|
||||
.and_then(make_heightfield),
|
||||
ColliderShape::Polyhedron(polyhedron) => pool
|
||||
.try_get_component_of_type::<Mesh>(polyhedron.geometry_source.0)
|
||||
.try_get_or_field_ref::<Mesh>(polyhedron.geometry_source.0)
|
||||
.ok()
|
||||
.map(|mesh| make_polyhedron_shape(owner_inv_global_transform, mesh)),
|
||||
}
|
||||
@@ -1300,7 +1300,10 @@ impl PhysicsWorld {
|
||||
let h = Handle::decode_from_u128(self.colliders.get(handle).unwrap().user_data);
|
||||
pred(
|
||||
h,
|
||||
graph.node(h).component_ref::<collider::Collider>().unwrap(),
|
||||
graph
|
||||
.node(h)
|
||||
.self_or_field_ref::<collider::Collider>()
|
||||
.unwrap(),
|
||||
)
|
||||
} else {
|
||||
true
|
||||
@@ -1712,7 +1715,7 @@ impl PhysicsWorld {
|
||||
}
|
||||
}
|
||||
} else if let Ok(parent_body) =
|
||||
nodes.try_get_component_of_type::<scene::rigidbody::RigidBody>(collider_node.parent())
|
||||
nodes.try_get_or_field_ref::<scene::rigidbody::RigidBody>(collider_node.parent())
|
||||
{
|
||||
if parent_body.native.get() != RigidBodyHandle::invalid() {
|
||||
let inv_global_transform = isometric_global_transform(nodes, handle)
|
||||
|
||||
@@ -269,11 +269,11 @@ pub trait NodeTrait: BaseNodeTrait + Reflect + Visit {
|
||||
// See ObjectOrVariantHelper for the cause of the indirection.
|
||||
impl<T: NodeTrait> ObjectOrVariantHelper<Node, T> for PhantomData<T> {
|
||||
fn convert_to_dest_type_helper(node: &Node) -> Option<&T> {
|
||||
(node.0.deref() as &dyn Reflect).self_or_field_ref_of_type()
|
||||
(node.0.deref() as &dyn Reflect).self_or_field_ref()
|
||||
}
|
||||
|
||||
fn convert_to_dest_type_helper_mut(node: &mut Node) -> Option<&mut T> {
|
||||
(node.0.deref_mut() as &mut dyn Reflect).self_or_field_mut_of_type()
|
||||
(node.0.deref_mut() as &mut dyn Reflect).self_or_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -187,9 +187,7 @@ impl NodeTrait for Ragdoll {
|
||||
|
||||
if *self.deactivate_colliders {
|
||||
for child in limb_body.children() {
|
||||
if let Ok(mut collider) =
|
||||
mbc.try_get_component_of_type_mut::<Collider>(*child)
|
||||
{
|
||||
if let Ok(mut collider) = mbc.try_get_or_field_mut::<Collider>(*child) {
|
||||
collider.set_is_sensor(false);
|
||||
}
|
||||
}
|
||||
@@ -226,9 +224,7 @@ impl NodeTrait for Ragdoll {
|
||||
|
||||
if *self.deactivate_colliders {
|
||||
for child in limb_body.children() {
|
||||
if let Ok(mut collider) =
|
||||
mbc.try_get_component_of_type_mut::<Collider>(*child)
|
||||
{
|
||||
if let Ok(mut collider) = mbc.try_get_or_field_mut::<Collider>(*child) {
|
||||
collider.set_is_sensor(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -924,14 +924,14 @@ impl Script {
|
||||
|
||||
/// Tries to borrow a component of given type.
|
||||
#[inline]
|
||||
pub fn query_component_ref<T: Reflect>(&self) -> Option<&T> {
|
||||
(self.instance.deref() as &dyn Reflect).self_or_field_ref_of_type()
|
||||
pub fn self_or_field_ref<T: Reflect>(&self) -> Option<&T> {
|
||||
(self.instance.deref() as &dyn Reflect).self_or_field_ref()
|
||||
}
|
||||
|
||||
/// Tries to borrow a component of given type.
|
||||
#[inline]
|
||||
pub fn query_component_mut<T: Reflect>(&mut self) -> Option<&mut T> {
|
||||
(self.instance.deref_mut() as &mut dyn Reflect).self_or_field_mut_of_type()
|
||||
pub fn self_or_field_mut<T: Reflect>(&mut self) -> Option<&mut T> {
|
||||
(self.instance.deref_mut() as &mut dyn Reflect).self_or_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ impl Control for AnimationBlendingStateMachine {
|
||||
fn update(&mut self, dt: f32, ui: &mut UserInterface) {
|
||||
if let Ok(animation_player) = ui
|
||||
.nodes
|
||||
.try_get_component_of_type_mut::<AnimationPlayer>(*self.animation_player)
|
||||
.try_get_or_field_mut::<AnimationPlayer>(*self.animation_player)
|
||||
{
|
||||
// Prevent animation player to apply animation to scene nodes. The animation will
|
||||
// do than instead.
|
||||
|
||||
@@ -272,7 +272,7 @@ impl Control for ColorGradientEditor {
|
||||
for (handle, pt) in ui[self.points_canvas]
|
||||
.children()
|
||||
.iter()
|
||||
.map(|c| (*c, ui.node(*c).query_component::<ColorPoint>().unwrap()))
|
||||
.map(|c| (*c, ui.node(*c).self_or_field_ref::<ColorPoint>().unwrap()))
|
||||
{
|
||||
gradient.add_point(GradientPoint::new(
|
||||
pt.location,
|
||||
@@ -317,7 +317,7 @@ impl ColorGradientEditor {
|
||||
.children()
|
||||
.iter()
|
||||
.filter(|c| **c != exclude)
|
||||
.map(|c| ui.node(*c).query_component::<ColorPoint>().unwrap())
|
||||
.map(|c| ui.node(*c).self_or_field_ref::<ColorPoint>().unwrap())
|
||||
{
|
||||
gradient.add_point(GradientPoint::new(pt.location, pt.color()));
|
||||
}
|
||||
@@ -616,7 +616,7 @@ impl Control for ColorPointsCanvas {
|
||||
fn arrange_override(&self, ui: &UserInterface, final_size: Vector2<f32>) -> Vector2<f32> {
|
||||
for &child in self.children() {
|
||||
let child_ref = ui.node(child);
|
||||
if let Some(color_point) = child_ref.query_component::<ColorPoint>() {
|
||||
if let Some(color_point) = child_ref.self_or_field_ref::<ColorPoint>() {
|
||||
let x_pos = final_size.x * color_point.location - child_ref.desired_size().x * 0.5;
|
||||
|
||||
ui.arrange_node(
|
||||
|
||||
@@ -456,10 +456,10 @@ pub trait Control: BaseControl + Deref<Target = Widget> + DerefMut + Reflect + V
|
||||
// See ObjectOrVariantHelper for the cause of the indirection.
|
||||
impl<T: Control> ObjectOrVariantHelper<UiNode, T> for PhantomData<T> {
|
||||
fn convert_to_dest_type_helper(node: &UiNode) -> Option<&T> {
|
||||
(node.0.deref() as &dyn Reflect).self_or_field_ref_of_type()
|
||||
(node.0.deref() as &dyn Reflect).self_or_field_ref()
|
||||
}
|
||||
|
||||
fn convert_to_dest_type_helper_mut(node: &mut UiNode) -> Option<&mut T> {
|
||||
(node.0.deref_mut() as &mut dyn Reflect).self_or_field_mut_of_type()
|
||||
(node.0.deref_mut() as &mut dyn Reflect).self_or_field_mut()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ fn find_window(
|
||||
|
||||
let window_handle = ui
|
||||
.find_handle(ui.root(), &mut |n| {
|
||||
n.has_component::<Window>() && n.name == *window_name
|
||||
n.is_or_has_field::<Window>() && n.name == *window_name
|
||||
})
|
||||
.to_variant();
|
||||
|
||||
|
||||
@@ -300,7 +300,7 @@ impl DockingManager {
|
||||
|
||||
let floating_window = ui
|
||||
.find_handle(ui.root(), &mut |n| {
|
||||
n.has_component::<Window>() && n.name == floating_window_desc.name
|
||||
n.is_or_has_field::<Window>() && n.name == floating_window_desc.name
|
||||
})
|
||||
.to_variant();
|
||||
if floating_window.is_some() {
|
||||
|
||||
@@ -792,7 +792,7 @@ impl Control for Tile {
|
||||
}
|
||||
|
||||
if let Some((_, docking_manager)) =
|
||||
ui.find_component_up::<DockingManager>(self.parent())
|
||||
ui.find_self_or_field_up::<DockingManager>(self.parent())
|
||||
{
|
||||
docking_manager
|
||||
.floating_windows
|
||||
@@ -817,7 +817,7 @@ impl Control for Tile {
|
||||
fn preview_message(&self, ui: &UserInterface, message: &mut UiMessage) {
|
||||
if let Some(msg) = message.data::<WindowMessage>() {
|
||||
if let Some((_, docking_manager)) =
|
||||
ui.find_component_up::<DockingManager>(self.parent())
|
||||
ui.find_self_or_field_up::<DockingManager>(self.parent())
|
||||
{
|
||||
// Make sure we are dragging one of the floating windows of parent docking manager.
|
||||
if message.direction() == MessageDirection::FromWidget
|
||||
@@ -1077,7 +1077,9 @@ impl Tile {
|
||||
|
||||
send_size(ui, window.handle(), self.actual_local_size().x, height);
|
||||
|
||||
if let Some((_, docking_manager)) = ui.find_component_up::<DockingManager>(self.parent()) {
|
||||
if let Some((_, docking_manager)) =
|
||||
ui.find_self_or_field_up::<DockingManager>(self.parent())
|
||||
{
|
||||
docking_manager
|
||||
.floating_windows
|
||||
.borrow_mut()
|
||||
|
||||
@@ -186,7 +186,7 @@ pub fn build_tree<P: AsRef<Path>>(
|
||||
ui: &mut UserInterface,
|
||||
) -> Handle<Tree> {
|
||||
let subtree = build_tree_item(path, parent_path, menu, false, filter, &mut ui.build_ctx());
|
||||
if ui[parent].has_component::<TreeRoot>() {
|
||||
if ui[parent].is_or_has_field::<TreeRoot>() {
|
||||
ui.send(parent, TreeRootMessage::AddItem(subtree));
|
||||
} else {
|
||||
ui.send(parent, TreeMessage::AddItem(subtree));
|
||||
|
||||
@@ -346,7 +346,7 @@ impl FileBrowser {
|
||||
let parent_path = parent_path(path);
|
||||
let parent_tree = fs_tree::find_tree_item(self.tree_root, &parent_path, ui);
|
||||
if let Ok(parent_tree_node) = ui.try_get(parent_tree) {
|
||||
if parent_tree_node.has_component::<TreeRoot>() {
|
||||
if parent_tree_node.is_or_has_field::<TreeRoot>() {
|
||||
ui.send(
|
||||
parent_tree,
|
||||
TreeRootMessage::RemoveItem(tree_item.to_variant()),
|
||||
|
||||
@@ -97,7 +97,7 @@ fn write_test_tree(root: &Path) -> Vec<PathBuf> {
|
||||
fn count_tree_items(ui: &UserInterface) -> usize {
|
||||
let mut count = 0;
|
||||
for node in ui.nodes() {
|
||||
if node.has_component::<Tree>() {
|
||||
if node.is_or_has_field::<Tree>() {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
@@ -107,7 +107,7 @@ fn count_tree_items(ui: &UserInterface) -> usize {
|
||||
fn count_tree_roots(ui: &UserInterface) -> usize {
|
||||
let mut count = 0;
|
||||
for node in ui.nodes() {
|
||||
if node.has_component::<TreeRoot>() {
|
||||
if node.is_or_has_field::<TreeRoot>() {
|
||||
count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -564,7 +564,7 @@ where
|
||||
.with_target_type_id(TypeId::of::<T>())
|
||||
.with_style_resource(ctx.environment.as_ref().and_then(|env| {
|
||||
(&**env as &dyn Reflect)
|
||||
.first_field_ref_of_type::<Option<StyleResource>>()
|
||||
.first_field_ref::<Option<StyleResource>>()
|
||||
.cloned()
|
||||
.flatten()
|
||||
}))
|
||||
|
||||
+4
-1
@@ -80,7 +80,10 @@ impl ContextMenu {
|
||||
}
|
||||
|
||||
fn on_copy_clicked(&self, ui: &mut UserInterface) -> Option<()> {
|
||||
let text = ui.find_component::<Text>(self.placement_target)?.1.text();
|
||||
let text = ui
|
||||
.find_self_or_field::<Text>(self.placement_target)?
|
||||
.1
|
||||
.text();
|
||||
ui.clipboard_mut()?.set_contents(text).ok()
|
||||
}
|
||||
|
||||
|
||||
+16
-9
@@ -465,7 +465,7 @@ impl MenuItem {
|
||||
let mut menu_item_ref_container = Some(self);
|
||||
while let Some(menu_item_ref) = menu_item_ref_container {
|
||||
let popup_handle =
|
||||
menu_item_ref.find_by_criteria_up(ui, |n| n.has_component::<ContextMenu>());
|
||||
menu_item_ref.find_by_criteria_up(ui, |n| n.is_or_has_field::<ContextMenu>());
|
||||
|
||||
ui.send(
|
||||
menu_item_ref.handle,
|
||||
@@ -497,7 +497,7 @@ impl MenuItem {
|
||||
fn find_menu(from: Handle<UiNode>, ui: &UserInterface) -> Handle<UiNode> {
|
||||
let mut handle = from;
|
||||
while handle.is_some() {
|
||||
if let Some((_, panel)) = ui.find_component_up::<ContextMenu>(handle) {
|
||||
if let Some((_, panel)) = ui.find_self_or_field_up::<ContextMenu>(handle) {
|
||||
// Continue search from parent menu item of popup.
|
||||
handle = panel.parent_menu_item.to_base();
|
||||
} else {
|
||||
@@ -512,9 +512,9 @@ fn is_any_menu_item_contains_point(ui: &UserInterface, pt: Vector2<f32>) -> bool
|
||||
for (handle, menu) in ui
|
||||
.nodes()
|
||||
.pair_iter()
|
||||
.filter_map(|(h, n)| n.query_component::<MenuItem>().map(|menu| (h, menu)))
|
||||
.filter_map(|(h, n)| n.self_or_field_ref::<MenuItem>().map(|menu| (h, menu)))
|
||||
{
|
||||
if ui.find_component_up::<Menu>(handle).is_none()
|
||||
if ui.find_self_or_field_up::<Menu>(handle).is_none()
|
||||
&& menu.is_globally_visible()
|
||||
&& menu.screen_bounds().contains(pt)
|
||||
{
|
||||
@@ -633,7 +633,9 @@ impl Control for MenuItem {
|
||||
}
|
||||
}
|
||||
MenuItemMessage::Close { deselect } => {
|
||||
if let Some(panel) = ui.node(*self.items_panel).query_component::<ContextMenu>()
|
||||
if let Some(panel) = ui
|
||||
.node(*self.items_panel)
|
||||
.self_or_field_ref::<ContextMenu>()
|
||||
{
|
||||
if *panel.popup.is_open {
|
||||
ui.send(*self.items_panel, PopupMessage::Close);
|
||||
@@ -720,7 +722,7 @@ impl Control for MenuItem {
|
||||
break;
|
||||
} else {
|
||||
let node = ui.node(handle);
|
||||
if let Some(panel) = node.component_ref::<ContextMenu>() {
|
||||
if let Some(panel) = node.self_or_field_ref::<ContextMenu>() {
|
||||
// Once we found popup in chain, we must extract handle
|
||||
// of parent menu item to continue search.
|
||||
handle = panel.parent_menu_item.to_base();
|
||||
@@ -731,7 +733,9 @@ impl Control for MenuItem {
|
||||
}
|
||||
|
||||
if !found {
|
||||
if let Some(panel) = ui.node(*self.items_panel).query_component::<ContextMenu>()
|
||||
if let Some(panel) = ui
|
||||
.node(*self.items_panel)
|
||||
.self_or_field_ref::<ContextMenu>()
|
||||
{
|
||||
if *panel.popup.is_open {
|
||||
ui.send(self.handle(), MenuItemMessage::Close { deselect: true });
|
||||
@@ -751,7 +755,10 @@ impl Control for MenuItem {
|
||||
// Allow closing "orphaned" menus by clicking outside of them.
|
||||
if let OsEvent::MouseInput { state, .. } = event {
|
||||
if *state == ButtonState::Pressed {
|
||||
if let Some(panel) = ui.node(*self.items_panel).query_component::<ContextMenu>() {
|
||||
if let Some(panel) = ui
|
||||
.node(*self.items_panel)
|
||||
.self_or_field_ref::<ContextMenu>()
|
||||
{
|
||||
if *panel.popup.is_open {
|
||||
// Ensure that the cursor is outside any menus.
|
||||
if !is_any_menu_item_contains_point(ui, ui.cursor_position())
|
||||
@@ -1228,7 +1235,7 @@ fn keyboard_navigation(
|
||||
parent_menu_item_handle: Handle<MenuItem>,
|
||||
) -> bool {
|
||||
let Some(items_container) =
|
||||
(parent_menu_item as &dyn Reflect).self_or_field_ref_of_type::<ItemsContainer>()
|
||||
(parent_menu_item as &dyn Reflect).self_or_field_ref::<ItemsContainer>()
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
|
||||
@@ -142,7 +142,7 @@ impl Control for NavigationLayer {
|
||||
if *self.bring_into_view {
|
||||
// Find a parent scroll viewer.
|
||||
if let Some((scroll_viewer, _)) =
|
||||
ui.find_component_up::<ScrollViewer>(entry.handle)
|
||||
ui.find_self_or_field_up::<ScrollViewer>(entry.handle)
|
||||
{
|
||||
ui.send(
|
||||
scroll_viewer,
|
||||
|
||||
@@ -218,20 +218,20 @@ impl UiNode {
|
||||
/// top of existing one (via composition) and you have it as a field inside your widget. In this case, you
|
||||
/// can fetch it by using this method with the appropriate type. See docs for [`fyrox_core::type_traits::ComponentProvider::query_component_ref`]
|
||||
/// for more info.
|
||||
pub fn query_component<T>(&self) -> Option<&T>
|
||||
pub fn self_or_field_ref<T>(&self) -> Option<&T>
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
(self.0.deref() as &dyn Reflect).self_or_field_ref_of_type()
|
||||
(self.0.deref() as &dyn Reflect).self_or_field_ref()
|
||||
}
|
||||
|
||||
/// This method checks if the widget has a component of the given type `T`. Internally, it queries the component
|
||||
/// of the given type and checks if it exists.
|
||||
pub fn has_component<T>(&self) -> bool
|
||||
pub fn is_or_has_field<T>(&self) -> bool
|
||||
where
|
||||
T: Reflect,
|
||||
{
|
||||
self.query_component::<T>().is_some()
|
||||
self.self_or_field_ref::<T>().is_some()
|
||||
}
|
||||
|
||||
pub(crate) fn set_inheritance_data(
|
||||
|
||||
@@ -122,7 +122,7 @@ impl UserInterfaceTestingExtension for UserInterface {
|
||||
assert!(is_enabled(start_handle, self));
|
||||
assert!(start_node.is_globally_visible());
|
||||
if let Some((text_handle, text_node)) = self.find(start_handle, &mut |n| {
|
||||
if let Some(text_widget) = n.component_ref::<Text>() {
|
||||
if let Some(text_widget) = n.self_or_field_ref::<Text>() {
|
||||
text_widget.text() == text
|
||||
} else {
|
||||
false
|
||||
|
||||
@@ -369,7 +369,7 @@ impl Control for Tree {
|
||||
// Prevent selection changes by Alt+Click to be able to drag'n'drop tree items.
|
||||
if !keyboard_modifiers.alt {
|
||||
if let Some((tree_root_handle, tree_root)) =
|
||||
ui.find_component_up::<TreeRoot>(self.parent())
|
||||
ui.find_self_or_field_up::<TreeRoot>(self.parent())
|
||||
{
|
||||
let selection = if keyboard_modifiers.control {
|
||||
let mut selection = tree_root.selected.clone();
|
||||
@@ -411,7 +411,7 @@ impl Control for Tree {
|
||||
}
|
||||
}
|
||||
|
||||
if node.query_component::<Tree>().is_some() {
|
||||
if node.self_or_field_ref::<Tree>().is_some() {
|
||||
hierarchy.push(handle.to_variant());
|
||||
}
|
||||
|
||||
@@ -920,7 +920,7 @@ impl Control for TreeRoot {
|
||||
);
|
||||
message.set_handled(true);
|
||||
} else if let Some((parent_handle, _)) =
|
||||
ui.find_component_up::<Tree>(item.parent())
|
||||
ui.find_self_or_field_up::<Tree>(item.parent())
|
||||
{
|
||||
ui.send(
|
||||
self.handle,
|
||||
@@ -986,7 +986,7 @@ impl TreeRoot {
|
||||
}
|
||||
|
||||
let (parent_handle, parent_items, parent_ancestor, is_parent_root) = ui
|
||||
.find_component_up::<Tree>(item.parent())
|
||||
.find_self_or_field_up::<Tree>(item.parent())
|
||||
.map(|(tree_handle, tree)| {
|
||||
(
|
||||
tree_handle.to_variant::<Tree>(),
|
||||
@@ -1046,7 +1046,7 @@ impl TreeRoot {
|
||||
let mut current_ancestor = parent_handle;
|
||||
let mut current_ancestor_parent = parent_ancestor;
|
||||
while let Some((ancestor_handle, ancestor)) =
|
||||
ui.find_component_up::<Tree>(current_ancestor_parent)
|
||||
ui.find_self_or_field_up::<Tree>(current_ancestor_parent)
|
||||
{
|
||||
if ancestor.is_expanded {
|
||||
if let Some(current_ancestor_position) =
|
||||
|
||||
Reference in New Issue
Block a user