Surrealism-All / SurrealismUI

A third-party UI library using Slint, I think it will give you an extraordinary experience
https://surrealism-all.github.io/SurrealismUI.github.io/
MIT License
216 stars 20 forks source link

如何复用SSelect组件? #37

Closed agkyunromb closed 5 months ago

agkyunromb commented 5 months ago
use slint::slint;

fn main() {
    slint! {
        import { SSelect } from "../SurrealismUI/index.slint";

        export component MySelectToReUse inherits SSelect{
            options: [
                {id:0,label:"bar",value:"bar"},
                {id:1,label:"barr",value:"barr"},
            ];
        }

        export component App inherits Window {

            MySelectToReUse {}
            MySelectToReUse {}
        }

    }

    let app = App::new().unwrap();

    app.run().unwrap();
}

rust编译器报错: "proc macro panicked\nmessage: called Option::unwrap() on a None value"

实际上一个 MySelectToReUse {} 就报错了。 是不是使用的姿势不对?

syf20020816 commented 5 months ago

经过检查是因为init这个全局回调导致的问题,这个问题目前Slint官方并没有对其进行处理,我在多数组件中移除了init回调,看来漏掉了Select,我会在这周末发布的0.4.5版本中修复这个问题

syf20020816 commented 5 months ago

不过并不是所有组件都可以移除init这个回调的,目前collapse, tab, persona, switch这几个组件无法移除init,否则会影响正常使用,因此对于无法移除init回调的组件你应该使用下面这种方式:

component MyComponent{
     // copy what you need to use from switch component source code
     in property <length> switch-height;
     SSwitch{
          switch-height: root.switch-height;
          // ....
     }
}
syf20020816 commented 5 months ago

now it solved: commit url