From ba2f2d5719d1fb68fc94934ad26d048402c21070 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 15 Apr 2021 09:50:23 +0200 Subject: [PATCH] Add an Opacity element that does nothing --- api/sixtyfps-cpp/include/sixtyfps.h | 2 + sixtyfps_compiler/builtins.60 | 9 +++ sixtyfps_runtime/corelib/items.rs | 75 ++++++++++++++++++- .../interpreter/dynamic_component.rs | 1 + xtask/src/cbindgen.rs | 1 + 5 files changed, 87 insertions(+), 1 deletion(-) diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index 69fb40ce8..6f851cddf 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -48,6 +48,7 @@ extern const cbindgen_private::ItemVTable TextInputVTable; extern const cbindgen_private::ItemVTable ClipVTable; extern const cbindgen_private::ItemVTable BoxShadowVTable; extern const cbindgen_private::ItemVTable RotateVTable; +extern const cbindgen_private::ItemVTable OpacityVTable; extern const cbindgen_private::ItemVTable NativeButtonVTable; extern const cbindgen_private::ItemVTable NativeCheckBoxVTable; @@ -153,6 +154,7 @@ using cbindgen_private::ClippedImage; using cbindgen_private::Flickable; using cbindgen_private::FocusScope; using cbindgen_private::Image; +using cbindgen_private::Opacity; using cbindgen_private::Path; using cbindgen_private::Rectangle; using cbindgen_private::Rotate; diff --git a/sixtyfps_compiler/builtins.60 b/sixtyfps_compiler/builtins.60 index a064f55d3..039ec89c4 100644 --- a/sixtyfps_compiler/builtins.60 +++ b/sixtyfps_compiler/builtins.60 @@ -200,6 +200,15 @@ export Clip := _ { //-default_size_binding:expands_to_parent_geometry } +export Opacity := _ { + property x; + property y; + property width; + property height; + property opacity; + //-default_size_binding:expands_to_parent_geometry +} + Row := _ { //-is_non_item_type } diff --git a/sixtyfps_runtime/corelib/items.rs b/sixtyfps_runtime/corelib/items.rs index e23dac738..19b9c5f01 100644 --- a/sixtyfps_runtime/corelib/items.rs +++ b/sixtyfps_runtime/corelib/items.rs @@ -16,7 +16,9 @@ When adding an item or a property, it needs to be kept in sync with different pl - It needs to be changed in this module - In the compiler: builtins.60 - In the interpreter (new item only): dynamic_component.rs - - For the C++ code (new item only): the cbindgen.rs to export the new item, and the `using` declaration in sixtyfps.h + - For the C++ code (new item only): + - the cbindgen.rs to export the new item + - the `using` declaration in sixtyfps.h for the item and its vtable - Don't forget to update the documentation */ @@ -630,6 +632,77 @@ ItemVTable_static! { pub static ClipVTable for Clip } +#[repr(C)] +#[derive(FieldOffsets, Default, SixtyFPSElement)] +#[pin] +/// The Opacity Item is not meant to be used directly by the .60 code, instead, the `opacity: xxx` or `visible: false` should be used +pub struct Opacity { + // FIXME: this element shouldn't need these geometry property + pub x: Property, + pub y: Property, + pub width: Property, + pub height: Property, + pub opacity: Property, + pub cached_rendering_data: CachedRenderingData, +} + +impl Item for Opacity { + fn init(self: Pin<&Self>, _window: &ComponentWindow) {} + + fn geometry(self: Pin<&Self>) -> Rect { + euclid::rect(self.x(), self.y(), self.width(), self.height()) + } + + fn layouting_info(self: Pin<&Self>, _window: &ComponentWindow) -> LayoutInfo { + LayoutInfo { horizontal_stretch: 1., vertical_stretch: 1., ..LayoutInfo::default() } + } + + fn implicit_size(self: Pin<&Self>, _window: &ComponentWindow) -> Size { + Default::default() + } + + fn input_event_filter_before_children( + self: Pin<&Self>, + _: MouseEvent, + _window: &ComponentWindow, + _self_rc: &ItemRc, + ) -> InputEventFilterResult { + InputEventFilterResult::ForwardAndIgnore + } + + fn input_event( + self: Pin<&Self>, + _: MouseEvent, + _window: &ComponentWindow, + _self_rc: &ItemRc, + ) -> InputEventResult { + InputEventResult::EventIgnored + } + + fn key_event(self: Pin<&Self>, _: &KeyEvent, _window: &ComponentWindow) -> KeyEventResult { + KeyEventResult::EventIgnored + } + + fn focus_event(self: Pin<&Self>, _: &FocusEvent, _window: &ComponentWindow) {} + + fn render(self: Pin<&Self>, backend: &mut ItemRendererRef) { + // TODO + } +} + +impl ItemConsts for Opacity { + const cached_rendering_data_offset: const_field_offset::FieldOffset< + Opacity, + CachedRenderingData, + > = Opacity::FIELD_OFFSETS.cached_rendering_data.as_unpinned_projection(); +} + +ItemVTable_static! { + /// The VTable for `Opacity` + #[no_mangle] + pub static OpacityVTable for Opacity +} + #[repr(C)] #[derive(FieldOffsets, Default, SixtyFPSElement)] #[pin] diff --git a/sixtyfps_runtime/interpreter/dynamic_component.rs b/sixtyfps_runtime/interpreter/dynamic_component.rs index c9b41c9ec..9285ff2ef 100644 --- a/sixtyfps_runtime/interpreter/dynamic_component.rs +++ b/sixtyfps_runtime/interpreter/dynamic_component.rs @@ -623,6 +623,7 @@ fn generate_component<'id>( rtti_for::(), rtti_for::(), rtti_for::(), + rtti_for::(), ] .iter() .cloned(), diff --git a/xtask/src/cbindgen.rs b/xtask/src/cbindgen.rs index 044b8d912..7c34f4d47 100644 --- a/xtask/src/cbindgen.rs +++ b/xtask/src/cbindgen.rs @@ -72,6 +72,7 @@ fn gen_corelib(root_dir: &Path, include_dir: &Path) -> anyhow::Result<()> { "BoxShadow", "FillRule", "Rotate", + "Opacity", ] .iter() .map(|x| x.to_string())