mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Simplify signature of Component::run
We don't need to pass the root item anymore since ComponentVTable has now get_item_ref.
This commit is contained in:
parent
94ed0ae1d1
commit
02904c4014
7 changed files with 17 additions and 16 deletions
|
@ -84,7 +84,7 @@ struct ComponentWindow
|
||||||
void run(const Component *c) const
|
void run(const Component *c) const
|
||||||
{
|
{
|
||||||
sixtyfps_component_window_run(
|
sixtyfps_component_window_run(
|
||||||
&inner, vtable::VRefMut<ComponentVTable> { &Component::component_type, const_cast<Component *>(c) }, c->root_item());
|
&inner, vtable::VRefMut<ComponentVTable> { &Component::component_type, const_cast<Component *>(c) });
|
||||||
}
|
}
|
||||||
|
|
||||||
float scale_factor() const { return sixtyfps_component_window_get_scale_factor(&inner); }
|
float scale_factor() const { return sixtyfps_component_window_get_scale_factor(&inner); }
|
||||||
|
|
|
@ -329,7 +329,7 @@ declare_types! {
|
||||||
let component = cx.borrow(&mut this, |x| x.0.clone());
|
let component = cx.borrow(&mut this, |x| x.0.clone());
|
||||||
let component = component.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
let component = component.ok_or(()).or_else(|()| cx.throw_error("Invalid type"))?;
|
||||||
run_scoped(&mut cx,this.downcast().unwrap(), || {
|
run_scoped(&mut cx,this.downcast().unwrap(), || {
|
||||||
component.window().run(component.borrow(), component.borrow_instance().root_item());
|
component.window().run(component.borrow());
|
||||||
Ok(())
|
Ok(())
|
||||||
})?;
|
})?;
|
||||||
Ok(JsUndefined::new().as_value(&mut cx))
|
Ok(JsUndefined::new().as_value(&mut cx))
|
||||||
|
|
|
@ -127,6 +127,6 @@ impl WrappedCompiledComp {
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
pub fn run(&self, canvas_id: String) {
|
pub fn run(&self, canvas_id: String) {
|
||||||
let component = self.0.clone().create(canvas_id);
|
let component = self.0.clone().create(canvas_id);
|
||||||
component.window().run(component.borrow(), component.borrow_instance().root_item());
|
component.window().run(component.borrow());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -572,8 +572,6 @@ fn generate_component(
|
||||||
maybe_window_field_decl = Some(quote!(pub window: sixtyfps::re_exports::ComponentWindow));
|
maybe_window_field_decl = Some(quote!(pub window: sixtyfps::re_exports::ComponentWindow));
|
||||||
maybe_window_field_init = Some(quote!(window: sixtyfps::create_window()));
|
maybe_window_field_init = Some(quote!(window: sixtyfps::create_window()));
|
||||||
|
|
||||||
let root_elem = component.root_element.borrow();
|
|
||||||
let root_item_name = format_ident!("{}", root_elem.id);
|
|
||||||
visibility = Some(quote!(pub));
|
visibility = Some(quote!(pub));
|
||||||
|
|
||||||
has_window_impl = Some(quote!(
|
has_window_impl = Some(quote!(
|
||||||
|
@ -585,8 +583,7 @@ fn generate_component(
|
||||||
impl sixtyfps::Component for #component_id {
|
impl sixtyfps::Component for #component_id {
|
||||||
fn run(self: ::core::pin::Pin<&Self>) {
|
fn run(self: ::core::pin::Pin<&Self>) {
|
||||||
use sixtyfps::re_exports::*;
|
use sixtyfps::re_exports::*;
|
||||||
let root_item = Self::FIELD_OFFSETS.#root_item_name.apply_pin(self);
|
self.as_ref().window.run(VRef::new_pin(self.as_ref()));
|
||||||
self.as_ref().window.run(VRef::new_pin(self.as_ref()), VRef::new_pin(root_item));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
))
|
))
|
||||||
|
|
|
@ -14,7 +14,6 @@ LICENSE END */
|
||||||
aspects of windows on the screen.
|
aspects of windows on the screen.
|
||||||
*/
|
*/
|
||||||
use crate::component::ComponentVTable;
|
use crate::component::ComponentVTable;
|
||||||
use crate::items::ItemRef;
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::{
|
use std::{
|
||||||
convert::TryInto,
|
convert::TryInto,
|
||||||
|
@ -70,11 +69,15 @@ pub trait GenericWindow {
|
||||||
/// Arguments:
|
/// Arguments:
|
||||||
/// * `event_loop`: The event loop used to drive further event handling for this window
|
/// * `event_loop`: The event loop used to drive further event handling for this window
|
||||||
/// as it will receive events.
|
/// as it will receive events.
|
||||||
/// * `root_item`: The root item of the scene. If the item is a [`crate::items::Window`], then
|
/// * `component`: The component that holds the root item of the scene. If the item is a [`crate::items::Window`], then
|
||||||
/// the `width` and `height` properties are read and the values are passed to the windowing system as request
|
/// the `width` and `height` properties are read and the values are passed to the windowing system as request
|
||||||
/// for the initial size of the window. Then bindings are installed on these properties to keep them up-to-date
|
/// for the initial size of the window. Then bindings are installed on these properties to keep them up-to-date
|
||||||
/// with the size as it may be changed by the user or the windowing system in general.
|
/// with the size as it may be changed by the user or the windowing system in general.
|
||||||
fn map_window(self: Rc<Self>, event_loop: &EventLoop, root_item: Pin<ItemRef>);
|
fn map_window(
|
||||||
|
self: Rc<Self>,
|
||||||
|
event_loop: &EventLoop,
|
||||||
|
component: core::pin::Pin<crate::component::ComponentRef>,
|
||||||
|
);
|
||||||
/// Removes the window from the screen. The window is not destroyed though, it can be show (mapped) again later
|
/// Removes the window from the screen. The window is not destroyed though, it can be show (mapped) again later
|
||||||
/// by calling [`GenericWindow::map_window`].
|
/// by calling [`GenericWindow::map_window`].
|
||||||
fn unmap_window(self: Rc<Self>);
|
fn unmap_window(self: Rc<Self>);
|
||||||
|
@ -140,10 +143,10 @@ impl ComponentWindow {
|
||||||
Self(window_impl)
|
Self(window_impl)
|
||||||
}
|
}
|
||||||
/// Spins an event loop and renders the items of the provided component in this window.
|
/// Spins an event loop and renders the items of the provided component in this window.
|
||||||
pub fn run(&self, component: Pin<VRef<ComponentVTable>>, root_item: Pin<ItemRef>) {
|
pub fn run(&self, component: Pin<VRef<ComponentVTable>>) {
|
||||||
let event_loop = crate::eventloop::EventLoop::new();
|
let event_loop = crate::eventloop::EventLoop::new();
|
||||||
|
|
||||||
self.0.clone().map_window(&event_loop, root_item);
|
self.0.clone().map_window(&event_loop, component);
|
||||||
|
|
||||||
event_loop.run(component);
|
event_loop.run(component);
|
||||||
|
|
||||||
|
@ -581,10 +584,9 @@ pub mod ffi {
|
||||||
pub unsafe extern "C" fn sixtyfps_component_window_run(
|
pub unsafe extern "C" fn sixtyfps_component_window_run(
|
||||||
handle: *const ComponentWindowOpaque,
|
handle: *const ComponentWindowOpaque,
|
||||||
component: Pin<VRef<ComponentVTable>>,
|
component: Pin<VRef<ComponentVTable>>,
|
||||||
root_item: Pin<VRef<ItemVTable>>,
|
|
||||||
) {
|
) {
|
||||||
let window = &*(handle as *const ComponentWindow);
|
let window = &*(handle as *const ComponentWindow);
|
||||||
window.run(component, root_item);
|
window.run(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the window scale factor.
|
/// Returns the window scale factor.
|
||||||
|
|
|
@ -639,7 +639,7 @@ impl<Backend: GraphicsBackend> crate::eventloop::GenericWindow for GraphicsWindo
|
||||||
fn map_window(
|
fn map_window(
|
||||||
self: Rc<Self>,
|
self: Rc<Self>,
|
||||||
event_loop: &crate::eventloop::EventLoop,
|
event_loop: &crate::eventloop::EventLoop,
|
||||||
root_item: Pin<ItemRef>,
|
component: core::pin::Pin<crate::component::ComponentRef>,
|
||||||
) {
|
) {
|
||||||
if matches!(&*self.map_state.borrow(), GraphicsWindowBackendState::Mapped(..)) {
|
if matches!(&*self.map_state.borrow(), GraphicsWindowBackendState::Mapped(..)) {
|
||||||
return;
|
return;
|
||||||
|
@ -670,6 +670,8 @@ impl<Backend: GraphicsBackend> crate::eventloop::GenericWindow for GraphicsWindo
|
||||||
|
|
||||||
let mut new_size = existing_size;
|
let mut new_size = existing_size;
|
||||||
|
|
||||||
|
let root_item = component.as_ref().get_item_ref(0);
|
||||||
|
|
||||||
if let Some(window_item) = ItemRef::downcast_pin(root_item) {
|
if let Some(window_item) = ItemRef::downcast_pin(root_item) {
|
||||||
let width =
|
let width =
|
||||||
crate::items::Window::FIELD_OFFSETS.width.apply_pin(window_item).get();
|
crate::items::Window::FIELD_OFFSETS.width.apply_pin(window_item).get();
|
||||||
|
|
|
@ -44,6 +44,6 @@ fn main() -> std::io::Result<()> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let component = c.create();
|
let component = c.create();
|
||||||
component.window().run(component.borrow(), component.borrow_instance().root_item());
|
component.window().run(component.borrow());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue