Skip to content

String conversions for custom enums / structs #4737

Answered by tronical
mitchgrout asked this question in Q&A
Discussion options

You must be logged in to vote

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

struct Note {
    ...
}

export component NoteLabel {
    in property <Note> note;
    HorizontalLayout {
        Text {
            text: ...;
        }
        Image {
            source: icon-for-octave(note.octave);
        }
    }
}

So perhaps that gives you more freedom in the future beyond text, while still providing you with some degree of encapsulation?

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mitchgrout
Comment options

@tronical
Comment options

Answer selected by mitchgrout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants