How to write/register truly native components? #5315
-
At the moment, slint components are just slint files. It can only hold slint values like color/brush/modelRc/string etc.. And the only way components can render themselves is by using Text or Rectangle or Path components. But how would I write a widget like video player? To use qml as a reference, the VideoOutput component contains a video sink property which holds a native c++ QVideoSink object. I think qt can register QObjects as QML objects, and they are exposed to qml as any other Component. And when the object is destroyed in qml, it simply calls the native object's destructor too. I want to do something similar for slint components. In particular, I want to use skia and expose more drawing primitives (eg: skia's backdrop blur shaders or paint object). I can probably just set some native callbacks in a global for common drawing routines, But, I cannot figure out how to make a component own some native object (like skia's paint) and pass it around as parameter to these native callbacks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Hi @coderedart, I meantime to help you with your video player. There is an example to display a video in Slint https://github.com/slint-ui/slint/tree/master/examples/ffmpeg. This way it is difficult to create a truly shareable video widget, but it could be a start. And for the custom drawing with skia part. What works always is to draw something, create an |
Beta Was this translation helpful? Give feedback.
-
"@tronical had worked on a prototype. If I remember right he want to continue to work on this topic soon." As far as I know Slint compiler creates Rust code that is compiled to native. Is this correct? In opposite the Python-API can work with interpreted Slint-Code only. |
Beta Was this translation helpful? Give feedback.
Currently to provide pre-compiled Slint components e.g. in a separate crate and use them in you application project does not work or am I wrong @tronical? What you can do is to ship slint files with your plugin you can use my custom widget crate as example
What you also can do is to ship generic functionality that is based on types from the slint-ui crate. For example I have done an generic keyboard selection behavior for models in Slint https://codeberg.org/flovansl/co_sl/src/branch/main/apps/coop_local/rust/src/item_selector.rs