Remove ComponentVtable::input_event

And the custom handling of the mouse grabber
This commit is contained in:
Olivier Goffart 2020-11-24 16:23:37 +01:00
parent 845627c6b4
commit 8a64f10e84
69 changed files with 213 additions and 469 deletions

View file

@ -178,44 +178,6 @@ using cbindgen_private::KeyEventResult;
using cbindgen_private::MouseEvent; using cbindgen_private::MouseEvent;
using cbindgen_private::sixtyfps_visit_item_tree; using cbindgen_private::sixtyfps_visit_item_tree;
namespace private_api { namespace private_api {
template<typename GetDynamic>
inline InputEventResult process_input_event(const ComponentRc &component_rc, int64_t &mouse_grabber,
MouseEvent mouse_event, Slice<ItemTreeNode> 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<char *>(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) void dealloc(const ComponentVTable *, uint8_t *ptr, vtable::Layout layout)
{ {

View file

@ -17,11 +17,11 @@ inline void mock_elapsed_time(int64_t time_in_ms)
cbindgen_private::sixtyfps_mock_elapsed_time(time_in_ms); cbindgen_private::sixtyfps_mock_elapsed_time(time_in_ms);
} }
template<typename Component> template<typename Component>
inline void send_mouse_click(const Component &component, float x, float y) inline void send_mouse_click(const ComponentHandle<Component> *component, float x, float y)
{ {
cbindgen_private::sixtyfps_send_mouse_click( cbindgen_private::sixtyfps_send_mouse_click(
{ &Component::component_type, const_cast<Component *>(&component) }, x, y, reinterpret_cast<const vtable::VRc<private_api::ComponentVTable>*>(component),
&component.window); x, y, &(*component)->window);
} }
template<typename Component> template<typename Component>

View file

@ -440,8 +440,9 @@ declare_types! {
let lock = cx.lock(); let lock = cx.lock();
let comp = this.borrow(&lock).0.clone(); let comp = this.borrow(&lock).0.clone();
let component = comp.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?; let component = comp.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
let win = component.window();
run_scoped(&mut cx,this.downcast().unwrap(), || { 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(())
})?; })?;
Ok(JsUndefined::new().as_value(&mut cx)) Ok(JsUndefined::new().as_value(&mut cx))

View file

@ -181,9 +181,9 @@ pub mod re_exports {
PathArcTo, PathData, PathElement, PathEvent, PathLineTo, Point, Rect, Size, PathArcTo, PathData, PathElement, PathEvent, PathLineTo, Point, Rect, Size,
}; };
pub use sixtyfps_corelib::input::{ pub use sixtyfps_corelib::input::{
process_ungrabbed_mouse_event, FocusEvent, InputEventResult, KeyCode, KeyEvent, FocusEvent, InputEventResult, KeyCode, KeyEvent, KeyEventResult, KeyboardModifiers,
KeyEventResult, KeyboardModifiers, MouseEvent, ALT_MODIFIER, CONTROL_MODIFIER, MouseEvent, ALT_MODIFIER, CONTROL_MODIFIER, COPY_PASTE_MODIFIER, LOGO_MODIFIER,
COPY_PASTE_MODIFIER, LOGO_MODIFIER, NO_MODIFIER, SHIFT_MODIFIER, NO_MODIFIER, SHIFT_MODIFIER,
}; };
pub use sixtyfps_corelib::item_tree::{ pub use sixtyfps_corelib::item_tree::{
item_offset, visit_item_tree, ItemTreeNode, ItemVisitorRefMut, ItemVisitorVTable, 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; pub use sixtyfps_corelib::tests::sixtyfps_mock_elapsed_time as mock_elapsed_time;
/// Simulate a mouse click /// Simulate a mouse click
pub fn send_mouse_click< pub fn send_mouse_click<
X: vtable::HasStaticVTable<sixtyfps_corelib::component::ComponentVTable> + HasWindow, X: vtable::HasStaticVTable<sixtyfps_corelib::component::ComponentVTable> + HasWindow + 'static,
>( >(
component: core::pin::Pin<&X>, component: &crate::ComponentHandle<X>,
x: f32, x: f32,
y: f32, y: f32,
) { ) {
sixtyfps_corelib::tests::sixtyfps_send_mouse_click( sixtyfps_corelib::tests::sixtyfps_send_mouse_click(
vtable::VRef::new_pin(component), &vtable::VRc::into_dyn(component.inner.clone()),
x, x,
y, y,
component.component_window(), component.inner.component_window(),
); );
} }

View file

@ -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); let (apply_layout, layout_info) = compute_layout(component, &mut repeater_layout_code);
component_struct.members.push(( component_struct.members.push((
@ -1196,7 +1168,7 @@ fn generate_component(
ty: "const sixtyfps::private_api::ComponentVTable".to_owned(), ty: "const sixtyfps::private_api::ComponentVTable".to_owned(),
name: format!("{}::component_type", component_id), name: format!("{}::component_type", component_id),
init: Some(format!( 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) component_id)
), ),
})); }));

View file

@ -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 #layouts
@ -769,7 +738,6 @@ fn generate_component(
#(#repeated_element_names : sixtyfps::re_exports::Repeater<#repeated_element_components>,)* #(#repeated_element_names : sixtyfps::re_exports::Repeater<#repeated_element_components>,)*
#(#self_weak : sixtyfps::re_exports::OnceCell<sixtyfps::re_exports::VWeak<sixtyfps::re_exports::ComponentVTable, #component_id>>,)* #(#self_weak : sixtyfps::re_exports::OnceCell<sixtyfps::re_exports::VWeak<sixtyfps::re_exports::ComponentVTable, #component_id>>,)*
#(parent : sixtyfps::re_exports::VWeak<sixtyfps::re_exports::ComponentVTable, #parent_component_type>,)* #(parent : sixtyfps::re_exports::VWeak<sixtyfps::re_exports::ComponentVTable, #parent_component_type>,)*
mouse_grabber: ::core::cell::Cell<sixtyfps::re_exports::VisitChildrenResult>,
#(#global_name : ::core::pin::Pin<::std::rc::Rc<#global_type>>,)* #(#global_name : ::core::pin::Pin<::std::rc::Rc<#global_type>>,)*
#window_field #window_field
} }
@ -789,7 +757,6 @@ fn generate_component(
#(#repeated_element_names : ::core::default::Default::default(),)* #(#repeated_element_names : ::core::default::Default::default(),)*
#(#self_weak : ::core::default::Default::default(),)* #(#self_weak : ::core::default::Default::default(),)*
#(parent : parent as sixtyfps::re_exports::VWeak::<sixtyfps::re_exports::ComponentVTable, #parent_component_type>,)* #(parent : parent as sixtyfps::re_exports::VWeak::<sixtyfps::re_exports::ComponentVTable, #parent_component_type>,)*
mouse_grabber: ::core::cell::Cell::new(sixtyfps::re_exports::VisitChildrenResult::CONTINUE),
#(#global_name : #global_type::new(),)* #(#global_name : #global_type::new(),)*
#window_field_init #window_field_init
}; };

View file

@ -13,7 +13,6 @@ LICENSE END */
use crate::eventloop::ComponentWindow; use crate::eventloop::ComponentWindow;
use crate::graphics::Rect; use crate::graphics::Rect;
use crate::input::{InputEventResult, MouseEvent};
use crate::item_tree::{ItemVisitorVTable, TraversalOrder, VisitChildrenResult}; use crate::item_tree::{ItemVisitorVTable, TraversalOrder, VisitChildrenResult};
use crate::items::ItemVTable; use crate::items::ItemVTable;
use crate::layout::LayoutInfo; 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 /// 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<VRef<ComponentVTable>>, Rect), pub apply_layout: extern "C" fn(core::pin::Pin<VRef<ComponentVTable>>, Rect),
/// input event
pub input_event: extern "C" fn(
core::pin::Pin<VRef<ComponentVTable>>,
MouseEvent,
&ComponentWindow,
) -> InputEventResult,
/// in-place destructor (for VRc) /// in-place destructor (for VRc)
pub drop_in_place: unsafe fn(VRefMut<ComponentVTable>) -> vtable::Layout, pub drop_in_place: unsafe fn(VRefMut<ComponentVTable>) -> vtable::Layout,
/// dealloc function (for VRc) /// dealloc function (for VRc)

View file

@ -13,7 +13,7 @@ LICENSE END */
use crate::component::ComponentRc; use crate::component::ComponentRc;
use crate::graphics::Point; use crate::graphics::Point;
use crate::item_tree::{ItemVisitorResult, VisitChildrenResult}; use crate::item_tree::ItemVisitorResult;
use crate::items::{ItemRc, ItemRef, ItemWeak}; use crate::items::{ItemRc, ItemRef, ItemWeak};
use euclid::default::Vector2D; use euclid::default::Vector2D;
use sixtyfps_corelib_macros::*; use sixtyfps_corelib_macros::*;
@ -464,66 +464,6 @@ pub enum FocusEvent {
WindowLostFocus, 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<Vector2D<f32>> {
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 /// Process the `mouse_event` on the `component`, the `mouse_grabber_stack` is the prebious stack
/// of mouse grabber. /// of mouse grabber.
/// Returns a new mouse grabber stack. /// Returns a new mouse grabber stack.
@ -593,30 +533,3 @@ pub fn process_mouse_input(
result 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<ItemRef>,
offset: Point,
event: MouseEvent,
old_grab: VisitChildrenResult,
) -> (InputEventResult, crate::item_tree::VisitChildrenResult) {
process_grabbed_mouse_event(component, item, offset, event, old_grab)
}*/
}

View file

@ -84,6 +84,5 @@ pub fn use_modules() -> usize {
+ properties::ffi::sixtyfps_property_init as usize + properties::ffi::sixtyfps_property_init as usize
+ string::ffi::sixtyfps_shared_string_bytes as usize + string::ffi::sixtyfps_shared_string_bytes as usize
+ eventloop::ffi::sixtyfps_component_window_drop 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 + component::ffi::sixtyfps_component_init_items as usize
} }

View file

@ -555,17 +555,6 @@ impl<C: RepeatedComponent> Repeater<C> {
crate::item_tree::VisitChildrenResult::CONTINUE 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 /// Return the amount of item currently in the component
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.inner.borrow().borrow().components.len() self.inner.borrow().borrow().components.len()

View file

@ -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. /// Simulate a click on a position within the component.
#[no_mangle] #[no_mangle]
pub extern "C" fn sixtyfps_send_mouse_click( pub extern "C" fn sixtyfps_send_mouse_click(
component: core::pin::Pin<crate::component::ComponentRef>, component: &crate::component::ComponentRc,
x: f32, x: f32,
y: f32, y: f32,
window: &crate::eventloop::ComponentWindow, 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); 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); 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. /// Simulate a change in keyboard modifiers pressed.

View file

@ -21,7 +21,6 @@ use sixtyfps_compilerlib::*;
use sixtyfps_corelib::component::{Component, ComponentRefPin, ComponentVTable}; use sixtyfps_corelib::component::{Component, ComponentRefPin, ComponentVTable};
use sixtyfps_corelib::eventloop::ComponentWindow; use sixtyfps_corelib::eventloop::ComponentWindow;
use sixtyfps_corelib::graphics::{Rect, Resource}; use sixtyfps_corelib::graphics::{Rect, Resource};
use sixtyfps_corelib::input::{InputEventResult, MouseEvent};
use sixtyfps_corelib::item_tree::{ use sixtyfps_corelib::item_tree::{
ItemTreeNode, ItemVisitorRefMut, ItemVisitorVTable, TraversalOrder, VisitChildrenResult, ItemTreeNode, ItemVisitorRefMut, ItemVisitorVTable, TraversalOrder, VisitChildrenResult,
}; };
@ -203,14 +202,6 @@ impl Component for ErasedComponentBox {
self.borrow().as_ref().visit_children_item(index, order, visitor) 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 { fn layout_info(self: Pin<&Self>) -> sixtyfps_corelib::layout::LayoutInfo {
self.borrow().as_ref().layout_info() self.borrow().as_ref().layout_info()
} }
@ -228,7 +219,6 @@ impl Component for ErasedComponentBox {
sixtyfps_corelib::ComponentVTable_static!(static COMPONENT_BOX_VT for ErasedComponentBox); sixtyfps_corelib::ComponentVTable_static!(static COMPONENT_BOX_VT for ErasedComponentBox);
pub(crate) struct ComponentExtraData { pub(crate) struct ComponentExtraData {
mouse_grabber: core::cell::Cell<VisitChildrenResult>,
pub(crate) globals: HashMap<String, Pin<Rc<dyn crate::global_component::GlobalComponent>>>, pub(crate) globals: HashMap<String, Pin<Rc<dyn crate::global_component::GlobalComponent>>>,
pub(crate) self_weak: pub(crate) self_weak:
once_cell::unsync::OnceCell<vtable::VWeak<ComponentVTable, ErasedComponentBox>>, once_cell::unsync::OnceCell<vtable::VWeak<ComponentVTable, ErasedComponentBox>>,
@ -236,11 +226,7 @@ pub(crate) struct ComponentExtraData {
impl Default for ComponentExtraData { impl Default for ComponentExtraData {
fn default() -> Self { fn default() -> Self {
Self { Self { globals: HashMap::new(), self_weak: Default::default() }
mouse_grabber: core::cell::Cell::new(VisitChildrenResult::CONTINUE),
globals: HashMap::new(),
self_weak: Default::default(),
}
} }
} }
@ -687,7 +673,6 @@ fn generate_component<'id>(
visit_children_item, visit_children_item,
layout_info, layout_info,
apply_layout, apply_layout,
input_event,
get_item_ref, get_item_ref,
drop_in_place, drop_in_place,
dealloc, 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()) (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::<Instance>()) };
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 { extern "C" fn layout_info(component: ComponentRefPin) -> LayoutInfo {
generativity::make_guard!(guard); generativity::make_guard!(guard);
// This is fine since we can only be called with a component that with our vtable which is a ComponentDescription // 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()); 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)] #[derive(Copy, Clone)]
pub struct InstanceRef<'a, 'id> { pub struct InstanceRef<'a, 'id> {
pub instance: Pin<&'a Instance<'id>>, pub instance: Pin<&'a Instance<'id>>,

View file

@ -27,8 +27,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_prop_a(), 1); assert_eq!(instance.get_prop_a(), 1);
assert_eq!(instance.get_prop_b(), 2); assert_eq!(instance.get_prop_b(), 2);
``` ```

View file

@ -63,8 +63,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_text1(), sixtyfps::SharedString::from("Hello")); assert_eq!(instance.get_text1(), sixtyfps::SharedString::from("Hello"));
assert_eq!(instance.get_text2(), sixtyfps::SharedString::from("Blah")); assert_eq!(instance.get_text2(), sixtyfps::SharedString::from("Blah"));
assert_eq!(instance.get_ti1_text(), sixtyfps::SharedString::from("Hello")); assert_eq!(instance.get_ti1_text(), sixtyfps::SharedString::from("Hello"));

View file

@ -29,8 +29,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_sub_width1(), 80.); assert_eq!(instance.get_sub_width1(), 80.);
assert_eq!(instance.get_sub_width2(), 80.); assert_eq!(instance.get_sub_width2(), 80.);
instance.set_sub_width1(99.); instance.set_sub_width1(99.);

View file

@ -42,8 +42,8 @@ assert(instance.get_rect1_pos_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 200.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 200.)));
assert!(instance.get_rect1_pos_ok()); assert!(instance.get_rect1_pos_ok());

View file

@ -50,8 +50,8 @@ assert(instance.get_rect1_pos_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 200.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 200.)));
assert!(instance.get_rect1_pos_ok()); assert!(instance.get_rect1_pos_ok());

View file

@ -31,8 +31,8 @@ assert_eq(instance.get_s1(), "123");
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
instance.set_condition(true); instance.set_condition(true);
assert_eq!(instance.get_s1(), "abc"); assert_eq!(instance.get_s1(), "abc");
assert_eq!(instance.get_s2(), "123"); assert_eq!(instance.get_s2(), "123");

View file

@ -29,8 +29,8 @@ assert_eq(instance.get_test_value2(), 3);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
instance.set_condition(true); instance.set_condition(true);
assert_eq!(instance.get_test_value(), 1); assert_eq!(instance.get_test_value(), 1);
assert_eq!(instance.get_test_value2(), 2); assert_eq!(instance.get_test_value2(), 2);

View file

@ -55,8 +55,8 @@ assert_eq(instance.get_result(), 5+33-1);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
instance.emit_action(); instance.emit_action();
assert_eq!(instance.get_result(), 3); assert_eq!(instance.get_result(), 3);
instance.set_value(5); instance.set_value(5);

View file

@ -33,37 +33,37 @@ auto handle = TestCase::create();
const TestCase &instance = *handle; const TestCase &instance = *handle;
// does not click on anything // 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_touch1(), 0);
assert_eq(instance.get_touch2(), 0); assert_eq(instance.get_touch2(), 0);
// click on second one // 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_touch1(), 0);
assert_eq(instance.get_touch2(), 1); assert_eq(instance.get_touch2(), 1);
// click on first one only // 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_touch1(), 1);
assert_eq(instance.get_touch2(), 1); assert_eq(instance.get_touch2(), 1);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
// does not click on anything // 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_touch1(), 0);
assert_eq!(instance.get_touch2(), 0); assert_eq!(instance.get_touch2(), 0);
// click on second one // 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_touch1(), 0);
assert_eq!(instance.get_touch2(), 1); assert_eq!(instance.get_touch2(), 1);
// click on first one only // 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_touch1(), 1);
assert_eq!(instance.get_touch2(), 1); assert_eq!(instance.get_touch2(), 1);
``` ```

View file

@ -37,8 +37,8 @@ assert_eq(instance.get_a(), (((42 + 8) * 10) / 2) - 3);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_t1(), 4 + 3 * 2 + 2 - 50 - 2); assert_eq!(instance.get_t1(), 4 + 3 * 2 + 2 - 50 - 2);
assert_eq!(instance.get_t2(), 500 / 2 * 30 - 1); assert_eq!(instance.get_t2(), 500 / 2 * 30 - 1);
instance.set_a(42); instance.set_a(42);

View file

@ -68,8 +68,8 @@ assert_eq(instance.get_t6(), true);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_t1(), true); assert_eq!(instance.get_t1(), true);
assert_eq!(instance.get_t2(), false); assert_eq!(instance.get_t2(), false);

View file

@ -22,8 +22,8 @@ assert_eq(instance.get_t2(), true);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_t1(), 98.5); assert_eq!(instance.get_t1(), 98.5);
assert_eq!(instance.get_t2(), true); assert_eq!(instance.get_t2(), true);
``` ```

View file

@ -23,8 +23,8 @@ assert_eq(instance.get_t3(),3);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_t1(), 0); assert_eq!(instance.get_t1(), 0);
assert_eq!(instance.get_t2(), 8.0); assert_eq!(instance.get_t2(), 8.0);
assert_eq!(instance.get_t3(), 3); assert_eq!(instance.get_t3(), 3);

View file

@ -36,8 +36,8 @@ assert_eq(instance.get_s4(), sixtyfps::SharedString("ayoxxx"));
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_s1(), sixtyfps::SharedString::from("hello1212")); assert_eq!(instance.get_s1(), sixtyfps::SharedString::from("hello1212"));
assert_eq!(instance.get_s2(), sixtyfps::SharedString::from("10hello5.1")); assert_eq!(instance.get_s2(), sixtyfps::SharedString::from("10hello5.1"));
instance.set_a(42); instance.set_a(42);

View file

@ -30,12 +30,12 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert!(!instance.get_input1_focused()); assert!(!instance.get_input1_focused());
assert!(!instance.get_input2_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_input1_focused());
assert!(!instance.get_input2_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_input1_text(), "Only for field 1");
assert_eq!(instance.get_input2_text(), ""); 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_input1_focused());
assert!(instance.get_input2_focused()); assert!(instance.get_input2_focused());
@ -58,7 +58,7 @@ const TestCase &instance = *handle;
assert(!instance.get_input1_focused()); assert(!instance.get_input1_focused());
assert(!instance.get_input2_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_input1_focused());
assert(!instance.get_input2_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_input1_text(), "Only for field 1");
assert_eq(instance.get_input2_text(), ""); 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_input1_focused());
assert(instance.get_input2_focused()); assert(instance.get_input2_focused());

View file

@ -36,8 +36,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert!(!instance.get_input1_focused()); assert!(!instance.get_input1_focused());
assert!(!instance.get_input2_focused()); assert!(!instance.get_input2_focused());

View file

@ -31,8 +31,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert!(instance.get_input1_focused()); assert!(instance.get_input1_focused());
assert!(!instance.get_input2_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_input1_text(), "Only for field 1");
assert_eq!(instance.get_input2_text(), ""); 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_input1_focused());
assert!(!instance.get_input2_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_input1_focused());
assert!(instance.get_input2_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_input1_text(), "Only for field 1");
assert_eq(instance.get_input2_text(), ""); 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_input1_focused());
assert(!instance.get_input2_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_input1_focused());
assert(instance.get_input2_focused()); assert(instance.get_input2_focused());
``` ```

View file

@ -30,8 +30,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert!(!instance.get_input1_focused()); assert!(!instance.get_input1_focused());
assert!(instance.get_input2_focused()); assert!(instance.get_input2_focused());
``` ```

View file

@ -32,8 +32,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert!(!instance.get_input1_focused()); assert!(!instance.get_input1_focused());
assert!(instance.get_input2_focused()); assert!(instance.get_input2_focused());
``` ```

View file

@ -24,8 +24,8 @@ assert_eq(instance.get_p2(), 44);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_p1(), 42); assert_eq!(instance.get_p1(), 42);
assert_eq!(instance.get_p2(), 44); assert_eq!(instance.get_p2(), 44);
``` ```

View file

@ -27,8 +27,8 @@ assert_eq(instance.get_exp().e.a, 2001);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_p1(), 2003); assert_eq!(instance.get_p1(), 2003);
assert_eq!(instance.get_exp().e.a, 2001); assert_eq!(instance.get_exp().e.a, 2001);
``` ```

View file

@ -19,8 +19,8 @@ assert_eq(instance.get_some_prop(), 42);
``` ```
```rust ```rust
let instance = MainWindow::new(); let handle = MainWindow::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_some_prop(), 42); assert_eq!(instance.get_some_prop(), 42);
``` ```

View file

@ -87,8 +87,8 @@ assert(instance.get_c1());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_v1()); assert!(instance.get_v1());

View file

@ -51,8 +51,8 @@ assert_eq(instance.get_layout_width(), 300);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok()); assert!(instance.get_rect1_pos_ok());

View file

@ -62,8 +62,8 @@ assert(instance.get_rect3_pos_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok()); assert!(instance.get_rect1_pos_ok());

View file

@ -65,8 +65,8 @@ assert(instance.get_rect2_pos_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok()); assert!(instance.get_rect1_pos_ok());

View file

@ -40,29 +40,29 @@ TestCase := Rectangle {
```cpp ```cpp
auto handle = TestCase::create(); auto handle = TestCase::create();
const TestCase &instance = *handle; 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<TestCase*>(&instance) }, sixtyfps::Rect{0, 0, 300, 300}); TestCase::apply_layout({&TestCase::component_type, const_cast<TestCase*>(&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); 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); assert_eq(instance.get_value(), 1+1+2);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; 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.))); 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); 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); assert_eq!(instance.get_value(), 1+1+2);
``` ```

View file

@ -43,28 +43,28 @@ export TestCase := Rectangle {
auto handle = TestCase::create(); auto handle = TestCase::create();
const TestCase &instance = *handle; 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); 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); 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); assert_eq(instance.get_value(), 9);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); 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); 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); 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); assert_eq!(instance.get_value(), 9);
``` ```

View file

@ -80,8 +80,8 @@ assert(instance.get_pink_rect_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_blue_rect_ok()); assert!(instance.get_blue_rect_ok());

View file

@ -142,8 +142,8 @@ assert(instance.get_rect_black2_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect_blue_ok()); assert!(instance.get_rect_blue_ok());

View file

@ -56,8 +56,8 @@ assert(instance.get_rect6_pos_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok()); assert!(instance.get_rect1_pos_ok());

View file

@ -64,8 +64,8 @@ assert(instance.get_rect4_pos_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok()); assert!(instance.get_rect1_pos_ok());

View file

@ -51,8 +51,8 @@ assert(instance.get_rect2_pos_ok());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_rect1_pos_ok()); assert!(instance.get_rect1_pos_ok());

View file

@ -95,8 +95,8 @@ assert(instance.get_test5());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
use sixtyfps::re_exports::Component; use sixtyfps::re_exports::Component;
instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.))); instance.apply_layout(sixtyfps::re_exports::Rect::new(Default::default(), sixtyfps::re_exports::Size::new(300., 300.)));
assert!(instance.get_test1()); assert!(instance.get_test1());

View file

@ -43,8 +43,8 @@ assert_eq(instance.get_p2(), 3);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_p1(), 51); assert_eq!(instance.get_p1(), 51);
assert_eq!(instance.get_p2(), 3); assert_eq!(instance.get_p2(), 3);
``` ```

View file

@ -29,8 +29,8 @@ assert_eq(instance.get_p2(), 5930);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_p1(), 5770); assert_eq!(instance.get_p1(), 5770);
assert_eq!(instance.get_p2(), 5930); assert_eq!(instance.get_p2(), 5930);
``` ```

View file

@ -95,28 +95,28 @@ export TestCase := Rectangle {
auto handle = TestCase::create(); auto handle = TestCase::create();
const TestCase &instance = *handle; 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); 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); 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); assert_eq(instance.get_value(), 13+42);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); 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); 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); 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); assert_eq!(instance.get_value(), 13+42);
``` ```

View file

@ -41,32 +41,32 @@ auto handle = TestCase::create();
const TestCase &instance = *handle; const TestCase &instance = *handle;
// condition is false // 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); assert_eq(instance.get_top_level(), 42);
instance.set_cond1(true); 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); assert_eq(instance.get_top_level(), 92);
instance.set_cond1(false); 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); assert_eq(instance.get_top_level(), 92);
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); 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); assert_eq!(instance.get_top_level(), 42);
instance.set_cond1(true); 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); assert_eq!(instance.get_top_level(), 92);
instance.set_cond1(false); 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); assert_eq!(instance.get_top_level(), 92);
``` ```

View file

@ -50,15 +50,15 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
// there should be nothing there // 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_score(), 0);
assert_eq!(instance.get_clicked_internal_state(), 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_score(), 789000);
assert_eq!(instance.get_clicked_internal_state(), 1); assert_eq!(instance.get_clicked_internal_state(), 1);
@ -72,32 +72,32 @@ let another_model = std::rc::Rc::new(sixtyfps::VecModel::<ModelData>::from(
instance.set_model(sixtyfps::ModelHandle::new(another_model.clone())); 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_score(), 333000);
assert_eq!(instance.get_clicked_internal_state(), 1); assert_eq!(instance.get_clicked_internal_state(), 1);
assert_eq!(instance.get_clicked_index(), 2); 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_score(), 222000);
assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("cruel")); assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("cruel"));
assert_eq!(instance.get_clicked_internal_state(), 1); assert_eq!(instance.get_clicked_internal_state(), 1);
another_model.push(("a4".into(), "!".into(), 444.)); 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_score(), 444000);
assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("!")); assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("!"));
assert_eq!(instance.get_clicked_internal_state(), 1); assert_eq!(instance.get_clicked_internal_state(), 1);
use sixtyfps::Model; use sixtyfps::Model;
another_model.set_row_data(1, ("a2".into(), "idyllic".into(), 555.)); 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_score(), 555000);
assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("idyllic")); assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("idyllic"));
assert_eq!(instance.get_clicked_internal_state(), 2); assert_eq!(instance.get_clicked_internal_state(), 2);
assert_eq!(instance.get_clicked_index(), 1); assert_eq!(instance.get_clicked_index(), 1);
another_model.remove(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_score(), 333000);
assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("world")); assert_eq!(instance.get_clicked_name(), sixtyfps::SharedString::from("world"));
assert_eq!(instance.get_clicked_internal_state(), 2); assert_eq!(instance.get_clicked_internal_state(), 2);
@ -110,11 +110,11 @@ auto handle = TestCase::create();
const TestCase &instance = *handle; const TestCase &instance = *handle;
// there should be nothing there // 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_score(), 0);
assert_eq(instance.get_clicked_internal_state(), 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_score(), 789000);
assert_eq(instance.get_clicked_internal_state(), 1); 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<sixtyfps::VectorModel<ModelData>>(std::move(array)); auto another_model = std::make_shared<sixtyfps::VectorModel<ModelData>>(std::move(array));
instance.set_model(another_model); 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_score(), 333000);
assert_eq(instance.get_clicked_internal_state(), 1); assert_eq(instance.get_clicked_internal_state(), 1);
assert_eq(instance.get_clicked_index(), 2); 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_score(), 222000);
assert_eq(instance.get_clicked_name(), "cruel"); assert_eq(instance.get_clicked_name(), "cruel");
assert_eq(instance.get_clicked_internal_state(), 1); assert_eq(instance.get_clicked_internal_state(), 1);
another_model->push_back({"a4", "!", 444.}); 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_score(), 444000);
assert_eq(instance.get_clicked_name(), "!"); assert_eq(instance.get_clicked_name(), "!");
assert_eq(instance.get_clicked_internal_state(), 1); assert_eq(instance.get_clicked_internal_state(), 1);
another_model->set_row_data(1, {"a2", "idyllic", 555.}); 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_score(), 555000);
assert_eq(instance.get_clicked_name(), "idyllic"); assert_eq(instance.get_clicked_name(), "idyllic");
assert_eq(instance.get_clicked_internal_state(), 2); assert_eq(instance.get_clicked_internal_state(), 2);
assert_eq(instance.get_clicked_index(), 1); assert_eq(instance.get_clicked_index(), 1);
another_model->erase(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_score(), 333000);
assert_eq(instance.get_clicked_name(), "world"); assert_eq(instance.get_clicked_name(), "world");
assert_eq(instance.get_clicked_internal_state(), 2); assert_eq(instance.get_clicked_internal_state(), 2);

View file

@ -44,10 +44,10 @@ TestCase := Rectangle {
/* /*
```rust ```rust
use sixtyfps::Model; use sixtyfps::Model;
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); 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); assert_eq!(instance.get_clicked_score(), 791);
type ModelData = (sixtyfps::SharedString, sixtyfps::SharedString, f32); type ModelData = (sixtyfps::SharedString, sixtyfps::SharedString, f32);
@ -60,10 +60,10 @@ let another_model = std::rc::Rc::new(sixtyfps::VecModel::<ModelData>::from(
instance.set_model(sixtyfps::ModelHandle::new(another_model.clone())); 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!(instance.get_clicked_score(), 335);
assert_eq!(another_model.row_data(2).2, 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!(instance.get_clicked_score(), 337);
assert_eq!(another_model.row_data(2).2, 337.); assert_eq!(another_model.row_data(2).2, 337.);
assert_eq!(another_model.row_data(2).1, sixtyfps::SharedString::from("world")); 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 ```cpp
auto handle = TestCase::create(); auto handle = TestCase::create();
const TestCase &instance = *handle; 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); assert_eq(instance.get_clicked_score(), 791);
using ModelData = std::tuple<sixtyfps::SharedString, sixtyfps::SharedString, float>; using ModelData = std::tuple<sixtyfps::SharedString, sixtyfps::SharedString, float>;
@ -83,10 +83,10 @@ array.push_back(ModelData{"a3", "world", 333.});
auto another_model = std::make_shared<sixtyfps::VectorModel<ModelData>>(std::move(array)); auto another_model = std::make_shared<sixtyfps::VectorModel<ModelData>>(std::move(array));
instance.set_model(another_model); 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(instance.get_clicked_score(), 335);
assert_eq(std::get<2>(another_model->row_data(2)), 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(instance.get_clicked_score(), 337);
assert_eq(std::get<2>(another_model->row_data(2)), 337.); assert_eq(std::get<2>(another_model->row_data(2)), 337.);
assert_eq(std::get<1>(another_model->row_data(2)), "world"); assert_eq(std::get<1>(another_model->row_data(2)), "world");

View file

@ -31,8 +31,8 @@ assert_eq(instance.get_this__has_6_slashes__(), 86);
``` ```
```rust ```rust
let instance = Test_Case::new(); let handle = Test_Case::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_property_x1(), 42.); assert_eq!(instance.get_property_x1(), 42.);
assert_eq!(instance.get_property_x2(), 42.); assert_eq!(instance.get_property_x2(), 42.);
assert_eq!(instance.get_this__has_6_slashes__(), 86); assert_eq!(instance.get_this__has_6_slashes__(), 86);

View file

@ -31,8 +31,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_hello(), 40); assert_eq!(instance.get_hello(), 40);
assert_eq!(instance.get_binding_dep(), 100); assert_eq!(instance.get_binding_dep(), 100);
instance.set_condition(false); instance.set_condition(false);

View file

@ -39,8 +39,8 @@ LICENSE END */
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_text1_foo(), 85 + 4); assert_eq!(instance.get_text1_foo(), 85 + 4);
assert_eq!(instance.get_some_prop(), 5); assert_eq!(instance.get_some_prop(), 5);
instance.set_active_index(1); instance.set_active_index(1);

View file

@ -35,8 +35,8 @@ assert_eq(signal_3_emited, 1);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
let signal_3_emited = std::rc::Rc::new(std::cell::Cell::new(0)); let signal_3_emited = std::rc::Rc::new(std::cell::Cell::new(0));
instance.on_test_signal3({ instance.on_test_signal3({
let signal_3_emited = signal_3_emited.clone(); let signal_3_emited = signal_3_emited.clone();

View file

@ -42,8 +42,8 @@ assert_eq(signal_3_string_value, "hello");
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
let signal_3_emited = std::rc::Rc::new(std::cell::RefCell::new((0, String::new()))); let signal_3_emited = std::rc::Rc::new(std::cell::RefCell::new((0, String::new())));
instance.on_test_signal3({ instance.on_test_signal3({
let signal_3_emited = signal_3_emited.clone(); let signal_3_emited = signal_3_emited.clone();

View file

@ -19,9 +19,9 @@ TestCase := TextInput {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
sixtyfps::testing::send_mouse_click(instance, 50., 50.); sixtyfps::testing::send_mouse_click(&handle, 50., 50.);
assert!(instance.get_input_focused()); assert!(instance.get_input_focused());
assert_eq!(instance.get_test_text(), ""); assert_eq!(instance.get_test_text(), "");
sixtyfps::testing::send_keyboard_string_sequence(instance, "Test"); sixtyfps::testing::send_keyboard_string_sequence(instance, "Test");

View file

@ -28,8 +28,8 @@ assert_eq(instance.get_color_of_initialized_text(), sixtyfps::Color::from_rgb_ui
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_default_text_color(), sixtyfps::Color::from_rgb_u8(0, 0, 0)); 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)); assert_eq!(instance.get_color_of_initialized_text(), sixtyfps::Color::from_rgb_u8(255, 255, 255));
``` ```

View file

@ -19,9 +19,9 @@ TestCase := TextInput {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
sixtyfps::testing::send_mouse_click(instance, 50., 50.); sixtyfps::testing::send_mouse_click(&handle, 50., 50.);
assert!(instance.get_input_focused()); assert!(instance.get_input_focused());
assert_eq!(instance.get_test_text(), ""); assert_eq!(instance.get_test_text(), "");
sixtyfps::testing::send_keyboard_string_sequence(instance, "😍"); sixtyfps::testing::send_keyboard_string_sequence(instance, "😍");

View file

@ -21,8 +21,8 @@ assert(!instance.get_falsevar());
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert!(instance.get_truevar(), 1); assert!(instance.get_truevar(), 1);
assert!(!instance.get_falsevar(), 1); assert!(!instance.get_falsevar(), 1);
``` ```

View file

@ -48,8 +48,8 @@ assert_eq(instance.get_i2(), 50);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_untyped_d1(), 100); assert_eq!(instance.get_untyped_d1(), 100);
assert_eq!(instance.get_untyped_d2(), 3000); assert_eq!(instance.get_untyped_d2(), 3000);
assert_eq!(instance.get_untyped_d3(), 1500); assert_eq!(instance.get_untyped_d3(), 1500);

View file

@ -58,8 +58,8 @@ assert(instance.get_value());
```rust ```rust
let ratio = 1.; let ratio = 1.;
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_l1(), 12.); assert_eq!(instance.get_l1(), 12.);
assert_eq!(instance.get_l2(), 12. * ratio); assert_eq!(instance.get_l2(), 12. * ratio);
assert_eq!(instance.get_l3(), 100. + 12. * ratio); assert_eq!(instance.get_l3(), 100. + 12. * ratio);

View file

@ -26,8 +26,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_foo_a(), sixtyfps::SharedString::from("444")); assert_eq!(instance.get_foo_a(), sixtyfps::SharedString::from("444"));
assert_eq!(instance.get_foo_b(), 12); assert_eq!(instance.get_foo_b(), 12);
instance.emit_change_foo(); instance.emit_change_foo();

View file

@ -30,8 +30,8 @@ assert(!fuzzy_compare(instance.get_p1(), 1.001));
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_p1(), 1.); assert_eq!(instance.get_p1(), 1.);
assert_eq!(instance.get_p2(), 0.01); assert_eq!(instance.get_p2(), 0.01);
assert_eq!(instance.get_p3(), 0.055); assert_eq!(instance.get_p3(), 0.055);

View file

@ -37,8 +37,8 @@ assert_eq(instance.get_controlled_test_length(), 100.);
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_test_length(), 100.); assert_eq!(instance.get_test_length(), 100.);
assert_eq!(instance.get_controlled_test_length(), 20.); assert_eq!(instance.get_controlled_test_length(), 20.);

View file

@ -27,8 +27,8 @@ assert(!instance.get_e2());
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_p1(), "hello"); assert_eq!(instance.get_p1(), "hello");
assert_eq!(instance.get_p2(), "fox:🦊"); assert_eq!(instance.get_p2(), "fox:🦊");
assert!(instance.get_e1()); assert!(instance.get_e1());

View file

@ -32,8 +32,8 @@ assert(fuzzy_compare(instance.get_negative_as_float(), -1200000.1));
``` ```
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert!(instance.get_test_is_float()); assert!(instance.get_test_is_float());
assert_eq!(instance.get_number_as_float(), 42.56); assert_eq!(instance.get_number_as_float(), 42.56);
assert_eq!(instance.get_negative_as_float(), -1200000.1); assert_eq!(instance.get_negative_as_float(), -1200000.1);

View file

@ -30,8 +30,8 @@ TestCase := Rectangle {
/* /*
```rust ```rust
let instance = TestCase::new(); let handle = TestCase::new();
let instance = instance.as_ref(); let instance = handle.as_ref();
assert_eq!(instance.get_player_1().score, 12); assert_eq!(instance.get_player_1().score, 12);
assert_eq!(instance.get_player_1(), Player{ name: "Player1".into(), score: 12, energy_level: 0.8 }); assert_eq!(instance.get_player_1(), Player{ name: "Player1".into(), score: 12, energy_level: 0.8 });