Skip to content

Interfaces for style #1870

@ogoffart

Description

@ogoffart

Currently, the style must re-implement a lot of components, but there is nothing that checks that these component have the same interface/properties.

The idea would be to build interfaces like so:
(based on the current interface of Button https://docs.rs/slint/latest/slint/docs/widgets/index.html#button)

interface Button {
   in property <string> text;
   in property <bool> checkable;
   in-out property <string> checked;
   out property <bool> pressed;
   in property <image> icon;
   callback clicked();
}

Then, the style would have to implement this interface:

// FIXME should we import that? from where, should it be bluit-in
import { Button } from "std.slint"; 

component MyStyleButton implements Button {
   pressed: ta.pressed; // can set output properties
   Text { text: root.text } // can access property
   ta := TouchArea { clicked => { root.clicked() } } // call callbacks
   
   in property <int> extra_prop; // ERROR!  not allowed to add public properties
}

// re-export the MyStyleButton as the Button of our style
export MyStyleButton as Button;

It is a bit akward to have to go through MyStyleButton as a separate name, maybe we could allow component Button implements Button {...} and have different namespace for components and for interface.

Unresolved question:

  • How do we make sure that the style implements all the widgets?
  • How do we make sure that a style don't export more than the required widget?
  • Is it a breaking change, in Slint, to add more widgets? Should we add some sort of versioning?
  • Should the interface allow to also have some logic in them?
  • What about widgets like TabWidget or ListView that needs compiler support?
  • Should we even allow users to declare new interface, or are these just be builtin?

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:language-slintCompiler for the .slint language (mO,bF)rfcRequest for comments: proposals for changes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions