diff --git a/api/sixtyfps-cpp/include/sixtyfps_interpreter.h b/api/sixtyfps-cpp/include/sixtyfps_interpreter.h index 055bd4655..958b31668 100644 --- a/api/sixtyfps-cpp/include/sixtyfps_interpreter.h +++ b/api/sixtyfps-cpp/include/sixtyfps_interpreter.h @@ -220,6 +220,12 @@ private: /// It is also possible to query the type the value holds by calling the Value::type() /// function. /// +/// Note that models are only represented in one direction: You can create a sixtyfps::Model +/// in C++, store it in a std::shared_ptr and construct Value from it. Then you can set it on a +/// property in your .60 code that was declared to be either an array (`property <[sometype]> foo;`) +/// or an object literal (`property <{foo: string, bar: int}> myprop;`). Such properties are dynamic +/// and accept models implemented in C++. +/// /// ``` /// Value v(42.0); // Creates a value that holds a double with the value 42. /// @@ -306,10 +312,6 @@ public: /// Type::Array, otherwise an empty optional is returned. inline std::optional> to_array() const; - /// Returns a std::optional that contains a model of values if the type of this Value is - /// Type::Model, otherwise an empty optional is returned. - std::optional>> to_model() const; - /// Returns a std::optional that contains a brush if the type of this Value is /// Type::Brush, otherwise an empty optional is returned. std::optional to_brush() const diff --git a/api/sixtyfps-cpp/tests/interpreter.cpp b/api/sixtyfps-cpp/tests/interpreter.cpp index 76d000ed7..b9adcf949 100644 --- a/api/sixtyfps-cpp/tests/interpreter.cpp +++ b/api/sixtyfps-cpp/tests/interpreter.cpp @@ -337,3 +337,39 @@ SCENARIO("Invoke callback") REQUIRE(!res.has_value()); } } + +SCENARIO("Array between .60 and C++") +{ + using namespace sixtyfps::interpreter; + using namespace sixtyfps; + + ComponentCompiler compiler; + + auto result = compiler.build_from_source( + "export Dummy := Rectangle { property <[int]> array: [1, 2, 3]; }", ""); + REQUIRE(result.has_value()); + auto instance = result->create(); + + SECTION(".60 to C++") + { + auto maybe_array = instance->get_property("array"); + REQUIRE(maybe_array.has_value()); + REQUIRE(maybe_array->type() == Value::Type::Array); + + auto array = *maybe_array; + REQUIRE(array == sixtyfps::SharedVector { Value(1.), Value(2.), Value(3.) }); + } + + SECTION("C++ to .60") + { + sixtyfps::SharedVector cpp_array { Value(4.), Value(5.), Value(6.) }; + + instance->set_property("array", Value(cpp_array)); + auto maybe_array = instance->get_property("array"); + REQUIRE(maybe_array.has_value()); + REQUIRE(maybe_array->type() == Value::Type::Array); + + auto actual_array = *maybe_array; + REQUIRE(actual_array == cpp_array); + } +}