Error: 'z' must be a number literal #4739
-
I'm creating a sequence of piano keys using the following code fragment: private property<[{ offset: float, note: Note }]> note-configs: [
{ offset: 0.0, note: { octave: octave, base: BaseNote.c, accidental: Accidental.neutral } },
{ offset: 0.5, note: { octave: octave, base: BaseNote.c, accidental: Accidental.sharp } },
{ offset: 1.0, note: { octave: octave, base: BaseNote.d, accidental: Accidental.neutral } },
{ offset: 1.5, note: { octave: octave, base: BaseNote.d, accidental: Accidental.sharp } },
{ offset: 2.0, note: { octave: octave, base: BaseNote.e, accidental: Accidental.neutral } },
{ offset: 3.0, note: { octave: octave, base: BaseNote.f, accidental: Accidental.neutral } },
{ offset: 3.5, note: { octave: octave, base: BaseNote.f, accidental: Accidental.sharp } },
{ offset: 4.0, note: { octave: octave, base: BaseNote.g, accidental: Accidental.neutral } },
{ offset: 4.5, note: { octave: octave, base: BaseNote.g, accidental: Accidental.sharp } },
{ offset: 5.0, note: { octave: octave, base: BaseNote.a, accidental: Accidental.neutral } },
{ offset: 5.5, note: { octave: octave, base: BaseNote.a, accidental: Accidental.sharp } },
{ offset: 6.0, note: { octave: octave, base: BaseNote.b, accidental: Accidental.neutral } },
];
for cfg in note-configs: PianoKey {
width: parent.width / 7;
height: (self.note.accidental == Accidental.sharp)? (parent.height / 2) : parent.height;
x: cfg.offset * self.width;
y: 0;
note: cfg.note;
z: (self.note.accidental == Accidental.neutral)? 0 : 1;
} I've set up my
What's the rationale for requiring a literal value? Is there a way I can resolve this without re-ordering my model? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I suppose one option would be to split my model into the white/black keys, although in this case I would like to write something like... private property<...> note-configs = { ... };
private property<...> white-note-configs = filter(note-configs, lambda-to-select-white-keys);
private property<...> black-note-configs = filter(note-configs, lambda-to-select-black-keys); ...as this would allow me to keep my config in one place, since the need to separate the configs is driven by my need to create them in a special order. |
Beta Was this translation helpful? Give feedback.
Yes, I'd also use a central config. Writing
filter
like that is not possible in .slint code yet, but using aFilterModel
in Rust or C++ should be possible. You could have a callback that has basically the signature offilter
as you prototyped it above and instead oflambda-to-select-white-keys
you pass in the parameters you need to select the white or black keys.Dynamic z ordering it not implemented yet - tracking this in #221 .