-
Notifications
You must be signed in to change notification settings - Fork 644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ability to embed slint component from different source #2390
Comments
We were also discussing that the |
The question is whether a I'm sure people will try things like this
So i'm just afraid that the |
You're right, |
Back in the meeting, we also discussed the concept of component factory. And in fact, i think we should revisit this option.
in rust let foobar = FooBar::new().unwrap();
// `component-factory` takes a `Rc<dyn slint::ComponentFactory>`
foobar.set_my_component_factory(Rc::new(MyComponentFactory::new()));
impl slint::ComponentFactory for MyComponentFactory {
fn build_component(&self) -> ComponentHandle {
let result = self.the_component_definition.create();
// store so we can update it with property changes.
self.current_component.borrow_mut() = result.as_weak()
result
}
} |
I think the The problem I am struggling with right now is that I have a Setting the parent node on a component is not supported via the |
True, we may need to change ComponentHandle to no longer have an Inner, or create a new trait that can be used as a trait object.
I'm thinking having a set_parent_node may be the simpler. The wrapper option might be complicated, because the inner node of a repeated component will have a weak pointer to the non-wrapper as a parent. |
Only if we use /// Wrapper around something that implements ComponentHandle.
/// Can be constructed with `ComponentInstance::from(my_component)` where my_component immplements
/// the ComponentHandle trait. (eg: slint_interpreter::ComponentInstance or the type generated from
/// the slint code.
///
/// FIXME: naming?
pub struct ComponentInstance(crate::component::ComponentRc);
impl<T: ComponentHandle> From<T> for ComponentInstance
where
T::Inner: vtable::HasStaticVTable<ComponentVTable> + 'static,
{
fn from(value: T) -> Self {
Self(vtable::VRc::into_dyn(value.as_weak().inner().upgrade().unwrap()))
}
}
/// The type `component-factory` in slint maps to a Rc<dyn ComponentFactory>
pub trait ComponentFactory {
fn build(&self) -> ComponentInstance;
} This is going to make C++ a bit tricky because |
I see |
Only if you set We do have an experimental feature adding a But yes, the idea is to allow arbitrary components (e.g. generated by the slint interpreter or by some dynamically loaded rust code) by having a Again: Use with care, this may or may not land in Slint and it will definitely change API/ABI before it becomes stable. |
Use case:
We would introduce a new
component
property type, and aEmbed
builtin element:The generated code for the setter would be something like
We should try to create the window adapter lazily because the
Embed
will set it when the sub-tree is visited (by its surrounding WindowAdapter)The geometry constraints are forwarded from the embedded component to the
Embedd
element.There will be a two way binding for the width and height of the Embedd element, and its component.
If a component is used several times, we need to do either:
The Embed should know its source location at runtime to give the developer some idea on where the error came from.
The text was updated successfully, but these errors were encountered: