|
|
@@ -79,6 +79,8 @@ static const String document_rml = R"(
|
|
|
<p>{{ s3.val }}</p>
|
|
|
<p>{{ s4.val }}</p>
|
|
|
<p>{{ s5.val }}</p>
|
|
|
+<p>{{ simple }}</p>
|
|
|
+<p>{{ scoped }}</p>
|
|
|
|
|
|
<h1>Basic</h1>
|
|
|
<p>{{ basic.a }}</p>
|
|
|
@@ -87,6 +89,8 @@ static const String document_rml = R"(
|
|
|
<p>{{ basic.d }}</p>
|
|
|
<p>{{ basic.e }}</p>
|
|
|
<p>{{ basic.f }}</p>
|
|
|
+<p id="simple" data-event-click="basic.simple = 2">{{ basic.simple }}</p>
|
|
|
+<p>{{ basic.scoped }}</p>
|
|
|
|
|
|
<h1>Wrapped</h1>
|
|
|
<p>{{ wrapped.a.val }}</p>
|
|
|
@@ -184,12 +188,19 @@ struct StringWrap {
|
|
|
String val;
|
|
|
};
|
|
|
|
|
|
+enum SimpleEnum { Simple_Zero = 0, Simple_One, Simple_Two };
|
|
|
+
|
|
|
+enum class ScopedEnum : uint64_t { Zero = 0, One, Two };
|
|
|
+
|
|
|
struct Globals {
|
|
|
int i0 = 0;
|
|
|
int* i1 = new int(1);
|
|
|
UniquePtr<int> i2 = MakeUnique<int>(2);
|
|
|
SharedPtr<int> i3 = MakeShared<int>(3);
|
|
|
|
|
|
+ SimpleEnum simple = Simple_One;
|
|
|
+ ScopedEnum scoped = ScopedEnum::One;
|
|
|
+
|
|
|
String s0 = "s0";
|
|
|
String* s1 = new String("s1");
|
|
|
StringWrap s2 = StringWrap("s2");
|
|
|
@@ -209,6 +220,9 @@ struct Basic {
|
|
|
int a = 1;
|
|
|
int* b = new int(2);
|
|
|
|
|
|
+ SimpleEnum simple = Simple_One;
|
|
|
+ ScopedEnum scoped = ScopedEnum::One;
|
|
|
+
|
|
|
int GetC()
|
|
|
{
|
|
|
static int v = 5;
|
|
|
@@ -345,6 +359,8 @@ bool InitializeDataBindings(Context* context)
|
|
|
constructor.Bind("s4", &globals.s4);
|
|
|
constructor.Bind("s5", &globals.s5);
|
|
|
|
|
|
+ constructor.Bind("simple", &globals.simple);
|
|
|
+ constructor.Bind("scoped", &globals.scoped);
|
|
|
// Invalid: Each of the following should give a compile-time failure.
|
|
|
// constructor.Bind("x0", &globals.x0);
|
|
|
// constructor.Bind("x1", &globals.x1);
|
|
|
@@ -361,6 +377,8 @@ bool InitializeDataBindings(Context* context)
|
|
|
handle.RegisterMember("d", &Basic::GetD);
|
|
|
handle.RegisterMember("e", &Basic::GetE);
|
|
|
handle.RegisterMember("f", &Basic::GetF);
|
|
|
+ handle.RegisterMember("simple", &Basic::simple);
|
|
|
+ handle.RegisterMember("scoped", &Basic::scoped);
|
|
|
|
|
|
// handle.RegisterMember("x0", &Basic::x0);
|
|
|
// handle.RegisterMember("x1", &Basic::x1);
|
|
|
@@ -486,3 +504,51 @@ TEST_CASE("databinding.aliasing")
|
|
|
|
|
|
TestsShell::ShutdownShell();
|
|
|
}
|
|
|
+
|
|
|
+static const String set_enum_rml = R"(
|
|
|
+<rml>
|
|
|
+<head>
|
|
|
+ <title>Test</title>
|
|
|
+ <link type="text/template" href="/assets/window.rml"/>
|
|
|
+ <style>
|
|
|
+ body.window {
|
|
|
+ width: 500px;
|
|
|
+ height: 400px;
|
|
|
+ }
|
|
|
+ </style>
|
|
|
+</head>
|
|
|
+<body template="window">
|
|
|
+<div data-model="basics">
|
|
|
+<p id="simple" data-event-click="simple = 2">{{ simple }}</p>
|
|
|
+</div>
|
|
|
+</body>
|
|
|
+</rml>
|
|
|
+)";
|
|
|
+
|
|
|
+TEST_CASE("databinding.set_enum")
|
|
|
+{
|
|
|
+ Context* context = TestsShell::GetContext();
|
|
|
+ REQUIRE(context);
|
|
|
+
|
|
|
+ globals.simple = Simple_One;
|
|
|
+
|
|
|
+ REQUIRE(InitializeDataBindings(context));
|
|
|
+
|
|
|
+ ElementDocument* document = context->LoadDocumentFromMemory(set_enum_rml);
|
|
|
+ REQUIRE(document);
|
|
|
+ document->Show();
|
|
|
+
|
|
|
+ TestsShell::RenderLoop();
|
|
|
+
|
|
|
+ Element* element = document->GetElementById("simple");
|
|
|
+ CHECK(element->GetInnerRML() == "1");
|
|
|
+
|
|
|
+ element->DispatchEvent(EventId::Click, Dictionary());
|
|
|
+ TestsShell::RenderLoop();
|
|
|
+
|
|
|
+ CHECK(globals.simple == Simple_Two);
|
|
|
+ CHECK(element->GetInnerRML() == "2");
|
|
|
+
|
|
|
+ document->Close();
|
|
|
+ TestsShell::ShutdownShell();
|
|
|
+}
|