Open tronical opened 8 months ago
My suggestion:
We can also simplify some code in the viewer that tries to serialize/deserialize enum values: https://github.com/slint-ui/slint/blob/6576a62d86acd94c877710fbe25753a16eac921c/tools/viewer/main.rs#L318
Add some code in the interpreter to convert Value::String to Type::Enumeration, that takes care of the setters
Ok, so given
enum Foo {
Bar,
Baz
}
and
in-out property <Foo> blub;
I suppose I should be able to assign the string "Bar" to it (via API, not in .slint of course)?
For the getter, right, we could just return a string.
In the public API for the interpreter in Rust and C++, enumerations are not supported.
Internally, they are implemented as a pair of enum name as string and enum variant as string.
Acceptance criteria for this issue is to be able to read and write properties declared in Slint that hold an enum declared in Slint, from Rust and C++ API. After implementing this, follow-up issues should be created for language bindings (JavaScript, Python) to add support there, too. When completed, #4778 can be reverted again.
For support in JavaScript and Python, it might make sense to include the exported enums as objects in the corresponding module objects the JS/Python load_file APIs create, and let each object have the enumeration variants as properties. Their value could be a fully qualified string, or something else - whatever the interpreter API accepts at that point.