slint icon indicating copy to clipboard operation
slint copied to clipboard

Default values for struct fields

Open ogoffart opened this issue 1 year ago • 3 comments

It is often requested to have default values for struct fields

It could look like this:

struct Player {
     score: int = -1,
     name: string = "John Smith",
}

Then, when initialized, or converted from a struct with less fields, the other fields are initialized with thei default value:

component X {
   // initialized to default values
   property <Player> player1;
   // score will be -1
   property <Player> player2: { name: "Alex" };
}

The Default implementation of the rust structure or C++ default constructor must initialize the fields accordingly.

ogoffart avatar Jun 20 '23 05:06 ogoffart