Replies: 3 comments 6 replies
-
|
Hello. I tried to reproduce this, but couldn't do so, this case seems to work for me. I threw together this unit test, and it runs successfully here. Could you test this on your end? Are you able to reproduce the issue in in our testing facilities? namespace Based {
static const String document_rect2d_rml = R"(
<rml>
<head>
<title>Test</title>
<link type="text/template" href="/assets/window.rml"/>
<style>
body.window
{
left: 50px;
right: 50px;
top: 30px;
bottom: 30px;
max-width: -1px;
max-height: -1px;
}
</style>
</head>
<body template="window" data-model="basics">
<p>{{ rect.x }}</p>
<p>{{ rect.y }}</p>
<p>{{ rect.w }}</p>
<p>{{ rect.h }}</p>
</body>
</rml>
)";
template <typename T>
struct Rect2D {
union {
T x, s;
};
union {
T y, t;
};
T w, h;
};
bool BindRect2D(Context* context)
{
Rml::DataModelConstructor constructor = context->CreateDataModel("basics");
if (!constructor)
return false;
bool res = true;
if (auto rect2di_handle = constructor.RegisterStruct<Rect2D<int>>())
{
res &= rect2di_handle.RegisterMember("x", &Rect2D<int>::x);
res &= rect2di_handle.RegisterMember("y", &Rect2D<int>::y);
res &= rect2di_handle.RegisterMember("w", &Rect2D<int>::w);
res &= rect2di_handle.RegisterMember("h", &Rect2D<int>::h);
}
else
{
FAIL("Failed to bind Rect2D<int>");
}
if (!res)
{
FAIL("Failed to bind Rect2D<int> fields");
}
constructor.Bind("rect", new Based::Rect2D<int>{1, 2, 3, 4});
return true;
}
} // namespace Based
TEST_CASE("data_binding.templated_struct")
{
Context* context = TestsShell::GetContext();
REQUIRE(context);
REQUIRE(Based::BindRect2D(context));
ElementDocument* document = context->LoadDocumentFromMemory(Based::document_rect2d_rml);
REQUIRE(document);
document->Show();
TestsShell::RenderLoop();
CHECK(document->QuerySelector("p:nth-child(1)")->GetInnerRML() == "1");
CHECK(document->QuerySelector("p:nth-child(2)")->GetInnerRML() == "2");
CHECK(document->QuerySelector("p:nth-child(3)")->GetInnerRML() == "3");
CHECK(document->QuerySelector("p:nth-child(4)")->GetInnerRML() == "4");
document->Close();
TestsShell::ShutdownShell();
} |
Beta Was this translation helpful? Give feedback.
-
|
Solved, see #759 discussion and https://mikke89.github.io/RmlUiDoc/pages/data_bindings/model.html#registering-types-across-library-boundaries |
Beta Was this translation helpful? Give feedback.
-
|
Well, this story got an unexpected continuation. By default MinGW exports all symbols in dll, regardless of dllexport attribute you use. This can be changed by setting So, here we go. Header: extern template class BASED_API Rml::Family<Based::Rect2D<int>>;Cpp: template class Rml::Family<Based::Rect2D<int>>;And... Let's look into the template <typename T>
class Family : FamilyBase {
public:
static FamilyId Id()
{
static int id = GetNewId();
return static_cast<FamilyId>(id);
}
};Matches the bug exactly. The So, I guess I'd stick to keeping all symbols being exported, until this bug gets fixed, if it ever would - the first report was 8 years ago and it's still in an unconfirmed state. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. I'm trying to figure out if I'm missing something, as I can't register/bind a simple templated struct:
Registration (with excess checks):
log.fatal()is not triggered.And, finally, binding:
Which fails with the message:
The
Modelclass is a pretty simple wrapper (some checks omitted):Thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions