From 98dbd7fe83b5196fb034ad38014378726df60710 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 31 May 2024 10:47:53 +0200 Subject: [PATCH 1/6] Implement `DerefMut` for all generated tuple structs --- .../src/blueprint/components/active_tab.rs | 7 ++++++ .../blueprint/components/included_content.rs | 7 ++++++ .../components/lock_range_during_zoom.rs | 7 ++++++ .../blueprint/components/query_expression.rs | 7 ++++++ .../blueprint/components/space_view_class.rs | 7 ++++++ .../blueprint/components/space_view_origin.rs | 7 ++++++ .../components/viewer_recommendation_hash.rs | 7 ++++++ .../components/visible_time_range.rs | 7 ++++++ .../blueprint/components/visual_bounds2d.rs | 7 ++++++ crates/re_types/src/components/class_id.rs | 7 ++++++ crates/re_types/src/components/color.rs | 7 ++++++ .../re_types/src/components/half_sizes2d.rs | 7 ++++++ .../re_types/src/components/half_sizes3d.rs | 7 ++++++ crates/re_types/src/components/keypoint_id.rs | 7 ++++++ crates/re_types/src/components/material.rs | 7 ++++++ crates/re_types/src/components/media_type.rs | 7 ++++++ crates/re_types/src/components/name.rs | 7 ++++++ .../src/components/out_of_tree_transform3d.rs | 7 ++++++ .../src/components/pinhole_projection.rs | 7 ++++++ crates/re_types/src/components/position2d.rs | 7 ++++++ crates/re_types/src/components/position3d.rs | 7 ++++++ crates/re_types/src/components/range1d.rs | 7 ++++++ crates/re_types/src/components/resolution.rs | 7 ++++++ crates/re_types/src/components/rotation3d.rs | 7 ++++++ crates/re_types/src/components/tensor_data.rs | 7 ++++++ crates/re_types/src/components/texcoord2d.rs | 7 ++++++ crates/re_types/src/components/text.rs | 7 ++++++ .../re_types/src/components/text_log_level.rs | 7 ++++++ crates/re_types/src/components/transform3d.rs | 7 ++++++ .../src/components/triangle_indices.rs | 7 ++++++ crates/re_types/src/components/vector2d.rs | 7 ++++++ crates/re_types/src/components/vector3d.rs | 7 ++++++ crates/re_types/src/datatypes/material.rs | 7 ++++++ .../src/testing/components/affix_fuzzer1.rs | 7 ++++++ .../src/testing/components/affix_fuzzer14.rs | 7 ++++++ .../src/testing/components/affix_fuzzer15.rs | 7 ++++++ .../src/testing/components/affix_fuzzer19.rs | 7 ++++++ .../src/testing/components/affix_fuzzer2.rs | 7 ++++++ .../src/testing/components/affix_fuzzer20.rs | 7 ++++++ .../src/testing/components/affix_fuzzer21.rs | 7 ++++++ .../src/testing/components/affix_fuzzer22.rs | 7 ++++++ .../src/testing/components/affix_fuzzer3.rs | 7 ++++++ .../src/testing/components/affix_fuzzer4.rs | 7 ++++++ .../src/testing/components/affix_fuzzer5.rs | 7 ++++++ .../src/testing/components/affix_fuzzer6.rs | 7 ++++++ .../src/testing/datatypes/affix_fuzzer5.rs | 7 ++++++ .../components/included_space_view.rs | 7 ++++++ .../blueprint/components/root_container.rs | 7 ++++++ .../components/space_view_maximized.rs | 7 ++++++ .../re_types_builder/src/codegen/rust/api.rs | 24 +++++++++++-------- 50 files changed, 357 insertions(+), 10 deletions(-) diff --git a/crates/re_types/src/blueprint/components/active_tab.rs b/crates/re_types/src/blueprint/components/active_tab.rs index 29281d755d1e..0c3fef1b6169 100644 --- a/crates/re_types/src/blueprint/components/active_tab.rs +++ b/crates/re_types/src/blueprint/components/active_tab.rs @@ -65,6 +65,13 @@ impl std::ops::Deref for ActiveTab { } } +impl std::ops::DerefMut for ActiveTab { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::EntityPath { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(ActiveTab); impl ::re_types_core::Loggable for ActiveTab { diff --git a/crates/re_types/src/blueprint/components/included_content.rs b/crates/re_types/src/blueprint/components/included_content.rs index c4e0091af388..d46c9475f035 100644 --- a/crates/re_types/src/blueprint/components/included_content.rs +++ b/crates/re_types/src/blueprint/components/included_content.rs @@ -66,6 +66,13 @@ impl std::ops::Deref for IncludedContent { } } +impl std::ops::DerefMut for IncludedContent { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::EntityPath { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(IncludedContent); impl ::re_types_core::Loggable for IncludedContent { diff --git a/crates/re_types/src/blueprint/components/lock_range_during_zoom.rs b/crates/re_types/src/blueprint/components/lock_range_during_zoom.rs index d9aa2e2911c9..425ad3b6a112 100644 --- a/crates/re_types/src/blueprint/components/lock_range_during_zoom.rs +++ b/crates/re_types/src/blueprint/components/lock_range_during_zoom.rs @@ -63,6 +63,13 @@ impl std::ops::Deref for LockRangeDuringZoom { } } +impl std::ops::DerefMut for LockRangeDuringZoom { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Bool { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(LockRangeDuringZoom); impl ::re_types_core::Loggable for LockRangeDuringZoom { diff --git a/crates/re_types/src/blueprint/components/query_expression.rs b/crates/re_types/src/blueprint/components/query_expression.rs index dd94a9d85015..794db44ccc94 100644 --- a/crates/re_types/src/blueprint/components/query_expression.rs +++ b/crates/re_types/src/blueprint/components/query_expression.rs @@ -70,6 +70,13 @@ impl std::ops::Deref for QueryExpression { } } +impl std::ops::DerefMut for QueryExpression { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Utf8 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(QueryExpression); impl ::re_types_core::Loggable for QueryExpression { diff --git a/crates/re_types/src/blueprint/components/space_view_class.rs b/crates/re_types/src/blueprint/components/space_view_class.rs index 09d890c16aa0..855b3f5e3103 100644 --- a/crates/re_types/src/blueprint/components/space_view_class.rs +++ b/crates/re_types/src/blueprint/components/space_view_class.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for SpaceViewClass { } } +impl std::ops::DerefMut for SpaceViewClass { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Utf8 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(SpaceViewClass); impl ::re_types_core::Loggable for SpaceViewClass { diff --git a/crates/re_types/src/blueprint/components/space_view_origin.rs b/crates/re_types/src/blueprint/components/space_view_origin.rs index a075d47f5924..42ba62504c96 100644 --- a/crates/re_types/src/blueprint/components/space_view_origin.rs +++ b/crates/re_types/src/blueprint/components/space_view_origin.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for SpaceViewOrigin { } } +impl std::ops::DerefMut for SpaceViewOrigin { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::EntityPath { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(SpaceViewOrigin); impl ::re_types_core::Loggable for SpaceViewOrigin { diff --git a/crates/re_types/src/blueprint/components/viewer_recommendation_hash.rs b/crates/re_types/src/blueprint/components/viewer_recommendation_hash.rs index 05ea1bc6294e..4d221e29bf3d 100644 --- a/crates/re_types/src/blueprint/components/viewer_recommendation_hash.rs +++ b/crates/re_types/src/blueprint/components/viewer_recommendation_hash.rs @@ -63,6 +63,13 @@ impl std::ops::Deref for ViewerRecommendationHash { } } +impl std::ops::DerefMut for ViewerRecommendationHash { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::UInt64 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(ViewerRecommendationHash); impl ::re_types_core::Loggable for ViewerRecommendationHash { diff --git a/crates/re_types/src/blueprint/components/visible_time_range.rs b/crates/re_types/src/blueprint/components/visible_time_range.rs index 84a2f626472c..704751e59a95 100644 --- a/crates/re_types/src/blueprint/components/visible_time_range.rs +++ b/crates/re_types/src/blueprint/components/visible_time_range.rs @@ -63,6 +63,13 @@ impl std::ops::Deref for VisibleTimeRange { } } +impl std::ops::DerefMut for VisibleTimeRange { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::VisibleTimeRange { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(VisibleTimeRange); impl ::re_types_core::Loggable for VisibleTimeRange { diff --git a/crates/re_types/src/blueprint/components/visual_bounds2d.rs b/crates/re_types/src/blueprint/components/visual_bounds2d.rs index 6b22413abee2..ca3d94b42b7e 100644 --- a/crates/re_types/src/blueprint/components/visual_bounds2d.rs +++ b/crates/re_types/src/blueprint/components/visual_bounds2d.rs @@ -64,6 +64,13 @@ impl std::ops::Deref for VisualBounds2D { } } +impl std::ops::DerefMut for VisualBounds2D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Range2D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(VisualBounds2D); impl ::re_types_core::Loggable for VisualBounds2D { diff --git a/crates/re_types/src/components/class_id.rs b/crates/re_types/src/components/class_id.rs index 48eec481246a..93c3c1f36081 100644 --- a/crates/re_types/src/components/class_id.rs +++ b/crates/re_types/src/components/class_id.rs @@ -66,6 +66,13 @@ impl std::ops::Deref for ClassId { } } +impl std::ops::DerefMut for ClassId { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::ClassId { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(ClassId); impl ::re_types_core::Loggable for ClassId { diff --git a/crates/re_types/src/components/color.rs b/crates/re_types/src/components/color.rs index 1b812bb1e91b..3ef354754bb9 100644 --- a/crates/re_types/src/components/color.rs +++ b/crates/re_types/src/components/color.rs @@ -64,6 +64,13 @@ impl std::ops::Deref for Color { } } +impl std::ops::DerefMut for Color { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Rgba32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Color); impl ::re_types_core::Loggable for Color { diff --git a/crates/re_types/src/components/half_sizes2d.rs b/crates/re_types/src/components/half_sizes2d.rs index dbfc69998b93..83f524bdab9f 100644 --- a/crates/re_types/src/components/half_sizes2d.rs +++ b/crates/re_types/src/components/half_sizes2d.rs @@ -63,6 +63,13 @@ impl std::ops::Deref for HalfSizes2D { } } +impl std::ops::DerefMut for HalfSizes2D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Vec2D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(HalfSizes2D); impl ::re_types_core::Loggable for HalfSizes2D { diff --git a/crates/re_types/src/components/half_sizes3d.rs b/crates/re_types/src/components/half_sizes3d.rs index 156ceebaf741..e6a3d907f9e3 100644 --- a/crates/re_types/src/components/half_sizes3d.rs +++ b/crates/re_types/src/components/half_sizes3d.rs @@ -63,6 +63,13 @@ impl std::ops::Deref for HalfSizes3D { } } +impl std::ops::DerefMut for HalfSizes3D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Vec3D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(HalfSizes3D); impl ::re_types_core::Loggable for HalfSizes3D { diff --git a/crates/re_types/src/components/keypoint_id.rs b/crates/re_types/src/components/keypoint_id.rs index c1af5f331ed7..6848b2a6997c 100644 --- a/crates/re_types/src/components/keypoint_id.rs +++ b/crates/re_types/src/components/keypoint_id.rs @@ -78,6 +78,13 @@ impl std::ops::Deref for KeypointId { } } +impl std::ops::DerefMut for KeypointId { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::KeypointId { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(KeypointId); impl ::re_types_core::Loggable for KeypointId { diff --git a/crates/re_types/src/components/material.rs b/crates/re_types/src/components/material.rs index 82c6e8cbc7f1..246daaa8a48f 100644 --- a/crates/re_types/src/components/material.rs +++ b/crates/re_types/src/components/material.rs @@ -60,6 +60,13 @@ impl std::ops::Deref for Material { } } +impl std::ops::DerefMut for Material { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Material { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Material); impl ::re_types_core::Loggable for Material { diff --git a/crates/re_types/src/components/media_type.rs b/crates/re_types/src/components/media_type.rs index 2cd9fa2b7014..53ebb7a930b8 100644 --- a/crates/re_types/src/components/media_type.rs +++ b/crates/re_types/src/components/media_type.rs @@ -64,6 +64,13 @@ impl std::ops::Deref for MediaType { } } +impl std::ops::DerefMut for MediaType { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Utf8 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(MediaType); impl ::re_types_core::Loggable for MediaType { diff --git a/crates/re_types/src/components/name.rs b/crates/re_types/src/components/name.rs index d4251a58fae4..282b925d6aa2 100644 --- a/crates/re_types/src/components/name.rs +++ b/crates/re_types/src/components/name.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for Name { } } +impl std::ops::DerefMut for Name { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Utf8 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Name); impl ::re_types_core::Loggable for Name { diff --git a/crates/re_types/src/components/out_of_tree_transform3d.rs b/crates/re_types/src/components/out_of_tree_transform3d.rs index d514f8f4d769..ead94b2bd403 100644 --- a/crates/re_types/src/components/out_of_tree_transform3d.rs +++ b/crates/re_types/src/components/out_of_tree_transform3d.rs @@ -65,6 +65,13 @@ impl std::ops::Deref for OutOfTreeTransform3D { } } +impl std::ops::DerefMut for OutOfTreeTransform3D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Transform3D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(OutOfTreeTransform3D); impl ::re_types_core::Loggable for OutOfTreeTransform3D { diff --git a/crates/re_types/src/components/pinhole_projection.rs b/crates/re_types/src/components/pinhole_projection.rs index 9821ac5b9c38..67e7af4d70fa 100644 --- a/crates/re_types/src/components/pinhole_projection.rs +++ b/crates/re_types/src/components/pinhole_projection.rs @@ -70,6 +70,13 @@ impl std::ops::Deref for PinholeProjection { } } +impl std::ops::DerefMut for PinholeProjection { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Mat3x3 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(PinholeProjection); impl ::re_types_core::Loggable for PinholeProjection { diff --git a/crates/re_types/src/components/position2d.rs b/crates/re_types/src/components/position2d.rs index 4cf861d0b7be..199e656e2889 100644 --- a/crates/re_types/src/components/position2d.rs +++ b/crates/re_types/src/components/position2d.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for Position2D { } } +impl std::ops::DerefMut for Position2D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Vec2D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Position2D); impl ::re_types_core::Loggable for Position2D { diff --git a/crates/re_types/src/components/position3d.rs b/crates/re_types/src/components/position3d.rs index f64b1859d6e7..756ee3c82dff 100644 --- a/crates/re_types/src/components/position3d.rs +++ b/crates/re_types/src/components/position3d.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for Position3D { } } +impl std::ops::DerefMut for Position3D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Vec3D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Position3D); impl ::re_types_core::Loggable for Position3D { diff --git a/crates/re_types/src/components/range1d.rs b/crates/re_types/src/components/range1d.rs index c0e852a9f6ef..9bde67b5d82c 100644 --- a/crates/re_types/src/components/range1d.rs +++ b/crates/re_types/src/components/range1d.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for Range1D { } } +impl std::ops::DerefMut for Range1D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Range1D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Range1D); impl ::re_types_core::Loggable for Range1D { diff --git a/crates/re_types/src/components/resolution.rs b/crates/re_types/src/components/resolution.rs index 54a38aef5245..a0164c0d92f2 100644 --- a/crates/re_types/src/components/resolution.rs +++ b/crates/re_types/src/components/resolution.rs @@ -62,6 +62,13 @@ impl std::ops::Deref for Resolution { } } +impl std::ops::DerefMut for Resolution { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Vec2D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Resolution); impl ::re_types_core::Loggable for Resolution { diff --git a/crates/re_types/src/components/rotation3d.rs b/crates/re_types/src/components/rotation3d.rs index 2ff44b7f35a0..dccdeda307e2 100644 --- a/crates/re_types/src/components/rotation3d.rs +++ b/crates/re_types/src/components/rotation3d.rs @@ -63,6 +63,13 @@ impl std::ops::Deref for Rotation3D { } } +impl std::ops::DerefMut for Rotation3D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Rotation3D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Rotation3D); impl ::re_types_core::Loggable for Rotation3D { diff --git a/crates/re_types/src/components/tensor_data.rs b/crates/re_types/src/components/tensor_data.rs index 143b10476f2b..67c05148e23b 100644 --- a/crates/re_types/src/components/tensor_data.rs +++ b/crates/re_types/src/components/tensor_data.rs @@ -73,6 +73,13 @@ impl std::ops::Deref for TensorData { } } +impl std::ops::DerefMut for TensorData { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::TensorData { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(TensorData); impl ::re_types_core::Loggable for TensorData { diff --git a/crates/re_types/src/components/texcoord2d.rs b/crates/re_types/src/components/texcoord2d.rs index f23907899bfa..578e03bacbf4 100644 --- a/crates/re_types/src/components/texcoord2d.rs +++ b/crates/re_types/src/components/texcoord2d.rs @@ -76,6 +76,13 @@ impl std::ops::Deref for Texcoord2D { } } +impl std::ops::DerefMut for Texcoord2D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Vec2D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Texcoord2D); impl ::re_types_core::Loggable for Texcoord2D { diff --git a/crates/re_types/src/components/text.rs b/crates/re_types/src/components/text.rs index 1a6d11084e39..95c7c02b5b75 100644 --- a/crates/re_types/src/components/text.rs +++ b/crates/re_types/src/components/text.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for Text { } } +impl std::ops::DerefMut for Text { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Utf8 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Text); impl ::re_types_core::Loggable for Text { diff --git a/crates/re_types/src/components/text_log_level.rs b/crates/re_types/src/components/text_log_level.rs index 7c3cbe603524..b080e191fa83 100644 --- a/crates/re_types/src/components/text_log_level.rs +++ b/crates/re_types/src/components/text_log_level.rs @@ -69,6 +69,13 @@ impl std::ops::Deref for TextLogLevel { } } +impl std::ops::DerefMut for TextLogLevel { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Utf8 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(TextLogLevel); impl ::re_types_core::Loggable for TextLogLevel { diff --git a/crates/re_types/src/components/transform3d.rs b/crates/re_types/src/components/transform3d.rs index 7d349e266eba..75233ba41d49 100644 --- a/crates/re_types/src/components/transform3d.rs +++ b/crates/re_types/src/components/transform3d.rs @@ -63,6 +63,13 @@ impl std::ops::Deref for Transform3D { } } +impl std::ops::DerefMut for Transform3D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Transform3D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Transform3D); impl ::re_types_core::Loggable for Transform3D { diff --git a/crates/re_types/src/components/triangle_indices.rs b/crates/re_types/src/components/triangle_indices.rs index 1d7c18ebbd8c..e69b42b16a69 100644 --- a/crates/re_types/src/components/triangle_indices.rs +++ b/crates/re_types/src/components/triangle_indices.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for TriangleIndices { } } +impl std::ops::DerefMut for TriangleIndices { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::UVec3D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(TriangleIndices); impl ::re_types_core::Loggable for TriangleIndices { diff --git a/crates/re_types/src/components/vector2d.rs b/crates/re_types/src/components/vector2d.rs index 647c34ed2c06..33a3e9b67c91 100644 --- a/crates/re_types/src/components/vector2d.rs +++ b/crates/re_types/src/components/vector2d.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for Vector2D { } } +impl std::ops::DerefMut for Vector2D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Vec2D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Vector2D); impl ::re_types_core::Loggable for Vector2D { diff --git a/crates/re_types/src/components/vector3d.rs b/crates/re_types/src/components/vector3d.rs index e6091d2760ad..ed5d78f4fb83 100644 --- a/crates/re_types/src/components/vector3d.rs +++ b/crates/re_types/src/components/vector3d.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for Vector3D { } } +impl std::ops::DerefMut for Vector3D { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Vec3D { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Vector3D); impl ::re_types_core::Loggable for Vector3D { diff --git a/crates/re_types/src/datatypes/material.rs b/crates/re_types/src/datatypes/material.rs index 5974ac869516..fd6df2df1e50 100644 --- a/crates/re_types/src/datatypes/material.rs +++ b/crates/re_types/src/datatypes/material.rs @@ -65,6 +65,13 @@ impl std::ops::Deref for Material { } } +impl std::ops::DerefMut for Material { + #[inline] + fn deref_mut(&mut self) -> &mut Option { + &mut self.albedo_factor + } +} + ::re_types_core::macros::impl_into_cow!(Material); impl ::re_types_core::Loggable for Material { diff --git a/crates/re_types/src/testing/components/affix_fuzzer1.rs b/crates/re_types/src/testing/components/affix_fuzzer1.rs index 714d4f6d4898..1e1f8edbb23a 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer1.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer1.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer1 { } } +impl std::ops::DerefMut for AffixFuzzer1 { + #[inline] + fn deref_mut(&mut self) -> &mut crate::testing::datatypes::AffixFuzzer1 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer1); impl ::re_types_core::Loggable for AffixFuzzer1 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer14.rs b/crates/re_types/src/testing/components/affix_fuzzer14.rs index 036c14b8ef7a..ee04056c5b4f 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer14.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer14.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer14 { } } +impl std::ops::DerefMut for AffixFuzzer14 { + #[inline] + fn deref_mut(&mut self) -> &mut crate::testing::datatypes::AffixFuzzer3 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer14); impl ::re_types_core::Loggable for AffixFuzzer14 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer15.rs b/crates/re_types/src/testing/components/affix_fuzzer15.rs index ee87ce605fed..8f52eacb611a 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer15.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer15.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer15 { } } +impl std::ops::DerefMut for AffixFuzzer15 { + #[inline] + fn deref_mut(&mut self) -> &mut Option { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer15); impl ::re_types_core::Loggable for AffixFuzzer15 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer19.rs b/crates/re_types/src/testing/components/affix_fuzzer19.rs index b7c44187dbfa..4c5934bc97c2 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer19.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer19.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer19 { } } +impl std::ops::DerefMut for AffixFuzzer19 { + #[inline] + fn deref_mut(&mut self) -> &mut crate::testing::datatypes::AffixFuzzer5 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer19); impl ::re_types_core::Loggable for AffixFuzzer19 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer2.rs b/crates/re_types/src/testing/components/affix_fuzzer2.rs index b44b41aff46c..620673dee3bb 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer2.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer2.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer2 { } } +impl std::ops::DerefMut for AffixFuzzer2 { + #[inline] + fn deref_mut(&mut self) -> &mut crate::testing::datatypes::AffixFuzzer1 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer2); impl ::re_types_core::Loggable for AffixFuzzer2 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer20.rs b/crates/re_types/src/testing/components/affix_fuzzer20.rs index 1f6d39e0f301..0bc1ac32807c 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer20.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer20.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer20 { } } +impl std::ops::DerefMut for AffixFuzzer20 { + #[inline] + fn deref_mut(&mut self) -> &mut crate::testing::datatypes::AffixFuzzer20 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer20); impl ::re_types_core::Loggable for AffixFuzzer20 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer21.rs b/crates/re_types/src/testing/components/affix_fuzzer21.rs index 9b3d63727f65..e0bb5dbf4db1 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer21.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer21.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer21 { } } +impl std::ops::DerefMut for AffixFuzzer21 { + #[inline] + fn deref_mut(&mut self) -> &mut crate::testing::datatypes::AffixFuzzer21 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer21); impl ::re_types_core::Loggable for AffixFuzzer21 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer22.rs b/crates/re_types/src/testing/components/affix_fuzzer22.rs index 60c79dd72940..aba57a616ceb 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer22.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer22.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer22 { } } +impl std::ops::DerefMut for AffixFuzzer22 { + #[inline] + fn deref_mut(&mut self) -> &mut Option { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer22); impl ::re_types_core::Loggable for AffixFuzzer22 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer3.rs b/crates/re_types/src/testing/components/affix_fuzzer3.rs index 7f7e30820d6e..ab359373fbe5 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer3.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer3.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer3 { } } +impl std::ops::DerefMut for AffixFuzzer3 { + #[inline] + fn deref_mut(&mut self) -> &mut crate::testing::datatypes::AffixFuzzer1 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer3); impl ::re_types_core::Loggable for AffixFuzzer3 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer4.rs b/crates/re_types/src/testing/components/affix_fuzzer4.rs index b5cf4cfbaac4..28bdfabb60ac 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer4.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer4.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer4 { } } +impl std::ops::DerefMut for AffixFuzzer4 { + #[inline] + fn deref_mut(&mut self) -> &mut Option { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer4); impl ::re_types_core::Loggable for AffixFuzzer4 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer5.rs b/crates/re_types/src/testing/components/affix_fuzzer5.rs index cc8aa044d90e..c33f8b1c272d 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer5.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer5.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer5 { } } +impl std::ops::DerefMut for AffixFuzzer5 { + #[inline] + fn deref_mut(&mut self) -> &mut Option { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer5); impl ::re_types_core::Loggable for AffixFuzzer5 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer6.rs b/crates/re_types/src/testing/components/affix_fuzzer6.rs index 2c92d6e25635..ee23e331bead 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer6.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer6.rs @@ -59,6 +59,13 @@ impl std::ops::Deref for AffixFuzzer6 { } } +impl std::ops::DerefMut for AffixFuzzer6 { + #[inline] + fn deref_mut(&mut self) -> &mut Option { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer6); impl ::re_types_core::Loggable for AffixFuzzer6 { diff --git a/crates/re_types/src/testing/datatypes/affix_fuzzer5.rs b/crates/re_types/src/testing/datatypes/affix_fuzzer5.rs index 17857a7a1b98..5451e13b8b4f 100644 --- a/crates/re_types/src/testing/datatypes/affix_fuzzer5.rs +++ b/crates/re_types/src/testing/datatypes/affix_fuzzer5.rs @@ -63,6 +63,13 @@ impl std::ops::Deref for AffixFuzzer5 { } } +impl std::ops::DerefMut for AffixFuzzer5 { + #[inline] + fn deref_mut(&mut self) -> &mut Option { + &mut self.single_optional_union + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer5); impl ::re_types_core::Loggable for AffixFuzzer5 { diff --git a/crates/re_types_blueprint/src/blueprint/components/included_space_view.rs b/crates/re_types_blueprint/src/blueprint/components/included_space_view.rs index 50f59b4e0d8b..83d078567076 100644 --- a/crates/re_types_blueprint/src/blueprint/components/included_space_view.rs +++ b/crates/re_types_blueprint/src/blueprint/components/included_space_view.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for IncludedSpaceView { } } +impl std::ops::DerefMut for IncludedSpaceView { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Uuid { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(IncludedSpaceView); impl ::re_types_core::Loggable for IncludedSpaceView { diff --git a/crates/re_types_blueprint/src/blueprint/components/root_container.rs b/crates/re_types_blueprint/src/blueprint/components/root_container.rs index 944ddd02eb16..3f18d33a375d 100644 --- a/crates/re_types_blueprint/src/blueprint/components/root_container.rs +++ b/crates/re_types_blueprint/src/blueprint/components/root_container.rs @@ -64,6 +64,13 @@ impl std::ops::Deref for RootContainer { } } +impl std::ops::DerefMut for RootContainer { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Uuid { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(RootContainer); impl ::re_types_core::Loggable for RootContainer { diff --git a/crates/re_types_blueprint/src/blueprint/components/space_view_maximized.rs b/crates/re_types_blueprint/src/blueprint/components/space_view_maximized.rs index 6d4f4b882fde..ab23defb3329 100644 --- a/crates/re_types_blueprint/src/blueprint/components/space_view_maximized.rs +++ b/crates/re_types_blueprint/src/blueprint/components/space_view_maximized.rs @@ -61,6 +61,13 @@ impl std::ops::Deref for SpaceViewMaximized { } } +impl std::ops::DerefMut for SpaceViewMaximized { + #[inline] + fn deref_mut(&mut self) -> &mut crate::datatypes::Uuid { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(SpaceViewMaximized); impl ::re_types_core::Loggable for SpaceViewMaximized { diff --git a/crates/re_types_builder/src/codegen/rust/api.rs b/crates/re_types_builder/src/codegen/rust/api.rs index 2cc207367c77..e6fd8ed101ec 100644 --- a/crates/re_types_builder/src/codegen/rust/api.rs +++ b/crates/re_types_builder/src/codegen/rust/api.rs @@ -1526,6 +1526,8 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { let quoted_obj_name = format_ident!("{}", obj.name); let quoted_obj_field_name = format_ident!("{}", obj_field.name); + let quoted_type = quote_field_type_from_object_field(obj_field); + if obj_field.typ.fqname().is_some() { if let Some(inner) = obj_field.typ.vector_inner() { if obj_field.is_nullable { @@ -1558,18 +1560,16 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { } } } else { - let quoted_type = quote_field_type_from_object_field(obj_field); - let quoted_binding = if obj_is_tuple_struct { quote!(Self(v.into())) } else { quote!(Self { #quoted_obj_field_name: v.into() }) }; - let quoted_borrow_deref_impl = if obj_is_tuple_struct { - quote!(&self.0) + let self_field_access = if obj_is_tuple_struct { + quote!(self.0) } else { - quote!( &self.#quoted_obj_field_name ) + quote!(self.#quoted_obj_field_name ) }; quote! { @@ -1582,7 +1582,7 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { impl std::borrow::Borrow<#quoted_type> for #quoted_obj_name { #[inline] fn borrow(&self) -> &#quoted_type { - #quoted_borrow_deref_impl + &#self_field_access } } @@ -1591,15 +1591,19 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { #[inline] fn deref(&self) -> &#quoted_type { - #quoted_borrow_deref_impl + &#self_field_access + } + } + + impl std::ops::DerefMut for #quoted_obj_name { + #[inline] + fn deref_mut(&mut self) -> &mut #quoted_type { + &mut #self_field_access } } } } } else { - let quoted_type = quote_field_type_from_object_field(obj_field); - let quoted_obj_field_name = format_ident!("{}", obj_field.name); - let (quoted_binding, quoted_read) = if obj_is_tuple_struct { (quote!(Self(#quoted_obj_field_name)), quote!(value.0)) } else { From 2834631fc87a4134e013b3a28556c40bd95201cd Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 31 May 2024 10:59:51 +0200 Subject: [PATCH 2/6] unify code path for text editros using new `DerefMut` --- crates/re_edit_ui/src/lib.rs | 23 +++++----------------- crates/re_edit_ui/src/singleline_string.rs | 19 ++++++++++++++++++ 2 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 crates/re_edit_ui/src/singleline_string.rs diff --git a/crates/re_edit_ui/src/lib.rs b/crates/re_edit_ui/src/lib.rs index ed7dc3259eb8..cdabd5176c54 100644 --- a/crates/re_edit_ui/src/lib.rs +++ b/crates/re_edit_ui/src/lib.rs @@ -6,13 +6,13 @@ mod corner2d; mod marker_shape; mod response_utils; +mod singleline_string; mod visible; -// ---- - use egui::NumExt as _; use re_types::components::{Color, MarkerSize, Name, Radius, StrokeWidth, Text}; use re_viewer_context::ViewerContext; +use singleline_string::edit_singleline_string; // ---- @@ -29,20 +29,6 @@ fn edit_color_ui(_ctx: &ViewerContext<'_>, ui: &mut egui::Ui, value: &mut Color) response } -fn edit_text_ui(_ctx: &ViewerContext<'_>, ui: &mut egui::Ui, value: &mut Text) -> egui::Response { - let mut edit_text = value.to_string(); - let response = egui::TextEdit::singleline(&mut edit_text).show(ui).response; - *value = edit_text.into(); - response -} - -fn edit_name_ui(_ctx: &ViewerContext<'_>, ui: &mut egui::Ui, value: &mut Name) -> egui::Response { - let mut edit_name = value.to_string(); - let response = egui::TextEdit::singleline(&mut edit_name).show(ui).response; - *value = edit_name.into(); - response -} - fn edit_radius_ui( _ctx: &ViewerContext<'_>, ui: &mut egui::Ui, @@ -94,9 +80,10 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) { registry.add_editor(corner2d::edit_corner2d); registry.add_editor(marker_shape::edit_marker_shape_ui); registry.add_editor(edit_marker_size_ui); - registry.add_editor(edit_name_ui); registry.add_editor(edit_radius_ui); registry.add_editor(edit_stroke_width_ui); - registry.add_editor(edit_text_ui); registry.add_editor(visible::edit_visible); + + registry.add_editor::(edit_singleline_string); + registry.add_editor::(edit_singleline_string); } diff --git a/crates/re_edit_ui/src/singleline_string.rs b/crates/re_edit_ui/src/singleline_string.rs new file mode 100644 index 000000000000..22e3bd9a4988 --- /dev/null +++ b/crates/re_edit_ui/src/singleline_string.rs @@ -0,0 +1,19 @@ +/// Generic singleline string editor. +pub fn edit_singleline_string( + _ctx: &re_viewer_context::ViewerContext<'_>, + ui: &mut egui::Ui, + value: &mut impl std::ops::DerefMut, +) -> egui::Response { + edit_singleline_string_impl(ui, value) +} + +/// Non monomorphized implementation of [`edit_singleline_string`]. +fn edit_singleline_string_impl( + ui: &mut egui::Ui, + value: &mut re_types::datatypes::Utf8, +) -> egui::Response { + let mut edit_name = value.to_string(); + let response = egui::TextEdit::singleline(&mut edit_name).show(ui).response; + *value = edit_name.into(); + response +} From 3b3a669e671c04e60ec61ee58f73f0a0f8430379 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 31 May 2024 11:57:26 +0200 Subject: [PATCH 3/6] deref/derefmut for all single element components --- .../components/entity_properties_component.rs | 16 ++++++ .../src/blueprint/components/column_share.rs | 16 ++++++ .../src/blueprint/components/row_share.rs | 16 ++++++ .../src/blueprint/components/visible.rs | 16 ++++++ crates/re_types/src/components/blob.rs | 16 ++++++ crates/re_types/src/components/depth_meter.rs | 16 ++++++ .../src/components/disconnected_space.rs | 16 ++++++ crates/re_types/src/components/draw_order.rs | 16 ++++++ crates/re_types/src/components/marker_size.rs | 16 ++++++ crates/re_types/src/components/radius.rs | 16 ++++++ crates/re_types/src/components/scalar.rs | 16 ++++++ .../src/components/scalar_scattering.rs | 16 ++++++ .../re_types/src/components/stroke_width.rs | 16 ++++++ .../src/components/view_coordinates.rs | 16 ++++++ .../src/testing/components/affix_fuzzer10.rs | 16 ++++++ .../src/testing/components/affix_fuzzer11.rs | 16 ++++++ .../src/testing/components/affix_fuzzer12.rs | 16 ++++++ .../src/testing/components/affix_fuzzer13.rs | 16 ++++++ .../src/testing/components/affix_fuzzer8.rs | 16 ++++++ .../src/testing/components/affix_fuzzer9.rs | 16 ++++++ .../src/blueprint/components/auto_layout.rs | 16 ++++++ .../blueprint/components/auto_space_views.rs | 16 ++++++ .../src/blueprint/components/grid_columns.rs | 16 ++++++ .../re_types_builder/src/codegen/rust/api.rs | 56 ++++++++++++------- .../src/components/clear_is_recursive.rs | 16 ++++++ .../src/components/visualizer_overrides.rs | 16 ++++++ 26 files changed, 435 insertions(+), 21 deletions(-) diff --git a/crates/re_entity_db/src/blueprint/components/entity_properties_component.rs b/crates/re_entity_db/src/blueprint/components/entity_properties_component.rs index c95f1240d294..61e6392b3d70 100644 --- a/crates/re_entity_db/src/blueprint/components/entity_properties_component.rs +++ b/crates/re_entity_db/src/blueprint/components/entity_properties_component.rs @@ -40,6 +40,22 @@ impl From for crate::EntityProperties { } } +impl std::ops::Deref for EntityPropertiesComponent { + type Target = crate::EntityProperties; + + #[inline] + fn deref(&self) -> &crate::EntityProperties { + &self.0 + } +} + +impl std::ops::DerefMut for EntityPropertiesComponent { + #[inline] + fn deref_mut(&mut self) -> &mut crate::EntityProperties { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(EntityPropertiesComponent); impl ::re_types_core::Loggable for EntityPropertiesComponent { diff --git a/crates/re_types/src/blueprint/components/column_share.rs b/crates/re_types/src/blueprint/components/column_share.rs index 24b9536be3d3..6ecffe927898 100644 --- a/crates/re_types/src/blueprint/components/column_share.rs +++ b/crates/re_types/src/blueprint/components/column_share.rs @@ -55,6 +55,22 @@ impl From for f32 { } } +impl std::ops::Deref for ColumnShare { + type Target = f32; + + #[inline] + fn deref(&self) -> &f32 { + &self.0 + } +} + +impl std::ops::DerefMut for ColumnShare { + #[inline] + fn deref_mut(&mut self) -> &mut f32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(ColumnShare); impl ::re_types_core::Loggable for ColumnShare { diff --git a/crates/re_types/src/blueprint/components/row_share.rs b/crates/re_types/src/blueprint/components/row_share.rs index 41aba6a432ce..4ef5bcb7f5a8 100644 --- a/crates/re_types/src/blueprint/components/row_share.rs +++ b/crates/re_types/src/blueprint/components/row_share.rs @@ -55,6 +55,22 @@ impl From for f32 { } } +impl std::ops::Deref for RowShare { + type Target = f32; + + #[inline] + fn deref(&self) -> &f32 { + &self.0 + } +} + +impl std::ops::DerefMut for RowShare { + #[inline] + fn deref_mut(&mut self) -> &mut f32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(RowShare); impl ::re_types_core::Loggable for RowShare { diff --git a/crates/re_types/src/blueprint/components/visible.rs b/crates/re_types/src/blueprint/components/visible.rs index aa5eefdf8b47..6634016dc492 100644 --- a/crates/re_types/src/blueprint/components/visible.rs +++ b/crates/re_types/src/blueprint/components/visible.rs @@ -53,6 +53,22 @@ impl From for bool { } } +impl std::ops::Deref for Visible { + type Target = bool; + + #[inline] + fn deref(&self) -> &bool { + &self.0 + } +} + +impl std::ops::DerefMut for Visible { + #[inline] + fn deref_mut(&mut self) -> &mut bool { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Visible); impl ::re_types_core::Loggable for Visible { diff --git a/crates/re_types/src/components/blob.rs b/crates/re_types/src/components/blob.rs index 54a5eff9720d..a0ef25e12d64 100644 --- a/crates/re_types/src/components/blob.rs +++ b/crates/re_types/src/components/blob.rs @@ -53,6 +53,22 @@ impl From for ::re_types_core::ArrowBuffer { } } +impl std::ops::Deref for Blob { + type Target = ::re_types_core::ArrowBuffer; + + #[inline] + fn deref(&self) -> &::re_types_core::ArrowBuffer { + &self.0 + } +} + +impl std::ops::DerefMut for Blob { + #[inline] + fn deref_mut(&mut self) -> &mut ::re_types_core::ArrowBuffer { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Blob); impl ::re_types_core::Loggable for Blob { diff --git a/crates/re_types/src/components/depth_meter.rs b/crates/re_types/src/components/depth_meter.rs index e55476b6467c..fae9b6aca5dd 100644 --- a/crates/re_types/src/components/depth_meter.rs +++ b/crates/re_types/src/components/depth_meter.rs @@ -53,6 +53,22 @@ impl From for f32 { } } +impl std::ops::Deref for DepthMeter { + type Target = f32; + + #[inline] + fn deref(&self) -> &f32 { + &self.0 + } +} + +impl std::ops::DerefMut for DepthMeter { + #[inline] + fn deref_mut(&mut self) -> &mut f32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(DepthMeter); impl ::re_types_core::Loggable for DepthMeter { diff --git a/crates/re_types/src/components/disconnected_space.rs b/crates/re_types/src/components/disconnected_space.rs index 65a17ba73526..73bcd734066f 100644 --- a/crates/re_types/src/components/disconnected_space.rs +++ b/crates/re_types/src/components/disconnected_space.rs @@ -63,6 +63,22 @@ impl From for bool { } } +impl std::ops::Deref for DisconnectedSpace { + type Target = bool; + + #[inline] + fn deref(&self) -> &bool { + &self.0 + } +} + +impl std::ops::DerefMut for DisconnectedSpace { + #[inline] + fn deref_mut(&mut self) -> &mut bool { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(DisconnectedSpace); impl ::re_types_core::Loggable for DisconnectedSpace { diff --git a/crates/re_types/src/components/draw_order.rs b/crates/re_types/src/components/draw_order.rs index a5170f3c49cb..bdce680cd67c 100644 --- a/crates/re_types/src/components/draw_order.rs +++ b/crates/re_types/src/components/draw_order.rs @@ -59,6 +59,22 @@ impl From for f32 { } } +impl std::ops::Deref for DrawOrder { + type Target = f32; + + #[inline] + fn deref(&self) -> &f32 { + &self.0 + } +} + +impl std::ops::DerefMut for DrawOrder { + #[inline] + fn deref_mut(&mut self) -> &mut f32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(DrawOrder); impl ::re_types_core::Loggable for DrawOrder { diff --git a/crates/re_types/src/components/marker_size.rs b/crates/re_types/src/components/marker_size.rs index 76dfc674a49b..1c7d16b1fc19 100644 --- a/crates/re_types/src/components/marker_size.rs +++ b/crates/re_types/src/components/marker_size.rs @@ -53,6 +53,22 @@ impl From for f32 { } } +impl std::ops::Deref for MarkerSize { + type Target = f32; + + #[inline] + fn deref(&self) -> &f32 { + &self.0 + } +} + +impl std::ops::DerefMut for MarkerSize { + #[inline] + fn deref_mut(&mut self) -> &mut f32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(MarkerSize); impl ::re_types_core::Loggable for MarkerSize { diff --git a/crates/re_types/src/components/radius.rs b/crates/re_types/src/components/radius.rs index b87561b388b4..4fb7cc4a7708 100644 --- a/crates/re_types/src/components/radius.rs +++ b/crates/re_types/src/components/radius.rs @@ -53,6 +53,22 @@ impl From for f32 { } } +impl std::ops::Deref for Radius { + type Target = f32; + + #[inline] + fn deref(&self) -> &f32 { + &self.0 + } +} + +impl std::ops::DerefMut for Radius { + #[inline] + fn deref_mut(&mut self) -> &mut f32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Radius); impl ::re_types_core::Loggable for Radius { diff --git a/crates/re_types/src/components/scalar.rs b/crates/re_types/src/components/scalar.rs index 88aa47dca063..4d0a5d99d0b4 100644 --- a/crates/re_types/src/components/scalar.rs +++ b/crates/re_types/src/components/scalar.rs @@ -55,6 +55,22 @@ impl From for f64 { } } +impl std::ops::Deref for Scalar { + type Target = f64; + + #[inline] + fn deref(&self) -> &f64 { + &self.0 + } +} + +impl std::ops::DerefMut for Scalar { + #[inline] + fn deref_mut(&mut self) -> &mut f64 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(Scalar); impl ::re_types_core::Loggable for Scalar { diff --git a/crates/re_types/src/components/scalar_scattering.rs b/crates/re_types/src/components/scalar_scattering.rs index 92faaf6cca5e..4f5ade0d9ebd 100644 --- a/crates/re_types/src/components/scalar_scattering.rs +++ b/crates/re_types/src/components/scalar_scattering.rs @@ -52,6 +52,22 @@ impl From for bool { } } +impl std::ops::Deref for ScalarScattering { + type Target = bool; + + #[inline] + fn deref(&self) -> &bool { + &self.0 + } +} + +impl std::ops::DerefMut for ScalarScattering { + #[inline] + fn deref_mut(&mut self) -> &mut bool { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(ScalarScattering); impl ::re_types_core::Loggable for ScalarScattering { diff --git a/crates/re_types/src/components/stroke_width.rs b/crates/re_types/src/components/stroke_width.rs index 23680e406360..f6c884989b43 100644 --- a/crates/re_types/src/components/stroke_width.rs +++ b/crates/re_types/src/components/stroke_width.rs @@ -53,6 +53,22 @@ impl From for f32 { } } +impl std::ops::Deref for StrokeWidth { + type Target = f32; + + #[inline] + fn deref(&self) -> &f32 { + &self.0 + } +} + +impl std::ops::DerefMut for StrokeWidth { + #[inline] + fn deref_mut(&mut self) -> &mut f32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(StrokeWidth); impl ::re_types_core::Loggable for StrokeWidth { diff --git a/crates/re_types/src/components/view_coordinates.rs b/crates/re_types/src/components/view_coordinates.rs index ced1cbdd80eb..4359f6bbf4df 100644 --- a/crates/re_types/src/components/view_coordinates.rs +++ b/crates/re_types/src/components/view_coordinates.rs @@ -71,6 +71,22 @@ impl From for [u8; 3usize] { } } +impl std::ops::Deref for ViewCoordinates { + type Target = [u8; 3usize]; + + #[inline] + fn deref(&self) -> &[u8; 3usize] { + &self.0 + } +} + +impl std::ops::DerefMut for ViewCoordinates { + #[inline] + fn deref_mut(&mut self) -> &mut [u8; 3usize] { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(ViewCoordinates); impl ::re_types_core::Loggable for ViewCoordinates { diff --git a/crates/re_types/src/testing/components/affix_fuzzer10.rs b/crates/re_types/src/testing/components/affix_fuzzer10.rs index c59288d08feb..7290aa46767d 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer10.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer10.rs @@ -51,6 +51,22 @@ impl From for Option<::re_types_core::ArrowString> { } } +impl std::ops::Deref for AffixFuzzer10 { + type Target = Option<::re_types_core::ArrowString>; + + #[inline] + fn deref(&self) -> &Option<::re_types_core::ArrowString> { + &self.0 + } +} + +impl std::ops::DerefMut for AffixFuzzer10 { + #[inline] + fn deref_mut(&mut self) -> &mut Option<::re_types_core::ArrowString> { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer10); impl ::re_types_core::Loggable for AffixFuzzer10 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer11.rs b/crates/re_types/src/testing/components/affix_fuzzer11.rs index 8b3c634eec3d..e82f1cbc6b83 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer11.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer11.rs @@ -51,6 +51,22 @@ impl From for Option<::re_types_core::ArrowBuffer> { } } +impl std::ops::Deref for AffixFuzzer11 { + type Target = Option<::re_types_core::ArrowBuffer>; + + #[inline] + fn deref(&self) -> &Option<::re_types_core::ArrowBuffer> { + &self.0 + } +} + +impl std::ops::DerefMut for AffixFuzzer11 { + #[inline] + fn deref_mut(&mut self) -> &mut Option<::re_types_core::ArrowBuffer> { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer11); impl ::re_types_core::Loggable for AffixFuzzer11 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer12.rs b/crates/re_types/src/testing/components/affix_fuzzer12.rs index 097fcb40aa71..418e5f874771 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer12.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer12.rs @@ -51,6 +51,22 @@ impl From for Vec<::re_types_core::ArrowString> { } } +impl std::ops::Deref for AffixFuzzer12 { + type Target = Vec<::re_types_core::ArrowString>; + + #[inline] + fn deref(&self) -> &Vec<::re_types_core::ArrowString> { + &self.0 + } +} + +impl std::ops::DerefMut for AffixFuzzer12 { + #[inline] + fn deref_mut(&mut self) -> &mut Vec<::re_types_core::ArrowString> { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer12); impl ::re_types_core::Loggable for AffixFuzzer12 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer13.rs b/crates/re_types/src/testing/components/affix_fuzzer13.rs index fc5ab5948fb6..63f363ea9113 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer13.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer13.rs @@ -51,6 +51,22 @@ impl From for Option> { } } +impl std::ops::Deref for AffixFuzzer13 { + type Target = Option>; + + #[inline] + fn deref(&self) -> &Option> { + &self.0 + } +} + +impl std::ops::DerefMut for AffixFuzzer13 { + #[inline] + fn deref_mut(&mut self) -> &mut Option> { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer13); impl ::re_types_core::Loggable for AffixFuzzer13 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer8.rs b/crates/re_types/src/testing/components/affix_fuzzer8.rs index 0fb7322c5c04..094f0f91ad92 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer8.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer8.rs @@ -51,6 +51,22 @@ impl From for Option { } } +impl std::ops::Deref for AffixFuzzer8 { + type Target = Option; + + #[inline] + fn deref(&self) -> &Option { + &self.0 + } +} + +impl std::ops::DerefMut for AffixFuzzer8 { + #[inline] + fn deref_mut(&mut self) -> &mut Option { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer8); impl ::re_types_core::Loggable for AffixFuzzer8 { diff --git a/crates/re_types/src/testing/components/affix_fuzzer9.rs b/crates/re_types/src/testing/components/affix_fuzzer9.rs index dffc9d317580..2d730f322165 100644 --- a/crates/re_types/src/testing/components/affix_fuzzer9.rs +++ b/crates/re_types/src/testing/components/affix_fuzzer9.rs @@ -51,6 +51,22 @@ impl From for ::re_types_core::ArrowString { } } +impl std::ops::Deref for AffixFuzzer9 { + type Target = ::re_types_core::ArrowString; + + #[inline] + fn deref(&self) -> &::re_types_core::ArrowString { + &self.0 + } +} + +impl std::ops::DerefMut for AffixFuzzer9 { + #[inline] + fn deref_mut(&mut self) -> &mut ::re_types_core::ArrowString { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AffixFuzzer9); impl ::re_types_core::Loggable for AffixFuzzer9 { diff --git a/crates/re_types_blueprint/src/blueprint/components/auto_layout.rs b/crates/re_types_blueprint/src/blueprint/components/auto_layout.rs index 7167224317f3..8d2856b9c9cc 100644 --- a/crates/re_types_blueprint/src/blueprint/components/auto_layout.rs +++ b/crates/re_types_blueprint/src/blueprint/components/auto_layout.rs @@ -53,6 +53,22 @@ impl From for bool { } } +impl std::ops::Deref for AutoLayout { + type Target = bool; + + #[inline] + fn deref(&self) -> &bool { + &self.0 + } +} + +impl std::ops::DerefMut for AutoLayout { + #[inline] + fn deref_mut(&mut self) -> &mut bool { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AutoLayout); impl ::re_types_core::Loggable for AutoLayout { diff --git a/crates/re_types_blueprint/src/blueprint/components/auto_space_views.rs b/crates/re_types_blueprint/src/blueprint/components/auto_space_views.rs index 04223f5ca8ac..c2d95248673f 100644 --- a/crates/re_types_blueprint/src/blueprint/components/auto_space_views.rs +++ b/crates/re_types_blueprint/src/blueprint/components/auto_space_views.rs @@ -53,6 +53,22 @@ impl From for bool { } } +impl std::ops::Deref for AutoSpaceViews { + type Target = bool; + + #[inline] + fn deref(&self) -> &bool { + &self.0 + } +} + +impl std::ops::DerefMut for AutoSpaceViews { + #[inline] + fn deref_mut(&mut self) -> &mut bool { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(AutoSpaceViews); impl ::re_types_core::Loggable for AutoSpaceViews { diff --git a/crates/re_types_blueprint/src/blueprint/components/grid_columns.rs b/crates/re_types_blueprint/src/blueprint/components/grid_columns.rs index e10e5c743406..983af2525ae6 100644 --- a/crates/re_types_blueprint/src/blueprint/components/grid_columns.rs +++ b/crates/re_types_blueprint/src/blueprint/components/grid_columns.rs @@ -55,6 +55,22 @@ impl From for u32 { } } +impl std::ops::Deref for GridColumns { + type Target = u32; + + #[inline] + fn deref(&self) -> &u32 { + &self.0 + } +} + +impl std::ops::DerefMut for GridColumns { + #[inline] + fn deref_mut(&mut self) -> &mut u32 { + &mut self.0 + } +} + ::re_types_core::macros::impl_into_cow!(GridColumns); impl ::re_types_core::Loggable for GridColumns { diff --git a/crates/re_types_builder/src/codegen/rust/api.rs b/crates/re_types_builder/src/codegen/rust/api.rs index e6fd8ed101ec..5e5d677b8200 100644 --- a/crates/re_types_builder/src/codegen/rust/api.rs +++ b/crates/re_types_builder/src/codegen/rust/api.rs @@ -1528,6 +1528,29 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { let quoted_type = quote_field_type_from_object_field(obj_field); + let self_field_access = if obj_is_tuple_struct { + quote!(self.0) + } else { + quote!(self.#quoted_obj_field_name ) + }; + let deref_impl = quote! { + impl std::ops::Deref for #quoted_obj_name { + type Target = #quoted_type; + + #[inline] + fn deref(&self) -> &#quoted_type { + &#self_field_access + } + } + + impl std::ops::DerefMut for #quoted_obj_name { + #[inline] + fn deref_mut(&mut self) -> &mut #quoted_type { + &mut #self_field_access + } + } + }; + if obj_field.typ.fqname().is_some() { if let Some(inner) = obj_field.typ.vector_inner() { if obj_field.is_nullable { @@ -1566,12 +1589,6 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { quote!(Self { #quoted_obj_field_name: v.into() }) }; - let self_field_access = if obj_is_tuple_struct { - quote!(self.0) - } else { - quote!(self.#quoted_obj_field_name ) - }; - quote! { impl> From for #quoted_obj_name { fn from(v: T) -> Self { @@ -1586,21 +1603,7 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { } } - impl std::ops::Deref for #quoted_obj_name { - type Target = #quoted_type; - - #[inline] - fn deref(&self) -> &#quoted_type { - &#self_field_access - } - } - - impl std::ops::DerefMut for #quoted_obj_name { - #[inline] - fn deref_mut(&mut self) -> &mut #quoted_type { - &mut #self_field_access - } - } + #deref_impl } } } else { @@ -1613,6 +1616,15 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { ) }; + // Emit `Deref`/`DerefMut` only for components since datatypes may want to do custom implementations. + // Note that all components _should_ be implemented by components, so once we + // enforce that, we'd not actually hit this path. + let deref_impl = if obj.kind == ObjectKind::Component { + deref_impl + } else { + quote!() + }; + quote! { impl From<#quoted_type> for #quoted_obj_name { #[inline] @@ -1627,6 +1639,8 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { #quoted_read } } + + #deref_impl } } } diff --git a/crates/re_types_core/src/components/clear_is_recursive.rs b/crates/re_types_core/src/components/clear_is_recursive.rs index c55b876f6ca2..dedb70f52be6 100644 --- a/crates/re_types_core/src/components/clear_is_recursive.rs +++ b/crates/re_types_core/src/components/clear_is_recursive.rs @@ -55,6 +55,22 @@ impl From for bool { } } +impl std::ops::Deref for ClearIsRecursive { + type Target = bool; + + #[inline] + fn deref(&self) -> &bool { + &self.0 + } +} + +impl std::ops::DerefMut for ClearIsRecursive { + #[inline] + fn deref_mut(&mut self) -> &mut bool { + &mut self.0 + } +} + crate::macros::impl_into_cow!(ClearIsRecursive); impl crate::Loggable for ClearIsRecursive { diff --git a/crates/re_types_core/src/components/visualizer_overrides.rs b/crates/re_types_core/src/components/visualizer_overrides.rs index 138f2d9d7371..8fa237ba2b91 100644 --- a/crates/re_types_core/src/components/visualizer_overrides.rs +++ b/crates/re_types_core/src/components/visualizer_overrides.rs @@ -53,6 +53,22 @@ impl From for Vec { } } +impl std::ops::Deref for VisualizerOverrides { + type Target = Vec; + + #[inline] + fn deref(&self) -> &Vec { + &self.0 + } +} + +impl std::ops::DerefMut for VisualizerOverrides { + #[inline] + fn deref_mut(&mut self) -> &mut Vec { + &mut self.0 + } +} + crate::macros::impl_into_cow!(VisualizerOverrides); impl crate::Loggable for VisualizerOverrides { From 2580249119403c0ea4a5149c2711f6ede018e012 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 31 May 2024 12:02:37 +0200 Subject: [PATCH 4/6] organize component agnostic editors neatly --- .../src/datatype_editors/bool_toggle.rs | 22 ++++++++ .../src/datatype_editors/float_drag.rs | 22 ++++++++ crates/re_edit_ui/src/datatype_editors/mod.rs | 5 ++ .../singleline_string.rs | 0 crates/re_edit_ui/src/lib.rs | 56 +++---------------- 5 files changed, 57 insertions(+), 48 deletions(-) create mode 100644 crates/re_edit_ui/src/datatype_editors/bool_toggle.rs create mode 100644 crates/re_edit_ui/src/datatype_editors/float_drag.rs create mode 100644 crates/re_edit_ui/src/datatype_editors/mod.rs rename crates/re_edit_ui/src/{ => datatype_editors}/singleline_string.rs (100%) diff --git a/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs b/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs new file mode 100644 index 000000000000..12237408907a --- /dev/null +++ b/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs @@ -0,0 +1,22 @@ +use std::ops::DerefMut; + +use egui::NumExt as _; + +/// Generic editor for a f32 value from zero to infinity. +pub fn edit_f32_zero_to_inf( + _ctx: &re_viewer_context::ViewerContext<'_>, + ui: &mut egui::Ui, + value: &mut impl DerefMut, +) -> egui::Response { + edit_f32_zero_to_inf_impl(ui, value) +} + +/// Non monomorphized implementation of [`edit_f32_zero_to_inf`]. +fn edit_f32_zero_to_inf_impl(ui: &mut egui::Ui, value: &mut f32) -> egui::Response { + let speed = (*value * 0.01).at_least(0.001); + ui.add( + egui::DragValue::new(value) + .clamp_range(0.0..=f32::INFINITY) + .speed(speed), + ) +} diff --git a/crates/re_edit_ui/src/datatype_editors/float_drag.rs b/crates/re_edit_ui/src/datatype_editors/float_drag.rs new file mode 100644 index 000000000000..12237408907a --- /dev/null +++ b/crates/re_edit_ui/src/datatype_editors/float_drag.rs @@ -0,0 +1,22 @@ +use std::ops::DerefMut; + +use egui::NumExt as _; + +/// Generic editor for a f32 value from zero to infinity. +pub fn edit_f32_zero_to_inf( + _ctx: &re_viewer_context::ViewerContext<'_>, + ui: &mut egui::Ui, + value: &mut impl DerefMut, +) -> egui::Response { + edit_f32_zero_to_inf_impl(ui, value) +} + +/// Non monomorphized implementation of [`edit_f32_zero_to_inf`]. +fn edit_f32_zero_to_inf_impl(ui: &mut egui::Ui, value: &mut f32) -> egui::Response { + let speed = (*value * 0.01).at_least(0.001); + ui.add( + egui::DragValue::new(value) + .clamp_range(0.0..=f32::INFINITY) + .speed(speed), + ) +} diff --git a/crates/re_edit_ui/src/datatype_editors/mod.rs b/crates/re_edit_ui/src/datatype_editors/mod.rs new file mode 100644 index 000000000000..d6d74d925e7b --- /dev/null +++ b/crates/re_edit_ui/src/datatype_editors/mod.rs @@ -0,0 +1,5 @@ +mod float_drag; +mod singleline_string; + +pub use float_drag::edit_f32_zero_to_inf; +pub use singleline_string::edit_singleline_string; diff --git a/crates/re_edit_ui/src/singleline_string.rs b/crates/re_edit_ui/src/datatype_editors/singleline_string.rs similarity index 100% rename from crates/re_edit_ui/src/singleline_string.rs rename to crates/re_edit_ui/src/datatype_editors/singleline_string.rs diff --git a/crates/re_edit_ui/src/lib.rs b/crates/re_edit_ui/src/lib.rs index cdabd5176c54..9fbaa6f9945c 100644 --- a/crates/re_edit_ui/src/lib.rs +++ b/crates/re_edit_ui/src/lib.rs @@ -4,15 +4,13 @@ //! This should be called by `re_viewer` on startup. mod corner2d; +mod datatype_editors; mod marker_shape; mod response_utils; -mod singleline_string; mod visible; -use egui::NumExt as _; use re_types::components::{Color, MarkerSize, Name, Radius, StrokeWidth, Text}; use re_viewer_context::ViewerContext; -use singleline_string::edit_singleline_string; // ---- @@ -29,46 +27,6 @@ fn edit_color_ui(_ctx: &ViewerContext<'_>, ui: &mut egui::Ui, value: &mut Color) response } -fn edit_radius_ui( - _ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut Radius, -) -> egui::Response { - let speed = (value.0 * 0.01).at_least(0.001); - - ui.add( - egui::DragValue::new(&mut value.0) - .clamp_range(0.0..=f64::INFINITY) - .speed(speed), - ) -} - -fn edit_stroke_width_ui( - _ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut StrokeWidth, -) -> egui::Response { - let speed = (value.0 * 0.01).at_least(0.001); - ui.add( - egui::DragValue::new(&mut value.0) - .clamp_range(0.0..=f64::INFINITY) - .speed(speed), - ) -} - -fn edit_marker_size_ui( - _ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut MarkerSize, -) -> egui::Response { - let speed = (value.0 * 0.01).at_least(0.001); - ui.add( - egui::DragValue::new(&mut value.0) - .clamp_range(0.0..=f64::INFINITY) - .speed(speed), - ) -} - // ---- /// Registers all editors of this crate in the component UI registry. @@ -79,11 +37,13 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) { registry.add_editor(edit_color_ui); registry.add_editor(corner2d::edit_corner2d); registry.add_editor(marker_shape::edit_marker_shape_ui); - registry.add_editor(edit_marker_size_ui); - registry.add_editor(edit_radius_ui); - registry.add_editor(edit_stroke_width_ui); + registry.add_editor(visible::edit_visible); - registry.add_editor::(edit_singleline_string); - registry.add_editor::(edit_singleline_string); + registry.add_editor::(datatype_editors::edit_singleline_string); + registry.add_editor::(datatype_editors::edit_singleline_string); + + registry.add_editor::(datatype_editors::edit_f32_zero_to_inf); + registry.add_editor::(datatype_editors::edit_f32_zero_to_inf); + registry.add_editor::(datatype_editors::edit_f32_zero_to_inf); } From 251b5fb69c0cbeeb975be7ec81e8ce6863152f0f Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Fri, 31 May 2024 12:08:43 +0200 Subject: [PATCH 5/6] make bool edit_ui generic (there's more bools incoming soon! --- .../src/datatype_editors/bool_toggle.rs | 28 ++++++++----------- .../src/datatype_editors/float_drag.rs | 4 +-- crates/re_edit_ui/src/datatype_editors/mod.rs | 2 ++ crates/re_edit_ui/src/lib.rs | 8 ++++-- crates/re_edit_ui/src/visible.rs | 15 ---------- 5 files changed, 20 insertions(+), 37 deletions(-) delete mode 100644 crates/re_edit_ui/src/visible.rs diff --git a/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs b/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs index 12237408907a..24c16dabb72e 100644 --- a/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs +++ b/crates/re_edit_ui/src/datatype_editors/bool_toggle.rs @@ -1,22 +1,18 @@ -use std::ops::DerefMut; - -use egui::NumExt as _; - -/// Generic editor for a f32 value from zero to infinity. -pub fn edit_f32_zero_to_inf( +/// Generic editor for a boolean value. +pub fn edit_bool( _ctx: &re_viewer_context::ViewerContext<'_>, ui: &mut egui::Ui, - value: &mut impl DerefMut, + value: &mut impl std::ops::DerefMut, ) -> egui::Response { - edit_f32_zero_to_inf_impl(ui, value) + edit_bool_impl(ui, value) } -/// Non monomorphized implementation of [`edit_f32_zero_to_inf`]. -fn edit_f32_zero_to_inf_impl(ui: &mut egui::Ui, value: &mut f32) -> egui::Response { - let speed = (*value * 0.01).at_least(0.001); - ui.add( - egui::DragValue::new(value) - .clamp_range(0.0..=f32::INFINITY) - .speed(speed), - ) +/// Non monomorphized implementation of [`edit_bool`]. +fn edit_bool_impl(ui: &mut egui::Ui, value: &mut bool) -> egui::Response { + ui.scope(move |ui| { + ui.visuals_mut().widgets.hovered.expansion = 0.0; + ui.visuals_mut().widgets.active.expansion = 0.0; + ui.add(re_ui::toggle_switch(15.0, value)) + }) + .inner } diff --git a/crates/re_edit_ui/src/datatype_editors/float_drag.rs b/crates/re_edit_ui/src/datatype_editors/float_drag.rs index 12237408907a..a0712b8d4dc2 100644 --- a/crates/re_edit_ui/src/datatype_editors/float_drag.rs +++ b/crates/re_edit_ui/src/datatype_editors/float_drag.rs @@ -1,12 +1,10 @@ -use std::ops::DerefMut; - use egui::NumExt as _; /// Generic editor for a f32 value from zero to infinity. pub fn edit_f32_zero_to_inf( _ctx: &re_viewer_context::ViewerContext<'_>, ui: &mut egui::Ui, - value: &mut impl DerefMut, + value: &mut impl std::ops::DerefMut, ) -> egui::Response { edit_f32_zero_to_inf_impl(ui, value) } diff --git a/crates/re_edit_ui/src/datatype_editors/mod.rs b/crates/re_edit_ui/src/datatype_editors/mod.rs index d6d74d925e7b..2621c61e6fb0 100644 --- a/crates/re_edit_ui/src/datatype_editors/mod.rs +++ b/crates/re_edit_ui/src/datatype_editors/mod.rs @@ -1,5 +1,7 @@ +mod bool_toggle; mod float_drag; mod singleline_string; +pub use bool_toggle::edit_bool; pub use float_drag::edit_f32_zero_to_inf; pub use singleline_string::edit_singleline_string; diff --git a/crates/re_edit_ui/src/lib.rs b/crates/re_edit_ui/src/lib.rs index 9fbaa6f9945c..66feb91f436f 100644 --- a/crates/re_edit_ui/src/lib.rs +++ b/crates/re_edit_ui/src/lib.rs @@ -7,9 +7,11 @@ mod corner2d; mod datatype_editors; mod marker_shape; mod response_utils; -mod visible; -use re_types::components::{Color, MarkerSize, Name, Radius, StrokeWidth, Text}; +use re_types::{ + blueprint::components::Visible, + components::{Color, MarkerSize, Name, Radius, StrokeWidth, Text}, +}; use re_viewer_context::ViewerContext; // ---- @@ -38,7 +40,7 @@ pub fn register_editors(registry: &mut re_viewer_context::ComponentUiRegistry) { registry.add_editor(corner2d::edit_corner2d); registry.add_editor(marker_shape::edit_marker_shape_ui); - registry.add_editor(visible::edit_visible); + registry.add_editor::(datatype_editors::edit_bool); registry.add_editor::(datatype_editors::edit_singleline_string); registry.add_editor::(datatype_editors::edit_singleline_string); diff --git a/crates/re_edit_ui/src/visible.rs b/crates/re_edit_ui/src/visible.rs deleted file mode 100644 index 6e2ef2e3d45f..000000000000 --- a/crates/re_edit_ui/src/visible.rs +++ /dev/null @@ -1,15 +0,0 @@ -use re_types::blueprint::components::Visible; -use re_viewer_context::ViewerContext; - -pub fn edit_visible( - _ctx: &ViewerContext<'_>, - ui: &mut egui::Ui, - value: &mut Visible, -) -> egui::Response { - ui.scope(|ui| { - ui.visuals_mut().widgets.hovered.expansion = 0.0; - ui.visuals_mut().widgets.active.expansion = 0.0; - ui.add(re_ui::toggle_switch(15.0, &mut value.0)) - }) - .inner -} From bd063f21ccf036a592b9fb39a3e50ba1900ece99 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Mon, 3 Jun 2024 10:06:45 +0200 Subject: [PATCH 6/6] clarify comment --- crates/re_types_builder/src/codegen/rust/api.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/re_types_builder/src/codegen/rust/api.rs b/crates/re_types_builder/src/codegen/rust/api.rs index 5e5d677b8200..04dcd7f8aca9 100644 --- a/crates/re_types_builder/src/codegen/rust/api.rs +++ b/crates/re_types_builder/src/codegen/rust/api.rs @@ -1616,9 +1616,9 @@ fn quote_from_impl_from_obj(obj: &Object) -> TokenStream { ) }; - // Emit `Deref`/`DerefMut` only for components since datatypes may want to do custom implementations. - // Note that all components _should_ be implemented by components, so once we - // enforce that, we'd not actually hit this path. + // If the field is not a custom datatype, emit `Deref`/`DerefMut` only for components. + // (in the long run all components are implemented with custom data types, making it so that we don't hit this path anymore) + // For ObjectKind::Datatype we sometimes have custom implementations for `Deref`, e.g. `Utf8String` derefs to `&str` instead of `ArrowString`. let deref_impl = if obj.kind == ObjectKind::Component { deref_impl } else {