Function loadSource

  • Loads the given Slint source code and returns an object that contains a function to construct the exported component of the Slint source code.

    The following example loads a "Hello World" style Slint source code and changes the Text label to a new greeting:

    import * as slint from "slint-ui";
    const source = `export component Main {
    in-out property <string> greeting <=> label.text;
    label := Text {
    text: "Hello World";
    }
    }`; // The content of main.slint
    let ui = slint.loadSource(source, "main.js");
    let main = new ui.Main();
    main.greeting = "Hello friends";

    Parameters

    • source: string

      The Slint source code to load.

    • filePath: string

      A path to the file to show log. If the path is a relative path, then it is resolved against the process' working directory.

    • Optional options: LoadFileOptions

      Use LoadFileOptions to configure additional Slint compilation aspects, such as include search paths, library imports, or the widget style.

    Returns Object

    The returned object is sealed and provides a property by the name of the component exported in the .slint file. In the above example the name of the property is Main. The property is a constructor function. Use it with the new operator to instantiate the component. The instantiated object exposes properties and callbacks, and implements the ComponentHandle interface. For more details about the exposed properties, see Instantiating A Component.

    Throws

    CompileError if errors occur during compilation.