String conversions for custom enums / structs #4737
-
Is it possible to define a conversion to export enum BaseNote { a, b, c, d, e, f, g }
export enum Accidental { flat, neutral, sharp }
export struct Note
{
octave: int,
note: BaseNote,
accidental: Accidental,
}
export component PianoKey inherits Rectangle{
in property<Note> note;
border-color: black;
border-width: 1px;
background: (note.accidental == Accidental.neutral)? white : black;
if (note.accidental == Accidental.neutral) : Text {
text: ?;
}
} Preferably, I could fill this hole with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Interesting point. It sounds like not necessarily a conversion to a string as-is but rather a conversion to a string for the purpose of displaying to the user - which fits into the needs for a UI. That said, I think perhaps it would make more sense to provide this as a component? Like
So perhaps that gives you more freedom in the future beyond text, while still providing you with some degree of encapsulation? |
Beta Was this translation helpful? Give feedback.
Interesting point. It sounds like not necessarily a conversion to a string as-is but rather a conversion to a string for the purpose of displaying to the user - which fits into the needs for a UI.
That said, I think perhaps it would make more sense to provide this as a component? Like
So perhaps that gives you more freedom in the future beyond text, while still providing you with some degree of encapsulation?