mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-02 06:41:14 +00:00
Start a new sixtyfps::Window API for Rust, C++, the interpreters and JS
The generated component now provides access to a Window type via the window() accessor function. This is part of #333
This commit is contained in:
parent
5fd63b63f1
commit
66891a299c
14 changed files with 200 additions and 50 deletions
|
@ -18,6 +18,7 @@ mod persistent_context;
|
|||
|
||||
struct WrappedComponentType(Option<sixtyfps_interpreter::ComponentDefinition>);
|
||||
struct WrappedComponentRc(Option<sixtyfps_interpreter::ComponentInstance>);
|
||||
struct WrappedWindow(Option<sixtyfps_interpreter::Window>);
|
||||
|
||||
/// We need to do some gymnastic with closures to pass the ExecuteContext with the right lifetime
|
||||
type GlobalContextCallback<'c> =
|
||||
|
@ -344,25 +345,14 @@ declare_types! {
|
|||
})?;
|
||||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
}
|
||||
method show(mut cx) {
|
||||
method window(mut cx) {
|
||||
let this = cx.this();
|
||||
let component = cx.borrow(&this, |x| x.0.as_ref().map(|c| c.clone_strong()));
|
||||
let component = component.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
||||
run_scoped(&mut cx,this.downcast().unwrap(), || {
|
||||
component.show();
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
}
|
||||
method hide(mut cx) {
|
||||
let this = cx.this();
|
||||
let component = cx.borrow(&this, |x| x.0.as_ref().map(|c| c.clone_strong()));
|
||||
let component = component.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
||||
run_scoped(&mut cx,this.downcast().unwrap(), || {
|
||||
component.hide();
|
||||
Ok(())
|
||||
})?;
|
||||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
let window = component.window();
|
||||
let mut obj = SixtyFpsWindow::new::<_, JsValue, _>(&mut cx, std::iter::empty())?;
|
||||
cx.borrow_mut(&mut obj, |mut obj| obj.0 = Some(window));
|
||||
Ok(obj.as_value(&mut cx))
|
||||
}
|
||||
method get_property(mut cx) {
|
||||
let prop_name = cx.argument::<JsString>(0)?.value();
|
||||
|
@ -485,6 +475,28 @@ declare_types! {
|
|||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
}
|
||||
}
|
||||
|
||||
class SixtyFpsWindow for WrappedWindow {
|
||||
init(_) {
|
||||
Ok(WrappedWindow(None))
|
||||
}
|
||||
|
||||
method show(mut cx) {
|
||||
let this = cx.this();
|
||||
let window = cx.borrow(&this, |x| x.0.as_ref().map(|c| c.clone()));
|
||||
let window = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
||||
window.show();
|
||||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
}
|
||||
|
||||
method hide(mut cx) {
|
||||
let this = cx.this();
|
||||
let window = cx.borrow(&this, |x| x.0.as_ref().map(|c| c.clone()));
|
||||
let window = window.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
||||
window.hide();
|
||||
Ok(JsUndefined::new().as_value(&mut cx))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn singleshot_timer_property(id: u32) -> String {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue