mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Move field accessors from Value to Struct in C++
This commit is contained in:
parent
3335ff8da5
commit
c6740fe592
2 changed files with 64 additions and 22 deletions
|
@ -128,10 +128,12 @@ SCENARIO("Value API")
|
|||
SECTION("Construct a model")
|
||||
{
|
||||
// And test that it is properly destroyed when the value is destroyed
|
||||
struct M : sixtyfps::VectorModel<Value> {
|
||||
struct M : sixtyfps::VectorModel<Value>
|
||||
{
|
||||
bool *destroyed;
|
||||
explicit M(bool *destroyed) : destroyed(destroyed) {}
|
||||
void play() {
|
||||
explicit M(bool *destroyed) : destroyed(destroyed) { }
|
||||
void play()
|
||||
{
|
||||
this->push_back(Value(4.));
|
||||
this->set_row_data(0, Value(9.));
|
||||
}
|
||||
|
@ -155,3 +157,18 @@ SCENARIO("Value API")
|
|||
}
|
||||
}
|
||||
|
||||
SCENARIO("Struct API")
|
||||
{
|
||||
using namespace sixtyfps::interpreter;
|
||||
Struct struc;
|
||||
|
||||
REQUIRE(!struc.get_field("not_there"));
|
||||
|
||||
struc.set_field("field_a", Value(true));
|
||||
|
||||
auto value_opt = struc.get_field("field_a");
|
||||
REQUIRE(value_opt.has_value());
|
||||
auto value = value_opt.value();
|
||||
REQUIRE(value.to_bool().has_value());
|
||||
REQUIRE(value.to_bool().value() == true);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue