mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Remove the component parameter from GenericWindow::process_key_input
This commit is contained in:
parent
516680ad5d
commit
a2dadf8fe8
6 changed files with 36 additions and 65 deletions
|
@ -20,16 +20,15 @@ template<typename Component>
|
|||
inline void send_mouse_click(const Component &component, float x, float y)
|
||||
{
|
||||
cbindgen_private::sixtyfps_send_mouse_click(
|
||||
{ &Component::component_type, const_cast<Component *>(&component) },
|
||||
x, y, &component.window);
|
||||
{ &Component::component_type, const_cast<Component *>(&component) }, x, y,
|
||||
&component.window);
|
||||
}
|
||||
|
||||
template<typename Component>
|
||||
inline void send_keyboard_string_sequence(const Component &component, const sixtyfps::SharedString &str)
|
||||
inline void send_keyboard_string_sequence(const Component &component,
|
||||
const sixtyfps::SharedString &str)
|
||||
{
|
||||
cbindgen_private::send_keyboard_string_sequence(
|
||||
{ &Component::component_type, const_cast<Component *>(&component) },
|
||||
&str, &component.window);
|
||||
cbindgen_private::send_keyboard_string_sequence(&str, &component.window);
|
||||
}
|
||||
|
||||
#define assert_eq(A, B) \
|
||||
|
|
|
@ -454,7 +454,7 @@ declare_types! {
|
|||
let comp = this.borrow(&lock).0.clone();
|
||||
let component = comp.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
||||
run_scoped(&mut cx,this.downcast().unwrap(), || {
|
||||
sixtyfps_corelib::tests::send_keyboard_string_sequence(component.borrow(), &sequence.into(), &component.window());
|
||||
sixtyfps_corelib::tests::send_keyboard_string_sequence(&sequence.into(), &component.window());
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
|
|
|
@ -335,7 +335,6 @@ pub mod testing {
|
|||
key_codes: &[crate::re_exports::KeyCode],
|
||||
) {
|
||||
sixtyfps_corelib::tests::sixtyfps_send_key_clicks(
|
||||
vtable::VRef::new_pin(component),
|
||||
&crate::re_exports::Slice::from_slice(key_codes),
|
||||
component.component_window(),
|
||||
)
|
||||
|
@ -349,7 +348,6 @@ pub mod testing {
|
|||
sequence: &str,
|
||||
) {
|
||||
sixtyfps_corelib::tests::send_keyboard_string_sequence(
|
||||
vtable::VRef::new_pin(component),
|
||||
&super::SharedString::from(sequence),
|
||||
component.component_window(),
|
||||
)
|
||||
|
|
|
@ -59,11 +59,7 @@ pub trait GenericWindow {
|
|||
/// Arguments:
|
||||
/// * `event`: The key event received by the windowing system.
|
||||
/// * `component`: The SixtyFPS compiled component that provides the tree of items.
|
||||
fn process_key_input(
|
||||
self: Rc<Self>,
|
||||
event: &KeyEvent,
|
||||
component: core::pin::Pin<crate::component::ComponentRef>,
|
||||
);
|
||||
fn process_key_input(self: Rc<Self>, event: &KeyEvent);
|
||||
/// Calls the `callback` function with the underlying winit::Window that this
|
||||
/// GenericWindow backs.
|
||||
fn with_platform_window(&self, callback: &dyn Fn(&winit::window::Window));
|
||||
|
@ -190,12 +186,8 @@ impl ComponentWindow {
|
|||
self.0.clone().current_keyboard_modifiers()
|
||||
}
|
||||
|
||||
pub(crate) fn process_key_input(
|
||||
&self,
|
||||
event: &KeyEvent,
|
||||
component: core::pin::Pin<crate::component::ComponentRef>,
|
||||
) {
|
||||
self.0.clone().process_key_input(event, component)
|
||||
pub(crate) fn process_key_input(&self, event: &KeyEvent) {
|
||||
self.0.clone().process_key_input(event)
|
||||
}
|
||||
|
||||
/// Clears the focus on any previously focused item and makes the provided
|
||||
|
@ -434,7 +426,7 @@ impl EventLoop {
|
|||
if let Some(ref key_event) =
|
||||
(input, window.current_keyboard_modifiers()).try_into().ok()
|
||||
{
|
||||
window.clone().process_key_input(key_event, component);
|
||||
window.clone().process_key_input(key_event);
|
||||
// FIXME: remove this, it should be based on actual changes rather than this
|
||||
window.request_redraw();
|
||||
}
|
||||
|
@ -458,7 +450,7 @@ impl EventLoop {
|
|||
unicode_scalar: ch.into(),
|
||||
modifiers,
|
||||
};
|
||||
window.clone().process_key_input(&key_event, component);
|
||||
window.clone().process_key_input(&key_event);
|
||||
// FIXME: remove this, it should be based on actual changes rather than this
|
||||
window.request_redraw();
|
||||
}
|
||||
|
|
|
@ -631,12 +631,11 @@ impl<Backend: GraphicsBackend> crate::eventloop::GenericWindow for GraphicsWindo
|
|||
);
|
||||
}
|
||||
|
||||
fn process_key_input(
|
||||
self: Rc<Self>,
|
||||
event: &KeyEvent,
|
||||
component: core::pin::Pin<crate::component::ComponentRef>,
|
||||
) {
|
||||
component.as_ref().key_event(event, &crate::eventloop::ComponentWindow::new(self.clone()));
|
||||
fn process_key_input(self: Rc<Self>, event: &KeyEvent) {
|
||||
let component = self.component.borrow().upgrade().unwrap();
|
||||
ComponentRc::borrow_pin(&component)
|
||||
.as_ref()
|
||||
.key_event(event, &crate::eventloop::ComponentWindow::new(self.clone()));
|
||||
}
|
||||
|
||||
fn with_platform_window(&self, callback: &dyn Fn(&winit::window::Window)) {
|
||||
|
|
|
@ -65,32 +65,24 @@ pub extern "C" fn sixtyfps_set_keyboard_modifiers(
|
|||
/// Simulate a key down event.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn sixtyfps_send_key_clicks(
|
||||
component: core::pin::Pin<crate::component::ComponentRef>,
|
||||
key_codes: &crate::slice::Slice<crate::input::KeyCode>,
|
||||
window: &crate::eventloop::ComponentWindow,
|
||||
) {
|
||||
for key_code in key_codes.iter() {
|
||||
window.process_key_input(
|
||||
&crate::input::KeyEvent::KeyPressed {
|
||||
code: *key_code,
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
},
|
||||
component,
|
||||
);
|
||||
window.process_key_input(
|
||||
&crate::input::KeyEvent::KeyReleased {
|
||||
code: *key_code,
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
},
|
||||
component,
|
||||
);
|
||||
window.process_key_input(&crate::input::KeyEvent::KeyPressed {
|
||||
code: *key_code,
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
});
|
||||
window.process_key_input(&crate::input::KeyEvent::KeyReleased {
|
||||
code: *key_code,
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Simulate a character input event.
|
||||
#[no_mangle]
|
||||
pub extern "C" fn send_keyboard_string_sequence(
|
||||
component: core::pin::Pin<crate::component::ComponentRef>,
|
||||
sequence: &crate::SharedString,
|
||||
window: &crate::eventloop::ComponentWindow,
|
||||
) {
|
||||
|
@ -98,25 +90,19 @@ pub extern "C" fn send_keyboard_string_sequence(
|
|||
|
||||
let key_down = |maybe_code: &Option<crate::input::KeyCode>| {
|
||||
maybe_code.clone().map(|code| {
|
||||
window.process_key_input(
|
||||
&crate::input::KeyEvent::KeyPressed {
|
||||
code: code,
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
},
|
||||
component,
|
||||
);
|
||||
window.process_key_input(&crate::input::KeyEvent::KeyPressed {
|
||||
code: code,
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
let key_up = |maybe_code: &Option<crate::input::KeyCode>| {
|
||||
maybe_code.clone().map(|code| {
|
||||
window.process_key_input(
|
||||
&crate::input::KeyEvent::KeyReleased {
|
||||
code: code,
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
},
|
||||
component,
|
||||
);
|
||||
window.process_key_input(&crate::input::KeyEvent::KeyReleased {
|
||||
code: code,
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -131,13 +117,10 @@ pub extern "C" fn send_keyboard_string_sequence(
|
|||
|
||||
key_down(&maybe_key_code);
|
||||
|
||||
window.process_key_input(
|
||||
&crate::input::KeyEvent::CharacterInput {
|
||||
unicode_scalar: ch.into(),
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
},
|
||||
component,
|
||||
);
|
||||
window.process_key_input(&crate::input::KeyEvent::CharacterInput {
|
||||
unicode_scalar: ch.into(),
|
||||
modifiers: window.current_keyboard_modifiers(),
|
||||
});
|
||||
|
||||
key_up(&maybe_key_code);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue