From 8a64f10e84ed858df4fa9cd02b6ada0bb6753de1 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Tue, 24 Nov 2020 16:23:37 +0100 Subject: [PATCH] Remove ComponentVtable::input_event And the custom handling of the mouse grabber --- api/sixtyfps-cpp/include/sixtyfps.h | 38 -------- api/sixtyfps-cpp/include/sixtyfps_testing.h | 6 +- api/sixtyfps-node/native/lib.rs | 3 +- api/sixtyfps-rs/lib.rs | 14 +-- sixtyfps_compiler/generator/cpp.rs | 30 +------ sixtyfps_compiler/generator/rust.rs | 33 ------- sixtyfps_runtime/corelib/component.rs | 8 -- sixtyfps_runtime/corelib/input.rs | 89 +------------------ sixtyfps_runtime/corelib/lib.rs | 1 - sixtyfps_runtime/corelib/model.rs | 11 --- sixtyfps_runtime/corelib/tests.rs | 29 ++++-- .../interpreter/dynamic_component.rs | 72 +-------------- tests/cases/bindings/override.60 | 4 +- tests/cases/bindings/two_way_binding.60 | 4 +- tests/cases/bindings/two_way_simple.60 | 4 +- tests/cases/children/children_placeholder.60 | 4 +- .../children_placeholder_two_levels.60 | 4 +- tests/cases/conditional/cast.60 | 4 +- tests/cases/conditional/expr.60 | 4 +- tests/cases/conditional/stm.60 | 4 +- tests/cases/elements/toucharea.60 | 16 ++-- tests/cases/expr/arithmetic.60 | 4 +- tests/cases/expr/comparison.60 | 4 +- tests/cases/expr/minmax.60 | 4 +- tests/cases/expr/mod.60 | 4 +- tests/cases/expr/string_concatenation.60 | 4 +- tests/cases/focus/focus_change.60 | 12 +-- .../focus/focus_change_through_signal.60 | 4 +- tests/cases/focus/initial_focus.60 | 12 +-- .../focus/initial_focus_through_component.60 | 4 +- .../focus/initial_focus_through_layout.60 | 4 +- tests/cases/imports/external_globals.60 | 4 +- tests/cases/imports/external_structs.60 | 4 +- tests/cases/imports/just_import.60 | 4 +- tests/cases/layout/box_alignment.60 | 4 +- tests/cases/layout/grid.60 | 4 +- tests/cases/layout/grid_min_max.60 | 4 +- tests/cases/layout/grid_padding.60 | 4 +- tests/cases/layout/grid_within_for.60 | 16 ++-- tests/cases/layout/horizontal_for.60 | 16 ++-- tests/cases/layout/horizontal_sizes.60 | 4 +- tests/cases/layout/nested_boxes.60 | 4 +- tests/cases/layout/nested_grid.60 | 4 +- tests/cases/layout/nested_grid_2.60 | 4 +- tests/cases/layout/nested_grid_minmax.60 | 4 +- tests/cases/layout/path.60 | 4 +- tests/cases/lookup/global_lookup.60 | 4 +- tests/cases/lookup/id_lookup.60 | 4 +- tests/cases/models/for.60 | 16 ++-- tests/cases/models/if.60 | 16 ++-- tests/cases/models/model.60 | 32 +++---- tests/cases/models/write_to_model.60 | 16 ++-- tests/cases/properties/dashes.60 | 4 +- tests/cases/properties/property_animation.60 | 4 +- tests/cases/properties/transitions.60 | 4 +- tests/cases/signals/handler.60 | 4 +- tests/cases/signals/handler_with_arg.60 | 4 +- tests/cases/text/cursor_move.60 | 6 +- tests/cases/text/default_color.60 | 4 +- tests/cases/text/surrogate_cursor.60 | 6 +- tests/cases/types/bool.60 | 4 +- tests/cases/types/duration.60 | 4 +- tests/cases/types/length.60 | 4 +- tests/cases/types/object.60 | 4 +- tests/cases/types/percent.60 | 4 +- tests/cases/types/relative_lengths.60 | 4 +- tests/cases/types/string.60 | 4 +- tests/cases/types/string_to_float.60 | 4 +- tests/cases/types/structs.60 | 4 +- 69 files changed, 213 insertions(+), 469 deletions(-) diff --git a/api/sixtyfps-cpp/include/sixtyfps.h b/api/sixtyfps-cpp/include/sixtyfps.h index 78d507a26..dafe79ce3 100644 --- a/api/sixtyfps-cpp/include/sixtyfps.h +++ b/api/sixtyfps-cpp/include/sixtyfps.h @@ -178,44 +178,6 @@ using cbindgen_private::KeyEventResult; using cbindgen_private::MouseEvent; using cbindgen_private::sixtyfps_visit_item_tree; namespace private_api { -template -inline InputEventResult process_input_event(const ComponentRc &component_rc, int64_t &mouse_grabber, - MouseEvent mouse_event, Slice tree, - GetDynamic get_dynamic, const ComponentWindow *window) -{ - if (mouse_grabber != -1) { - auto item_index = mouse_grabber & 0xffffffff; - auto rep_index = mouse_grabber >> 32; - auto offset = - cbindgen_private::sixtyfps_item_offset(component_rc.borrow(), tree, item_index); - mouse_event.pos = { mouse_event.pos.x - offset.x, mouse_event.pos.y - offset.y }; - const auto &item_node = tree.ptr[item_index]; - InputEventResult result = InputEventResult::EventIgnored; - cbindgen_private::ItemRc item_rc{component_rc, uintptr_t(item_index)}; - switch (item_node.tag) { - case ItemTreeNode::Tag::Item: - result = item_node.item.item.vtable->input_event( - { - item_node.item.item.vtable, - reinterpret_cast(component_rc.borrow().instance) - + item_node.item.item.offset, - }, - mouse_event, window, &item_rc); - break; - case ItemTreeNode::Tag::DynamicTree: { - ComponentRef comp = get_dynamic(item_node.dynamic_tree.index, rep_index); - result = comp.vtable->input_event(comp, mouse_event, window); - } break; - } - if (result != InputEventResult::GrabMouse) { - mouse_grabber = -1; - } - return result; - } else { - return cbindgen_private::sixtyfps_process_ungrabbed_mouse_event(&component_rc, mouse_event, - window, &mouse_grabber); - } -} void dealloc(const ComponentVTable *, uint8_t *ptr, vtable::Layout layout) { diff --git a/api/sixtyfps-cpp/include/sixtyfps_testing.h b/api/sixtyfps-cpp/include/sixtyfps_testing.h index 2b6aa8d70..dd6294fba 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_testing.h +++ b/api/sixtyfps-cpp/include/sixtyfps_testing.h @@ -17,11 +17,11 @@ inline void mock_elapsed_time(int64_t time_in_ms) cbindgen_private::sixtyfps_mock_elapsed_time(time_in_ms); } template -inline void send_mouse_click(const Component &component, float x, float y) +inline void send_mouse_click(const ComponentHandle *component, float x, float y) { cbindgen_private::sixtyfps_send_mouse_click( - { &Component::component_type, const_cast(&component) }, x, y, - &component.window); + reinterpret_cast*>(component), + x, y, &(*component)->window); } template diff --git a/api/sixtyfps-node/native/lib.rs b/api/sixtyfps-node/native/lib.rs index 1644dad48..5c8eb5adb 100644 --- a/api/sixtyfps-node/native/lib.rs +++ b/api/sixtyfps-node/native/lib.rs @@ -440,8 +440,9 @@ declare_types! { let lock = cx.lock(); let comp = this.borrow(&lock).0.clone(); let component = comp.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?; + let win = component.window(); run_scoped(&mut cx,this.downcast().unwrap(), || { - sixtyfps_corelib::tests::sixtyfps_send_mouse_click(component.borrow(), x, y, &component.window()); + sixtyfps_corelib::tests::sixtyfps_send_mouse_click(&vtable::VRc::into_dyn(component), x, y, &win); Ok(()) })?; Ok(JsUndefined::new().as_value(&mut cx)) diff --git a/api/sixtyfps-rs/lib.rs b/api/sixtyfps-rs/lib.rs index 950fb3ff9..88f8d4fa0 100644 --- a/api/sixtyfps-rs/lib.rs +++ b/api/sixtyfps-rs/lib.rs @@ -181,9 +181,9 @@ pub mod re_exports { PathArcTo, PathData, PathElement, PathEvent, PathLineTo, Point, Rect, Size, }; pub use sixtyfps_corelib::input::{ - process_ungrabbed_mouse_event, FocusEvent, InputEventResult, KeyCode, KeyEvent, - KeyEventResult, KeyboardModifiers, MouseEvent, ALT_MODIFIER, CONTROL_MODIFIER, - COPY_PASTE_MODIFIER, LOGO_MODIFIER, NO_MODIFIER, SHIFT_MODIFIER, + FocusEvent, InputEventResult, KeyCode, KeyEvent, KeyEventResult, KeyboardModifiers, + MouseEvent, ALT_MODIFIER, CONTROL_MODIFIER, COPY_PASTE_MODIFIER, LOGO_MODIFIER, + NO_MODIFIER, SHIFT_MODIFIER, }; pub use sixtyfps_corelib::item_tree::{ item_offset, visit_item_tree, ItemTreeNode, ItemVisitorRefMut, ItemVisitorVTable, @@ -308,17 +308,17 @@ pub mod testing { pub use sixtyfps_corelib::tests::sixtyfps_mock_elapsed_time as mock_elapsed_time; /// Simulate a mouse click pub fn send_mouse_click< - X: vtable::HasStaticVTable + HasWindow, + X: vtable::HasStaticVTable + HasWindow + 'static, >( - component: core::pin::Pin<&X>, + component: &crate::ComponentHandle, x: f32, y: f32, ) { sixtyfps_corelib::tests::sixtyfps_send_mouse_click( - vtable::VRef::new_pin(component), + &vtable::VRc::into_dyn(component.inner.clone()), x, y, - component.component_window(), + component.inner.component_window(), ); } diff --git a/sixtyfps_compiler/generator/cpp.rs b/sixtyfps_compiler/generator/cpp.rs index 1eca31be6..c8e76a2ba 100644 --- a/sixtyfps_compiler/generator/cpp.rs +++ b/sixtyfps_compiler/generator/cpp.rs @@ -1091,34 +1091,6 @@ fn generate_component( }), )); - component_struct.members.push(( - Access::Private, - Declaration::Var(Var { - ty: "int64_t".into(), - name: "mouse_grabber".into(), - init: Some("-1".into()), - }), - )); - component_struct.members.push(( - Access::Private, - Declaration::Function(Function { - name: "input_event".into(), - signature: - "(sixtyfps::private_api::ComponentRef component, sixtyfps::MouseEvent mouse_event, const sixtyfps::private_api::ComponentWindow *window) -> sixtyfps::InputEventResult" - .into(), - is_static: true, - statements: Some(vec![ - format!("auto self = reinterpret_cast<{}*>(component.instance);", component_id), - "auto self_rc = self->self_weak.lock()->into_dyn();".into(), - "return sixtyfps::private_api::process_input_event(self_rc, self->mouse_grabber, mouse_event, item_tree(), [self](int dyn_index, [[maybe_unused]] int rep_index) {".into(), - " (void)self;".into(), - format!(" switch(dyn_index) {{ {} }};", repeated_input_branch.join("")), - " return sixtyfps::private_api::ComponentRef{nullptr, nullptr};\n}, window);".into(), - ]), - ..Default::default() - }), - )); - let (apply_layout, layout_info) = compute_layout(component, &mut repeater_layout_code); component_struct.members.push(( @@ -1196,7 +1168,7 @@ fn generate_component( ty: "const sixtyfps::private_api::ComponentVTable".to_owned(), name: format!("{}::component_type", component_id), init: Some(format!( - "{{ visit_children, get_item_ref, layouting_info, apply_layout, input_event, sixtyfps::private_api::drop_in_place<{}>, sixtyfps::private_api::dealloc }}", + "{{ visit_children, get_item_ref, layouting_info, apply_layout, sixtyfps::private_api::drop_in_place<{}>, sixtyfps::private_api::dealloc }}", component_id) ), })); diff --git a/sixtyfps_compiler/generator/rust.rs b/sixtyfps_compiler/generator/rust.rs index 7c6ff9955..f08b56a1c 100644 --- a/sixtyfps_compiler/generator/rust.rs +++ b/sixtyfps_compiler/generator/rust.rs @@ -682,37 +682,6 @@ fn generate_component( } } - fn input_event(self: ::core::pin::Pin<&Self>, mouse_event : sixtyfps::re_exports::MouseEvent, window: &sixtyfps::re_exports::ComponentWindow) -> sixtyfps::re_exports::InputEventResult { - use sixtyfps::re_exports::*; - let mouse_grabber = self.mouse_grabber.get(); - let self_rc = VRc::into_dyn(self.as_ref().self_weak.get().unwrap().upgrade().unwrap()); - #[allow(unused)] - let (status, new_grab) = if let Some((item_index, rep_index)) = mouse_grabber.aborted_indexes() { - let tree = Self::item_tree(); - let offset = item_offset(self, tree, item_index); - let mut event = mouse_event.clone(); - event.pos -= offset.to_vector(); - let res = match tree[item_index] { - ItemTreeNode::Item { item, .. } => { - item.apply_pin(self).as_ref().input_event(event, window, &ItemRc::new(self_rc, item_index)) - } - ItemTreeNode::DynamicTree { index } => { - match index { - #(#repeated_input_branch)* - _ => panic!("invalid index {}", index), - } - } - }; - match res { - InputEventResult::GrabMouse => (res, mouse_grabber), - _ => (res, VisitChildrenResult::CONTINUE), - } - } else { - process_ungrabbed_mouse_event(&self_rc, mouse_event, window) - }; - self.mouse_grabber.set(new_grab); - status - } #layouts @@ -769,7 +738,6 @@ fn generate_component( #(#repeated_element_names : sixtyfps::re_exports::Repeater<#repeated_element_components>,)* #(#self_weak : sixtyfps::re_exports::OnceCell>,)* #(parent : sixtyfps::re_exports::VWeak,)* - mouse_grabber: ::core::cell::Cell, #(#global_name : ::core::pin::Pin<::std::rc::Rc<#global_type>>,)* #window_field } @@ -789,7 +757,6 @@ fn generate_component( #(#repeated_element_names : ::core::default::Default::default(),)* #(#self_weak : ::core::default::Default::default(),)* #(parent : parent as sixtyfps::re_exports::VWeak::,)* - mouse_grabber: ::core::cell::Cell::new(sixtyfps::re_exports::VisitChildrenResult::CONTINUE), #(#global_name : #global_type::new(),)* #window_field_init }; diff --git a/sixtyfps_runtime/corelib/component.rs b/sixtyfps_runtime/corelib/component.rs index b15807467..b2254e332 100644 --- a/sixtyfps_runtime/corelib/component.rs +++ b/sixtyfps_runtime/corelib/component.rs @@ -13,7 +13,6 @@ LICENSE END */ use crate::eventloop::ComponentWindow; use crate::graphics::Rect; -use crate::input::{InputEventResult, MouseEvent}; use crate::item_tree::{ItemVisitorVTable, TraversalOrder, VisitChildrenResult}; use crate::items::ItemVTable; use crate::layout::LayoutInfo; @@ -45,13 +44,6 @@ pub struct ComponentVTable { /// Apply the layout to all the items in the component, and set the geometry of the root to the given rect pub apply_layout: extern "C" fn(core::pin::Pin>, Rect), - /// input event - pub input_event: extern "C" fn( - core::pin::Pin>, - MouseEvent, - &ComponentWindow, - ) -> InputEventResult, - /// in-place destructor (for VRc) pub drop_in_place: unsafe fn(VRefMut) -> vtable::Layout, /// dealloc function (for VRc) diff --git a/sixtyfps_runtime/corelib/input.rs b/sixtyfps_runtime/corelib/input.rs index e6a69ba9a..93224cbcf 100644 --- a/sixtyfps_runtime/corelib/input.rs +++ b/sixtyfps_runtime/corelib/input.rs @@ -13,7 +13,7 @@ LICENSE END */ use crate::component::ComponentRc; use crate::graphics::Point; -use crate::item_tree::{ItemVisitorResult, VisitChildrenResult}; +use crate::item_tree::ItemVisitorResult; use crate::items::{ItemRc, ItemRef, ItemWeak}; use euclid::default::Vector2D; use sixtyfps_corelib_macros::*; @@ -464,66 +464,6 @@ pub enum FocusEvent { WindowLostFocus, } -/// Feed the given mouse event into the tree of items that component holds. The -/// event will be delivered to items in front first. -/// -/// The returned tuple is identical with the tuple the ItemVTable's input_event returns, -/// indicating the acceptance or potential mouse grabbing as well as how to proceed -/// in the event of recursive item tree traversal. -/// -/// Arguments: -/// * `component`: The component to deliver the event to. -/// * `event`: The mouse event to deliver. -pub fn process_ungrabbed_mouse_event( - component: &ComponentRc, - event: MouseEvent, - window: &crate::eventloop::ComponentWindow, -) -> (InputEventResult, VisitChildrenResult) { - let offset = Vector2D::new(0., 0.); - - let mut result = InputEventResult::EventIgnored; - let item_index = crate::item_tree::visit_items( - component, - crate::item_tree::TraversalOrder::FrontToBack, - |comp_rc, item, item_index, offset| -> ItemVisitorResult> { - let geom = item.as_ref().geometry(); - let geom = geom.translate(*offset); - - if geom.contains(event.pos) { - let mut event2 = event.clone(); - event2.pos -= geom.origin.to_vector(); - match item.as_ref().input_event( - event2, - window, - &crate::items::ItemRc::new(comp_rc.clone(), item_index), - ) { - InputEventResult::EventAccepted => { - result = InputEventResult::EventAccepted; - return ItemVisitorResult::Abort; - } - InputEventResult::EventIgnored => (), - InputEventResult::GrabMouse => { - result = InputEventResult::GrabMouse; - return ItemVisitorResult::Abort; - } - }; - } - - ItemVisitorResult::Continue(geom.origin.to_vector()) - }, - offset, - ); - - ( - result, - if result == InputEventResult::GrabMouse { - item_index - } else { - VisitChildrenResult::CONTINUE - }, - ) -} - /// Process the `mouse_event` on the `component`, the `mouse_grabber_stack` is the prebious stack /// of mouse grabber. /// Returns a new mouse grabber stack. @@ -593,30 +533,3 @@ pub fn process_mouse_input( result } - -pub(crate) mod ffi { - use super::*; - - #[no_mangle] - pub extern "C" fn sixtyfps_process_ungrabbed_mouse_event( - component: &ComponentRc, - event: MouseEvent, - window: &crate::eventloop::ComponentWindow, - new_mouse_grabber: &mut crate::item_tree::VisitChildrenResult, - ) -> InputEventResult { - let (res, grab) = process_ungrabbed_mouse_event(component, event, window); - *new_mouse_grabber = grab; - res - } - /* - #[no_mangle] - pub extern "C" fn sixtyfps_process_grabbed_mouse_event( - component: ComponentRefPin, - item: core::pin::Pin, - offset: Point, - event: MouseEvent, - old_grab: VisitChildrenResult, - ) -> (InputEventResult, crate::item_tree::VisitChildrenResult) { - process_grabbed_mouse_event(component, item, offset, event, old_grab) - }*/ -} diff --git a/sixtyfps_runtime/corelib/lib.rs b/sixtyfps_runtime/corelib/lib.rs index 49d1f9e42..4f665d74b 100644 --- a/sixtyfps_runtime/corelib/lib.rs +++ b/sixtyfps_runtime/corelib/lib.rs @@ -84,6 +84,5 @@ pub fn use_modules() -> usize { + properties::ffi::sixtyfps_property_init as usize + string::ffi::sixtyfps_shared_string_bytes as usize + eventloop::ffi::sixtyfps_component_window_drop as usize - + input::ffi::sixtyfps_process_ungrabbed_mouse_event as usize + component::ffi::sixtyfps_component_init_items as usize } diff --git a/sixtyfps_runtime/corelib/model.rs b/sixtyfps_runtime/corelib/model.rs index 432d0edf5..6c4fc5318 100644 --- a/sixtyfps_runtime/corelib/model.rs +++ b/sixtyfps_runtime/corelib/model.rs @@ -555,17 +555,6 @@ impl Repeater { crate::item_tree::VisitChildrenResult::CONTINUE } - /// Forward an input event to a particular item - pub fn input_event( - &self, - idx: usize, - event: crate::input::MouseEvent, - window: &crate::eventloop::ComponentWindow, - ) -> crate::input::InputEventResult { - let c = self.inner.borrow().borrow().components[idx].1.clone(); - c.map_or(Default::default(), |c| c.as_pin_ref().input_event(event, window)) - } - /// Return the amount of item currently in the component pub fn len(&self) -> usize { self.inner.borrow().borrow().components.len() diff --git a/sixtyfps_runtime/corelib/tests.rs b/sixtyfps_runtime/corelib/tests.rs index 31c22e587..6f383f1e4 100644 --- a/sixtyfps_runtime/corelib/tests.rs +++ b/sixtyfps_runtime/corelib/tests.rs @@ -28,17 +28,36 @@ pub extern "C" fn sixtyfps_mock_elapsed_time(time_in_ms: u64) { /// Simulate a click on a position within the component. #[no_mangle] pub extern "C" fn sixtyfps_send_mouse_click( - component: core::pin::Pin, + component: &crate::component::ComponentRc, x: f32, y: f32, window: &crate::eventloop::ComponentWindow, ) { - component.as_ref().apply_layout(window.0.get_geometry()); + let mut mouse_grabber = Vec::new(); + vtable::VRc::borrow_pin(component).as_ref().apply_layout(window.0.get_geometry()); + let pos = euclid::point2(x, y); - component.as_ref().input_event(MouseEvent { pos, what: MouseEventType::MouseMoved }, window); - component.as_ref().input_event(MouseEvent { pos, what: MouseEventType::MousePressed }, window); + + mouse_grabber = crate::input::process_mouse_input( + component.clone(), + MouseEvent { pos, what: MouseEventType::MouseMoved }, + window, + mouse_grabber, + ); + mouse_grabber = crate::input::process_mouse_input( + component.clone(), + MouseEvent { pos, what: MouseEventType::MousePressed }, + window, + mouse_grabber, + ); sixtyfps_mock_elapsed_time(50); - component.as_ref().input_event(MouseEvent { pos, what: MouseEventType::MouseReleased }, window); + mouse_grabber = crate::input::process_mouse_input( + component.clone(), + MouseEvent { pos, what: MouseEventType::MouseReleased }, + window, + mouse_grabber, + ); + drop(mouse_grabber); } /// Simulate a change in keyboard modifiers pressed. diff --git a/sixtyfps_runtime/interpreter/dynamic_component.rs b/sixtyfps_runtime/interpreter/dynamic_component.rs index a2ed5740e..086a603f5 100644 --- a/sixtyfps_runtime/interpreter/dynamic_component.rs +++ b/sixtyfps_runtime/interpreter/dynamic_component.rs @@ -21,7 +21,6 @@ use sixtyfps_compilerlib::*; use sixtyfps_corelib::component::{Component, ComponentRefPin, ComponentVTable}; use sixtyfps_corelib::eventloop::ComponentWindow; use sixtyfps_corelib::graphics::{Rect, Resource}; -use sixtyfps_corelib::input::{InputEventResult, MouseEvent}; use sixtyfps_corelib::item_tree::{ ItemTreeNode, ItemVisitorRefMut, ItemVisitorVTable, TraversalOrder, VisitChildrenResult, }; @@ -203,14 +202,6 @@ impl Component for ErasedComponentBox { self.borrow().as_ref().visit_children_item(index, order, visitor) } - fn input_event( - self: Pin<&Self>, - mouse_event: sixtyfps_corelib::input::MouseEvent, - window: &ComponentWindow, - ) -> sixtyfps_corelib::input::InputEventResult { - self.borrow().as_ref().input_event(mouse_event, window) - } - fn layout_info(self: Pin<&Self>) -> sixtyfps_corelib::layout::LayoutInfo { self.borrow().as_ref().layout_info() } @@ -228,7 +219,6 @@ impl Component for ErasedComponentBox { sixtyfps_corelib::ComponentVTable_static!(static COMPONENT_BOX_VT for ErasedComponentBox); pub(crate) struct ComponentExtraData { - mouse_grabber: core::cell::Cell, pub(crate) globals: HashMap>>, pub(crate) self_weak: once_cell::unsync::OnceCell>, @@ -236,11 +226,7 @@ pub(crate) struct ComponentExtraData { impl Default for ComponentExtraData { fn default() -> Self { - Self { - mouse_grabber: core::cell::Cell::new(VisitChildrenResult::CONTINUE), - globals: HashMap::new(), - self_weak: Default::default(), - } + Self { globals: HashMap::new(), self_weak: Default::default() } } } @@ -687,7 +673,6 @@ fn generate_component<'id>( visit_children_item, layout_info, apply_layout, - input_event, get_item_ref, drop_in_place, dealloc, @@ -1441,53 +1426,6 @@ pub fn get_repeater_by_name<'a, 'id>( (rep_in_comp.offset.apply_pin(instance_ref.instance), rep_in_comp.component_to_repeat.clone()) } -extern "C" fn input_event( - component: ComponentRefPin, - mouse_event: sixtyfps_corelib::input::MouseEvent, - window: &sixtyfps_corelib::eventloop::ComponentWindow, -) -> sixtyfps_corelib::input::InputEventResult { - // This is fine since we can only be called with a component that with our vtable which is a ComponentDescription - let component_type = unsafe { get_component_type(component) }; - let instance = unsafe { Pin::new_unchecked(&*component.as_ptr().cast::()) }; - let extra_data = component_type.extra_data_offset.apply(&*instance); - generativity::make_guard!(guard); - let instance_ref = unsafe { InstanceRef::from_pin_ref(component, guard) }; - let comp_rc = instance_ref.self_weak().get().unwrap().upgrade().unwrap(); - - let mouse_grabber = extra_data.mouse_grabber.get(); - let (status, new_grab) = if let Some((item_index, rep_index)) = mouse_grabber.aborted_indexes() - { - let tree = &component_type.item_tree; - let offset = sixtyfps_corelib::item_tree::item_offset(instance, tree, item_index); - let mut event = mouse_event.clone(); - event.pos -= offset.to_vector(); - let res = match tree[item_index] { - ItemTreeNode::Item { item, .. } => item.apply_pin(instance).as_ref().input_event( - event, - window, - &sixtyfps_corelib::items::ItemRc::new(vtable::VRc::into_dyn(comp_rc), item_index), - ), - ItemTreeNode::DynamicTree { index } => { - generativity::make_guard!(guard); - let rep_in_comp = component_type.repeater[index].unerase(guard); - rep_in_comp.offset.apply_pin(instance).input_event(rep_index, event, window) - } - }; - match res { - sixtyfps_corelib::input::InputEventResult::GrabMouse => (res, mouse_grabber), - _ => (res, VisitChildrenResult::CONTINUE), - } - } else { - sixtyfps_corelib::input::process_ungrabbed_mouse_event( - &vtable::VRc::into_dyn(comp_rc), - mouse_event, - window, - ) - }; - extra_data.mouse_grabber.set(new_grab); - status -} - extern "C" fn layout_info(component: ComponentRefPin) -> LayoutInfo { generativity::make_guard!(guard); // This is fine since we can only be called with a component that with our vtable which is a ComponentDescription @@ -1553,14 +1491,6 @@ unsafe extern "C" fn dealloc(_vtable: &ComponentVTable, ptr: *mut u8, layout: vt std::alloc::dealloc(ptr, layout.try_into().unwrap()); } -/// Get the component description from a ComponentRef -/// -/// Safety: the component must have been created by the interpreter -pub unsafe fn get_component_type<'a>(component: ComponentRefPin<'a>) -> &'a ComponentDescription { - &*(Pin::into_inner_unchecked(component).get_vtable() as *const ComponentVTable - as *const ComponentDescription) -} - #[derive(Copy, Clone)] pub struct InstanceRef<'a, 'id> { pub instance: Pin<&'a Instance<'id>>, diff --git a/tests/cases/bindings/override.60 b/tests/cases/bindings/override.60 index f8095cabc..0180d8475 100644 --- a/tests/cases/bindings/override.60 +++ b/tests/cases/bindings/override.60 @@ -27,8 +27,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_prop_a(), 1); assert_eq!(instance.get_prop_b(), 2); ``` diff --git a/tests/cases/bindings/two_way_binding.60 b/tests/cases/bindings/two_way_binding.60 index e615db286..78c77c57c 100644 --- a/tests/cases/bindings/two_way_binding.60 +++ b/tests/cases/bindings/two_way_binding.60 @@ -63,8 +63,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_text1(), sixtyfps::SharedString::from("Hello")); assert_eq!(instance.get_text2(), sixtyfps::SharedString::from("Blah")); assert_eq!(instance.get_ti1_text(), sixtyfps::SharedString::from("Hello")); diff --git a/tests/cases/bindings/two_way_simple.60 b/tests/cases/bindings/two_way_simple.60 index 5dd52b974..02e2e5459 100644 --- a/tests/cases/bindings/two_way_simple.60 +++ b/tests/cases/bindings/two_way_simple.60 @@ -29,8 +29,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_sub_width1(), 80.); assert_eq!(instance.get_sub_width2(), 80.); instance.set_sub_width1(99.); diff --git a/tests/cases/children/children_placeholder.60 b/tests/cases/children/children_placeholder.60 index db8854904..f85db2951 100644 --- a/tests/cases/children/children_placeholder.60 +++ b/tests/cases/children/children_placeholder.60 @@ -42,8 +42,8 @@ assert(instance.get_rect1_pos_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 200.))); assert!(instance.get_rect1_pos_ok()); diff --git a/tests/cases/children/children_placeholder_two_levels.60 b/tests/cases/children/children_placeholder_two_levels.60 index b1e785f7e..9133cb8d9 100644 --- a/tests/cases/children/children_placeholder_two_levels.60 +++ b/tests/cases/children/children_placeholder_two_levels.60 @@ -50,8 +50,8 @@ assert(instance.get_rect1_pos_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 200.))); assert!(instance.get_rect1_pos_ok()); diff --git a/tests/cases/conditional/cast.60 b/tests/cases/conditional/cast.60 index 6ba967a98..7e66b0882 100644 --- a/tests/cases/conditional/cast.60 +++ b/tests/cases/conditional/cast.60 @@ -31,8 +31,8 @@ assert_eq(instance.get_s1(), "123"); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); instance.set_condition(true); assert_eq!(instance.get_s1(), "abc"); assert_eq!(instance.get_s2(), "123"); diff --git a/tests/cases/conditional/expr.60 b/tests/cases/conditional/expr.60 index 57cb3150c..542520ea0 100644 --- a/tests/cases/conditional/expr.60 +++ b/tests/cases/conditional/expr.60 @@ -29,8 +29,8 @@ assert_eq(instance.get_test_value2(), 3); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); instance.set_condition(true); assert_eq!(instance.get_test_value(), 1); assert_eq!(instance.get_test_value2(), 2); diff --git a/tests/cases/conditional/stm.60 b/tests/cases/conditional/stm.60 index 1d0305a09..a8e49eb54 100644 --- a/tests/cases/conditional/stm.60 +++ b/tests/cases/conditional/stm.60 @@ -55,8 +55,8 @@ assert_eq(instance.get_result(), 5+33-1); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); instance.emit_action(); assert_eq!(instance.get_result(), 3); instance.set_value(5); diff --git a/tests/cases/elements/toucharea.60 b/tests/cases/elements/toucharea.60 index 065759274..9998a662a 100644 --- a/tests/cases/elements/toucharea.60 +++ b/tests/cases/elements/toucharea.60 @@ -33,37 +33,37 @@ auto handle = TestCase::create(); const TestCase &instance = *handle; // does not click on anything -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq(instance.get_touch1(), 0); assert_eq(instance.get_touch2(), 0); // click on second one -sixtyfps::testing::send_mouse_click(instance, 101., 101.); +sixtyfps::testing::send_mouse_click(&handle, 101., 101.); assert_eq(instance.get_touch1(), 0); assert_eq(instance.get_touch2(), 1); // click on first one only -sixtyfps::testing::send_mouse_click(instance, 108., 108.); +sixtyfps::testing::send_mouse_click(&handle, 108., 108.); assert_eq(instance.get_touch1(), 1); assert_eq(instance.get_touch2(), 1); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); // does not click on anything -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq!(instance.get_touch1(), 0); assert_eq!(instance.get_touch2(), 0); // click on second one -sixtyfps::testing::send_mouse_click(instance, 101., 101.); +sixtyfps::testing::send_mouse_click(&handle, 101., 101.); assert_eq!(instance.get_touch1(), 0); assert_eq!(instance.get_touch2(), 1); // click on first one only -sixtyfps::testing::send_mouse_click(instance, 108., 108.); +sixtyfps::testing::send_mouse_click(&handle, 108., 108.); assert_eq!(instance.get_touch1(), 1); assert_eq!(instance.get_touch2(), 1); ``` diff --git a/tests/cases/expr/arithmetic.60 b/tests/cases/expr/arithmetic.60 index b02b846e9..2a9a63dab 100644 --- a/tests/cases/expr/arithmetic.60 +++ b/tests/cases/expr/arithmetic.60 @@ -37,8 +37,8 @@ assert_eq(instance.get_a(), (((42 + 8) * 10) / 2) - 3); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_t1(), 4 + 3 * 2 + 2 - 50 - 2); assert_eq!(instance.get_t2(), 500 / 2 * 30 - 1); instance.set_a(42); diff --git a/tests/cases/expr/comparison.60 b/tests/cases/expr/comparison.60 index e2e9d4a61..86e03b56e 100644 --- a/tests/cases/expr/comparison.60 +++ b/tests/cases/expr/comparison.60 @@ -68,8 +68,8 @@ assert_eq(instance.get_t6(), true); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_t1(), true); assert_eq!(instance.get_t2(), false); diff --git a/tests/cases/expr/minmax.60 b/tests/cases/expr/minmax.60 index e370aa87a..2b1443977 100644 --- a/tests/cases/expr/minmax.60 +++ b/tests/cases/expr/minmax.60 @@ -22,8 +22,8 @@ assert_eq(instance.get_t2(), true); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_t1(), 98.5); assert_eq!(instance.get_t2(), true); ``` diff --git a/tests/cases/expr/mod.60 b/tests/cases/expr/mod.60 index cd2a151c5..37c8afe3a 100644 --- a/tests/cases/expr/mod.60 +++ b/tests/cases/expr/mod.60 @@ -23,8 +23,8 @@ assert_eq(instance.get_t3(),3); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_t1(), 0); assert_eq!(instance.get_t2(), 8.0); assert_eq!(instance.get_t3(), 3); diff --git a/tests/cases/expr/string_concatenation.60 b/tests/cases/expr/string_concatenation.60 index 587342003..66737fedc 100644 --- a/tests/cases/expr/string_concatenation.60 +++ b/tests/cases/expr/string_concatenation.60 @@ -36,8 +36,8 @@ assert_eq(instance.get_s4(), sixtyfps::SharedString("ayoxxx")); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_s1(), sixtyfps::SharedString::from("hello1212")); assert_eq!(instance.get_s2(), sixtyfps::SharedString::from("10hello5.1")); instance.set_a(42); diff --git a/tests/cases/focus/focus_change.60 b/tests/cases/focus/focus_change.60 index c66f1219c..698369391 100644 --- a/tests/cases/focus/focus_change.60 +++ b/tests/cases/focus/focus_change.60 @@ -30,12 +30,12 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert!(!instance.get_input1_focused()); assert!(!instance.get_input2_focused()); -sixtyfps::testing::send_mouse_click(instance, 150., 100.); +sixtyfps::testing::send_mouse_click(&handle, 150., 100.); assert!(instance.get_input1_focused()); assert!(!instance.get_input2_focused()); @@ -43,7 +43,7 @@ sixtyfps::testing::send_keyboard_string_sequence(instance, "Only for field 1"); assert_eq!(instance.get_input1_text(), "Only for field 1"); assert_eq!(instance.get_input2_text(), ""); -sixtyfps::testing::send_mouse_click(instance, 150., 300.); +sixtyfps::testing::send_mouse_click(&handle, 150., 300.); assert!(!instance.get_input1_focused()); assert!(instance.get_input2_focused()); @@ -58,7 +58,7 @@ const TestCase &instance = *handle; assert(!instance.get_input1_focused()); assert(!instance.get_input2_focused()); -sixtyfps::testing::send_mouse_click(instance, 150., 100.); +sixtyfps::testing::send_mouse_click(&handle, 150., 100.); assert(instance.get_input1_focused()); assert(!instance.get_input2_focused()); @@ -66,7 +66,7 @@ sixtyfps::testing::send_keyboard_string_sequence(instance, "Only for field 1"); assert_eq(instance.get_input1_text(), "Only for field 1"); assert_eq(instance.get_input2_text(), ""); -sixtyfps::testing::send_mouse_click(instance, 150., 300.); +sixtyfps::testing::send_mouse_click(&handle, 150., 300.); assert(!instance.get_input1_focused()); assert(instance.get_input2_focused()); diff --git a/tests/cases/focus/focus_change_through_signal.60 b/tests/cases/focus/focus_change_through_signal.60 index b8950e8f2..642015c67 100644 --- a/tests/cases/focus/focus_change_through_signal.60 +++ b/tests/cases/focus/focus_change_through_signal.60 @@ -36,8 +36,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert!(!instance.get_input1_focused()); assert!(!instance.get_input2_focused()); diff --git a/tests/cases/focus/initial_focus.60 b/tests/cases/focus/initial_focus.60 index 0cf924553..1291f88d9 100644 --- a/tests/cases/focus/initial_focus.60 +++ b/tests/cases/focus/initial_focus.60 @@ -31,8 +31,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert!(instance.get_input1_focused()); assert!(!instance.get_input2_focused()); @@ -40,11 +40,11 @@ sixtyfps::testing::send_keyboard_string_sequence(instance, "Only for field 1"); assert_eq!(instance.get_input1_text(), "Only for field 1"); assert_eq!(instance.get_input2_text(), ""); -sixtyfps::testing::send_mouse_click(instance, 150., 100.); +sixtyfps::testing::send_mouse_click(&handle, 150., 100.); assert!(instance.get_input1_focused()); assert!(!instance.get_input2_focused()); -sixtyfps::testing::send_mouse_click(instance, 150., 300.); +sixtyfps::testing::send_mouse_click(&handle, 150., 300.); assert!(!instance.get_input1_focused()); assert!(instance.get_input2_focused()); ``` @@ -59,11 +59,11 @@ sixtyfps::testing::send_keyboard_string_sequence(instance, "Only for field 1"); assert_eq(instance.get_input1_text(), "Only for field 1"); assert_eq(instance.get_input2_text(), ""); -sixtyfps::testing::send_mouse_click(instance, 150., 100.); +sixtyfps::testing::send_mouse_click(&handle, 150., 100.); assert(instance.get_input1_focused()); assert(!instance.get_input2_focused()); -sixtyfps::testing::send_mouse_click(instance, 150., 300.); +sixtyfps::testing::send_mouse_click(&handle, 150., 300.); assert(!instance.get_input1_focused()); assert(instance.get_input2_focused()); ``` diff --git a/tests/cases/focus/initial_focus_through_component.60 b/tests/cases/focus/initial_focus_through_component.60 index ecc64cce4..da06ee4f2 100644 --- a/tests/cases/focus/initial_focus_through_component.60 +++ b/tests/cases/focus/initial_focus_through_component.60 @@ -30,8 +30,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert!(!instance.get_input1_focused()); assert!(instance.get_input2_focused()); ``` diff --git a/tests/cases/focus/initial_focus_through_layout.60 b/tests/cases/focus/initial_focus_through_layout.60 index 54d72bcd2..542f8c4da 100644 --- a/tests/cases/focus/initial_focus_through_layout.60 +++ b/tests/cases/focus/initial_focus_through_layout.60 @@ -32,8 +32,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert!(!instance.get_input1_focused()); assert!(instance.get_input2_focused()); ``` diff --git a/tests/cases/imports/external_globals.60 b/tests/cases/imports/external_globals.60 index 53ac93e29..f15f0dea7 100644 --- a/tests/cases/imports/external_globals.60 +++ b/tests/cases/imports/external_globals.60 @@ -24,8 +24,8 @@ assert_eq(instance.get_p2(), 44); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_p1(), 42); assert_eq!(instance.get_p2(), 44); ``` diff --git a/tests/cases/imports/external_structs.60 b/tests/cases/imports/external_structs.60 index 6d5817f5a..6b639e965 100644 --- a/tests/cases/imports/external_structs.60 +++ b/tests/cases/imports/external_structs.60 @@ -27,8 +27,8 @@ assert_eq(instance.get_exp().e.a, 2001); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_p1(), 2003); assert_eq!(instance.get_exp().e.a, 2001); ``` diff --git a/tests/cases/imports/just_import.60 b/tests/cases/imports/just_import.60 index b6ff6737c..fdd2c1686 100644 --- a/tests/cases/imports/just_import.60 +++ b/tests/cases/imports/just_import.60 @@ -19,8 +19,8 @@ assert_eq(instance.get_some_prop(), 42); ``` ```rust -let instance = MainWindow::new(); -let instance = instance.as_ref(); +let handle = MainWindow::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_some_prop(), 42); ``` diff --git a/tests/cases/layout/box_alignment.60 b/tests/cases/layout/box_alignment.60 index f4693e115..f5d0cee8b 100644 --- a/tests/cases/layout/box_alignment.60 +++ b/tests/cases/layout/box_alignment.60 @@ -87,8 +87,8 @@ assert(instance.get_c1()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_v1()); diff --git a/tests/cases/layout/grid.60 b/tests/cases/layout/grid.60 index b22160e2b..f523cf3ad 100644 --- a/tests/cases/layout/grid.60 +++ b/tests/cases/layout/grid.60 @@ -51,8 +51,8 @@ assert_eq(instance.get_layout_width(), 300); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_rect1_pos_ok()); diff --git a/tests/cases/layout/grid_min_max.60 b/tests/cases/layout/grid_min_max.60 index 29a6797e1..9acd4df24 100644 --- a/tests/cases/layout/grid_min_max.60 +++ b/tests/cases/layout/grid_min_max.60 @@ -62,8 +62,8 @@ assert(instance.get_rect3_pos_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_rect1_pos_ok()); diff --git a/tests/cases/layout/grid_padding.60 b/tests/cases/layout/grid_padding.60 index caa2fc97b..3f4746e96 100644 --- a/tests/cases/layout/grid_padding.60 +++ b/tests/cases/layout/grid_padding.60 @@ -65,8 +65,8 @@ assert(instance.get_rect2_pos_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_rect1_pos_ok()); diff --git a/tests/cases/layout/grid_within_for.60 b/tests/cases/layout/grid_within_for.60 index ab9c17ef3..ecce0fd2d 100644 --- a/tests/cases/layout/grid_within_for.60 +++ b/tests/cases/layout/grid_within_for.60 @@ -40,29 +40,29 @@ TestCase := Rectangle { ```cpp auto handle = TestCase::create(); const TestCase &instance = *handle; -sixtyfps::testing::send_mouse_click(instance, -1., -1.); // FIXME: Force creation of repeater components before computing the layout +sixtyfps::testing::send_mouse_click(&handle, -1., -1.); // FIXME: Force creation of repeater components before computing the layout TestCase::apply_layout({&TestCase::component_type, const_cast(&instance) }, sixtyfps::Rect{0, 0, 300, 300}); -sixtyfps::testing::send_mouse_click(instance, 190., 190.); +sixtyfps::testing::send_mouse_click(&handle, 190., 190.); assert_eq(instance.get_value(), 1+1); -sixtyfps::testing::send_mouse_click(instance, 5., 290.); +sixtyfps::testing::send_mouse_click(&handle, 5., 290.); assert_eq(instance.get_value(), 1+1+2); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; -sixtyfps::testing::send_mouse_click(instance, -1., -1.); // FIXME: Force creation of repeater components before computing the layout +sixtyfps::testing::send_mouse_click(&handle, -1., -1.); // FIXME: Force creation of repeater components before computing the layout instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); -sixtyfps::testing::send_mouse_click(instance, 190., 190.); +sixtyfps::testing::send_mouse_click(&handle, 190., 190.); assert_eq!(instance.get_value(), 1+1); -sixtyfps::testing::send_mouse_click(instance, 5., 290.); +sixtyfps::testing::send_mouse_click(&handle, 5., 290.); assert_eq!(instance.get_value(), 1+1+2); ``` diff --git a/tests/cases/layout/horizontal_for.60 b/tests/cases/layout/horizontal_for.60 index 4cf15d4d1..711be882c 100644 --- a/tests/cases/layout/horizontal_for.60 +++ b/tests/cases/layout/horizontal_for.60 @@ -43,28 +43,28 @@ export TestCase := Rectangle { auto handle = TestCase::create(); const TestCase &instance = *handle; -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq(instance.get_value(), -10); -sixtyfps::testing::send_mouse_click(instance, 25., 25.); +sixtyfps::testing::send_mouse_click(&handle, 25., 25.); assert_eq(instance.get_value(), 8); -sixtyfps::testing::send_mouse_click(instance, 45., 15.); +sixtyfps::testing::send_mouse_click(&handle, 45., 15.); assert_eq(instance.get_value(), 9); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq!(instance.get_value(), -10); -sixtyfps::testing::send_mouse_click(instance, 25., 25.); +sixtyfps::testing::send_mouse_click(&handle, 25., 25.); assert_eq!(instance.get_value(), 8); -sixtyfps::testing::send_mouse_click(instance, 45., 15.); +sixtyfps::testing::send_mouse_click(&handle, 45., 15.); assert_eq!(instance.get_value(), 9); ``` diff --git a/tests/cases/layout/horizontal_sizes.60 b/tests/cases/layout/horizontal_sizes.60 index 92a5f879b..22dc5747c 100644 --- a/tests/cases/layout/horizontal_sizes.60 +++ b/tests/cases/layout/horizontal_sizes.60 @@ -80,8 +80,8 @@ assert(instance.get_pink_rect_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_blue_rect_ok()); diff --git a/tests/cases/layout/nested_boxes.60 b/tests/cases/layout/nested_boxes.60 index 8022af715..f699517e9 100644 --- a/tests/cases/layout/nested_boxes.60 +++ b/tests/cases/layout/nested_boxes.60 @@ -142,8 +142,8 @@ assert(instance.get_rect_black2_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_rect_blue_ok()); diff --git a/tests/cases/layout/nested_grid.60 b/tests/cases/layout/nested_grid.60 index 266df8e57..6f893af91 100644 --- a/tests/cases/layout/nested_grid.60 +++ b/tests/cases/layout/nested_grid.60 @@ -56,8 +56,8 @@ assert(instance.get_rect6_pos_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_rect1_pos_ok()); diff --git a/tests/cases/layout/nested_grid_2.60 b/tests/cases/layout/nested_grid_2.60 index 48edb0a77..85603fbf2 100644 --- a/tests/cases/layout/nested_grid_2.60 +++ b/tests/cases/layout/nested_grid_2.60 @@ -64,8 +64,8 @@ assert(instance.get_rect4_pos_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_rect1_pos_ok()); diff --git a/tests/cases/layout/nested_grid_minmax.60 b/tests/cases/layout/nested_grid_minmax.60 index bb1f4e8de..90901a5ff 100644 --- a/tests/cases/layout/nested_grid_minmax.60 +++ b/tests/cases/layout/nested_grid_minmax.60 @@ -51,8 +51,8 @@ assert(instance.get_rect2_pos_ok()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_rect1_pos_ok()); diff --git a/tests/cases/layout/path.60 b/tests/cases/layout/path.60 index 78c46b473..2c1d5ea5f 100644 --- a/tests/cases/layout/path.60 +++ b/tests/cases/layout/path.60 @@ -95,8 +95,8 @@ assert(instance.get_test5()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); use sixtyfps::re_exports::Component; instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); assert!(instance.get_test1()); diff --git a/tests/cases/lookup/global_lookup.60 b/tests/cases/lookup/global_lookup.60 index 1e771b822..b4cf58c45 100644 --- a/tests/cases/lookup/global_lookup.60 +++ b/tests/cases/lookup/global_lookup.60 @@ -43,8 +43,8 @@ assert_eq(instance.get_p2(), 3); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_p1(), 51); assert_eq!(instance.get_p2(), 3); ``` diff --git a/tests/cases/lookup/id_lookup.60 b/tests/cases/lookup/id_lookup.60 index 95a65e258..35ea4330a 100644 --- a/tests/cases/lookup/id_lookup.60 +++ b/tests/cases/lookup/id_lookup.60 @@ -29,8 +29,8 @@ assert_eq(instance.get_p2(), 5930); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_p1(), 5770); assert_eq!(instance.get_p2(), 5930); ``` diff --git a/tests/cases/models/for.60 b/tests/cases/models/for.60 index f8005a265..666c10232 100644 --- a/tests/cases/models/for.60 +++ b/tests/cases/models/for.60 @@ -95,28 +95,28 @@ export TestCase := Rectangle { auto handle = TestCase::create(); const TestCase &instance = *handle; -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq(instance.get_value(), 10); -sixtyfps::testing::send_mouse_click(instance, 15., 15.); +sixtyfps::testing::send_mouse_click(&handle, 15., 15.); assert_eq(instance.get_value(), 13); -sixtyfps::testing::send_mouse_click(instance, 5., 15.); +sixtyfps::testing::send_mouse_click(&handle, 5., 15.); assert_eq(instance.get_value(), 13+42); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq!(instance.get_value(), 10); -sixtyfps::testing::send_mouse_click(instance, 15., 15.); +sixtyfps::testing::send_mouse_click(&handle, 15., 15.); assert_eq!(instance.get_value(), 13); -sixtyfps::testing::send_mouse_click(instance, 5., 15.); +sixtyfps::testing::send_mouse_click(&handle, 5., 15.); assert_eq!(instance.get_value(), 13+42); ``` diff --git a/tests/cases/models/if.60 b/tests/cases/models/if.60 index 4de9108ba..1bbce83a7 100644 --- a/tests/cases/models/if.60 +++ b/tests/cases/models/if.60 @@ -41,32 +41,32 @@ auto handle = TestCase::create(); const TestCase &instance = *handle; // condition is false -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq(instance.get_top_level(), 42); instance.set_cond1(true); -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq(instance.get_top_level(), 92); instance.set_cond1(false); -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq(instance.get_top_level(), 92); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq!(instance.get_top_level(), 42); instance.set_cond1(true); -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq!(instance.get_top_level(), 92); instance.set_cond1(false); -sixtyfps::testing::send_mouse_click(instance, 5., 5.); +sixtyfps::testing::send_mouse_click(&handle, 5., 5.); assert_eq!(instance.get_top_level(), 92); ``` diff --git a/tests/cases/models/model.60 b/tests/cases/models/model.60 index 0964cd4b8..8b3e50493 100644 --- a/tests/cases/models/model.60 +++ b/tests/cases/models/model.60 @@ -50,15 +50,15 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); // there should be nothing there -sixtyfps::testing::send_mouse_click(instance, 25., 5.); +sixtyfps::testing::send_mouse_click(&handle, 25., 5.); assert_eq!(instance.get_clicked_score(), 0); assert_eq!(instance.get_clicked_internal_state(), 0); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq!(instance.get_clicked_score(), 789000); assert_eq!(instance.get_clicked_internal_state(), 1); @@ -72,32 +72,32 @@ let another_model = std::rc::Rc::new(sixtyfps::VecModel::::from( instance.set_model(sixtyfps::ModelHandle::new(another_model.clone())); -sixtyfps::testing::send_mouse_click(instance, 25., 5.); +sixtyfps::testing::send_mouse_click(&handle, 25., 5.); assert_eq!(instance.get_clicked_score(), 333000); assert_eq!(instance.get_clicked_internal_state(), 1); assert_eq!(instance.get_clicked_index(), 2); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq!(instance.get_clicked_score(), 222000); assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("cruel")); assert_eq!(instance.get_clicked_internal_state(), 1); another_model.push(("a4".into(), "!".into(), 444.)); -sixtyfps::testing::send_mouse_click(instance, 35., 5.); +sixtyfps::testing::send_mouse_click(&handle, 35., 5.); assert_eq!(instance.get_clicked_score(), 444000); assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("!")); assert_eq!(instance.get_clicked_internal_state(), 1); use sixtyfps::Model; another_model.set_row_data(1, ("a2".into(), "idyllic".into(), 555.)); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq!(instance.get_clicked_score(), 555000); assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("idyllic")); assert_eq!(instance.get_clicked_internal_state(), 2); assert_eq!(instance.get_clicked_index(), 1); another_model.remove(1); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq!(instance.get_clicked_score(), 333000); assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("world")); assert_eq!(instance.get_clicked_internal_state(), 2); @@ -110,11 +110,11 @@ auto handle = TestCase::create(); const TestCase &instance = *handle; // there should be nothing there -sixtyfps::testing::send_mouse_click(instance, 25., 5.); +sixtyfps::testing::send_mouse_click(&handle, 25., 5.); assert_eq(instance.get_clicked_score(), 0); assert_eq(instance.get_clicked_internal_state(), 0); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq(instance.get_clicked_score(), 789000); assert_eq(instance.get_clicked_internal_state(), 1); @@ -126,31 +126,31 @@ array.push_back(ModelData{"a3", "world", 333.}); auto another_model = std::make_shared>(std::move(array)); instance.set_model(another_model); -sixtyfps::testing::send_mouse_click(instance, 25., 5.); +sixtyfps::testing::send_mouse_click(&handle, 25., 5.); assert_eq(instance.get_clicked_score(), 333000); assert_eq(instance.get_clicked_internal_state(), 1); assert_eq(instance.get_clicked_index(), 2); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq(instance.get_clicked_score(), 222000); assert_eq(instance.get_clicked_name(), "cruel"); assert_eq(instance.get_clicked_internal_state(), 1); another_model->push_back({"a4", "!", 444.}); -sixtyfps::testing::send_mouse_click(instance, 35., 5.); +sixtyfps::testing::send_mouse_click(&handle, 35., 5.); assert_eq(instance.get_clicked_score(), 444000); assert_eq(instance.get_clicked_name(), "!"); assert_eq(instance.get_clicked_internal_state(), 1); another_model->set_row_data(1, {"a2", "idyllic", 555.}); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq(instance.get_clicked_score(), 555000); assert_eq(instance.get_clicked_name(), "idyllic"); assert_eq(instance.get_clicked_internal_state(), 2); assert_eq(instance.get_clicked_index(), 1); another_model->erase(1); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq(instance.get_clicked_score(), 333000); assert_eq(instance.get_clicked_name(), "world"); assert_eq(instance.get_clicked_internal_state(), 2); diff --git a/tests/cases/models/write_to_model.60 b/tests/cases/models/write_to_model.60 index c9da9e109..9b106696d 100644 --- a/tests/cases/models/write_to_model.60 +++ b/tests/cases/models/write_to_model.60 @@ -44,10 +44,10 @@ TestCase := Rectangle { /* ```rust use sixtyfps::Model; -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq!(instance.get_clicked_score(), 791); type ModelData = (sixtyfps::SharedString, sixtyfps::SharedString, f32); @@ -60,10 +60,10 @@ let another_model = std::rc::Rc::new(sixtyfps::VecModel::::from( instance.set_model(sixtyfps::ModelHandle::new(another_model.clone())); -sixtyfps::testing::send_mouse_click(instance, 25., 5.); +sixtyfps::testing::send_mouse_click(&handle, 25., 5.); assert_eq!(instance.get_clicked_score(), 335); assert_eq!(another_model.row_data(2).2, 335.); -sixtyfps::testing::send_mouse_click(instance, 25., 5.); +sixtyfps::testing::send_mouse_click(&handle, 25., 5.); assert_eq!(instance.get_clicked_score(), 337); assert_eq!(another_model.row_data(2).2, 337.); assert_eq!(another_model.row_data(2).1, sixtyfps::SharedString::from("world")); @@ -72,7 +72,7 @@ assert_eq!(another_model.row_data(2).1, sixtyfps::SharedString::from("world")); ```cpp auto handle = TestCase::create(); const TestCase &instance = *handle; -sixtyfps::testing::send_mouse_click(instance, 15., 5.); +sixtyfps::testing::send_mouse_click(&handle, 15., 5.); assert_eq(instance.get_clicked_score(), 791); using ModelData = std::tuple; @@ -83,10 +83,10 @@ array.push_back(ModelData{"a3", "world", 333.}); auto another_model = std::make_shared>(std::move(array)); instance.set_model(another_model); -sixtyfps::testing::send_mouse_click(instance, 25., 5.); +sixtyfps::testing::send_mouse_click(&handle, 25., 5.); assert_eq(instance.get_clicked_score(), 335); assert_eq(std::get<2>(another_model->row_data(2)), 335.); -sixtyfps::testing::send_mouse_click(instance, 25., 5.); +sixtyfps::testing::send_mouse_click(&handle, 25., 5.); assert_eq(instance.get_clicked_score(), 337); assert_eq(std::get<2>(another_model->row_data(2)), 337.); assert_eq(std::get<1>(another_model->row_data(2)), "world"); diff --git a/tests/cases/properties/dashes.60 b/tests/cases/properties/dashes.60 index a51ae5dc7..93053b0b0 100644 --- a/tests/cases/properties/dashes.60 +++ b/tests/cases/properties/dashes.60 @@ -31,8 +31,8 @@ assert_eq(instance.get_this__has_6_slashes__(), 86); ``` ```rust -let instance = Test_Case::new(); -let instance = instance.as_ref(); +let handle = Test_Case::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_property_x1(), 42.); assert_eq!(instance.get_property_x2(), 42.); assert_eq!(instance.get_this__has_6_slashes__(), 86); diff --git a/tests/cases/properties/property_animation.60 b/tests/cases/properties/property_animation.60 index f3070649b..64945b143 100644 --- a/tests/cases/properties/property_animation.60 +++ b/tests/cases/properties/property_animation.60 @@ -31,8 +31,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_hello(), 40); assert_eq!(instance.get_binding_dep(), 100); instance.set_condition(false); diff --git a/tests/cases/properties/transitions.60 b/tests/cases/properties/transitions.60 index c30bfed23..5b8fb1064 100644 --- a/tests/cases/properties/transitions.60 +++ b/tests/cases/properties/transitions.60 @@ -39,8 +39,8 @@ LICENSE END */ /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_text1_foo(), 85 + 4); assert_eq!(instance.get_some_prop(), 5); instance.set_active_index(1); diff --git a/tests/cases/signals/handler.60 b/tests/cases/signals/handler.60 index 49692ba77..6674519fd 100644 --- a/tests/cases/signals/handler.60 +++ b/tests/cases/signals/handler.60 @@ -35,8 +35,8 @@ assert_eq(signal_3_emited, 1); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); let signal_3_emited = std::rc::Rc::new(std::cell::Cell::new(0)); instance.on_test_signal3({ let signal_3_emited = signal_3_emited.clone(); diff --git a/tests/cases/signals/handler_with_arg.60 b/tests/cases/signals/handler_with_arg.60 index 9efe96b92..d9b7cd932 100644 --- a/tests/cases/signals/handler_with_arg.60 +++ b/tests/cases/signals/handler_with_arg.60 @@ -42,8 +42,8 @@ assert_eq(signal_3_string_value, "hello"); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); let signal_3_emited = std::rc::Rc::new(std::cell::RefCell::new((0, String::new()))); instance.on_test_signal3({ let signal_3_emited = signal_3_emited.clone(); diff --git a/tests/cases/text/cursor_move.60 b/tests/cases/text/cursor_move.60 index a972b99bb..6aa1286e1 100644 --- a/tests/cases/text/cursor_move.60 +++ b/tests/cases/text/cursor_move.60 @@ -19,9 +19,9 @@ TestCase := TextInput { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); -sixtyfps::testing::send_mouse_click(instance, 50., 50.); +let handle = TestCase::new(); +let instance = handle.as_ref(); +sixtyfps::testing::send_mouse_click(&handle, 50., 50.); assert!(instance.get_input_focused()); assert_eq!(instance.get_test_text(), ""); sixtyfps::testing::send_keyboard_string_sequence(instance, "Test"); diff --git a/tests/cases/text/default_color.60 b/tests/cases/text/default_color.60 index ac19b3393..38ecdb7ec 100644 --- a/tests/cases/text/default_color.60 +++ b/tests/cases/text/default_color.60 @@ -28,8 +28,8 @@ assert_eq(instance.get_color_of_initialized_text(), sixtyfps::Color::from_rgb_ui ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_default_text_color(), sixtyfps::Color::from_rgb_u8(0, 0, 0)); assert_eq!(instance.get_color_of_initialized_text(), sixtyfps::Color::from_rgb_u8(255, 255, 255)); ``` diff --git a/tests/cases/text/surrogate_cursor.60 b/tests/cases/text/surrogate_cursor.60 index e64936412..af76667cc 100644 --- a/tests/cases/text/surrogate_cursor.60 +++ b/tests/cases/text/surrogate_cursor.60 @@ -19,9 +19,9 @@ TestCase := TextInput { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); -sixtyfps::testing::send_mouse_click(instance, 50., 50.); +let handle = TestCase::new(); +let instance = handle.as_ref(); +sixtyfps::testing::send_mouse_click(&handle, 50., 50.); assert!(instance.get_input_focused()); assert_eq!(instance.get_test_text(), ""); sixtyfps::testing::send_keyboard_string_sequence(instance, "😍"); diff --git a/tests/cases/types/bool.60 b/tests/cases/types/bool.60 index 457c8c7f9..3e8a64048 100644 --- a/tests/cases/types/bool.60 +++ b/tests/cases/types/bool.60 @@ -21,8 +21,8 @@ assert(!instance.get_falsevar()); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert!(instance.get_truevar(), 1); assert!(!instance.get_falsevar(), 1); ``` diff --git a/tests/cases/types/duration.60 b/tests/cases/types/duration.60 index 3f597a1ef..44bf89655 100644 --- a/tests/cases/types/duration.60 +++ b/tests/cases/types/duration.60 @@ -48,8 +48,8 @@ assert_eq(instance.get_i2(), 50); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_untyped_d1(), 100); assert_eq!(instance.get_untyped_d2(), 3000); assert_eq!(instance.get_untyped_d3(), 1500); diff --git a/tests/cases/types/length.60 b/tests/cases/types/length.60 index 602c0e63b..f4e151491 100644 --- a/tests/cases/types/length.60 +++ b/tests/cases/types/length.60 @@ -58,8 +58,8 @@ assert(instance.get_value()); ```rust let ratio = 1.; -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_l1(), 12.); assert_eq!(instance.get_l2(), 12. * ratio); assert_eq!(instance.get_l3(), 100. + 12. * ratio); diff --git a/tests/cases/types/object.60 b/tests/cases/types/object.60 index 58ee54bf4..ea0e62076 100644 --- a/tests/cases/types/object.60 +++ b/tests/cases/types/object.60 @@ -26,8 +26,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_foo_a(), sixtyfps::SharedString::from("444")); assert_eq!(instance.get_foo_b(), 12); instance.emit_change_foo(); diff --git a/tests/cases/types/percent.60 b/tests/cases/types/percent.60 index 65dfbf146..f8bc6d02c 100644 --- a/tests/cases/types/percent.60 +++ b/tests/cases/types/percent.60 @@ -30,8 +30,8 @@ assert(!fuzzy_compare(instance.get_p1(), 1.001)); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_p1(), 1.); assert_eq!(instance.get_p2(), 0.01); assert_eq!(instance.get_p3(), 0.055); diff --git a/tests/cases/types/relative_lengths.60 b/tests/cases/types/relative_lengths.60 index 8ce757329..ceaed0e64 100644 --- a/tests/cases/types/relative_lengths.60 +++ b/tests/cases/types/relative_lengths.60 @@ -37,8 +37,8 @@ assert_eq(instance.get_controlled_test_length(), 100.); ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_test_length(), 100.); assert_eq!(instance.get_controlled_test_length(), 20.); diff --git a/tests/cases/types/string.60 b/tests/cases/types/string.60 index 0657a5734..84360139c 100644 --- a/tests/cases/types/string.60 +++ b/tests/cases/types/string.60 @@ -27,8 +27,8 @@ assert(!instance.get_e2()); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_p1(), "hello"); assert_eq!(instance.get_p2(), "fox:🦊"); assert!(instance.get_e1()); diff --git a/tests/cases/types/string_to_float.60 b/tests/cases/types/string_to_float.60 index 106ae7f57..a97dd4fdd 100644 --- a/tests/cases/types/string_to_float.60 +++ b/tests/cases/types/string_to_float.60 @@ -32,8 +32,8 @@ assert(fuzzy_compare(instance.get_negative_as_float(), -1200000.1)); ``` ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert!(instance.get_test_is_float()); assert_eq!(instance.get_number_as_float(), 42.56); assert_eq!(instance.get_negative_as_float(), -1200000.1); diff --git a/tests/cases/types/structs.60 b/tests/cases/types/structs.60 index b5070f57e..860d50705 100644 --- a/tests/cases/types/structs.60 +++ b/tests/cases/types/structs.60 @@ -30,8 +30,8 @@ TestCase := Rectangle { /* ```rust -let instance = TestCase::new(); -let instance = instance.as_ref(); +let handle = TestCase::new(); +let instance = handle.as_ref(); assert_eq!(instance.get_player_1().score, 12); assert_eq!(instance.get_player_1(), Player{ name: "Player1".into(), score: 12, energy_level: 0.8 });