-
Notifications
You must be signed in to change notification settings - Fork 614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converting enum to string #6852
Comments
I don't feel very comfortable with this. Other programming languages don't do this typically out of the box with enums and use reflection instead. And to make matters worse: this doesn't play well with translations. Perhaps we need a way to more easily create mappings? Like a match on an enum that errors when not all variants are covered. |
(in case you didn't know, it is converting to string for debugging purpose using the You can use But I agree with @tronical that this is not necessarily a good idea to have that in Slint itself. |
I suggest we don't implement this. But I'd like the ability for user to write something like this: function direction-string(dir: Direction): string {
match dir {
Direction.Left => "left",
// compiler errors out, because `Right` isn't handled here
}
} |
We already have a tracking issue for a match or switch: #1307 In the mean time, it can be done with something like: function direction-string(dir: Direction): string {
return dir == Direction.Left ? "left"
: dir == Direction.Right ? "right"
: ""; // unfortunately no errors/warnings at this point
}
} or in rust with a callback that does |
Feature Description
Currently, an enum that is defined in slint can not be given to the Text component as an input, a callback needs to be implemented in Rust to do the conversion.
Ideally, I would directly use the enum text as an input to the text.
Example:
that would be seen as "Right" on the screen.
Product Impact
We are a railway company building Remote Supervision Control Desktop application for a locomotive.
It would reduce the code and time.
The text was updated successfully, but these errors were encountered: