Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix expand symbol instance #113

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Domain/Layout/ExpandSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ void ExpandSymbol::processOtherOverrides(nlohmann::json& instance,
return;
}

auto instanceMasterId = instance[K_MASTER_ID];
for (auto& el : overrideValues.items())
{
auto& overrideItem = el.value();
Expand Down Expand Up @@ -637,13 +636,20 @@ nlohmann::json* ExpandSymbol::findChildObject(nlohmann::json& instance,
std::vector<std::string>& outChildInstanceIdStack)
{
auto instanceMasterId = instance[K_MASTER_ID];
std::string masterOverrideKey;
if (m_masters.find(instanceMasterId) != m_masters.end())
{
auto& masterJson = m_masters[instanceMasterId];
masterOverrideKey = masterJson.value(K_OVERRIDE_KEY, K_EMPTY_STRING);
}

auto& objectIdPaths = overrideItem[K_OBJECT_ID];
if (!objectIdPaths.is_array() || objectIdPaths.empty())
{
return nullptr;
}
else if (objectIdPaths.size() == 1 && objectIdPaths[0] == instanceMasterId)
else if (objectIdPaths.size() == 1 &&
(objectIdPaths[0] == instanceMasterId || objectIdPaths[0] == masterOverrideKey))
{
outChildInstanceIdStack = instanceIdStack;
return &instance;
Expand Down Expand Up @@ -732,7 +738,6 @@ void ExpandSymbol::scaleTree(nlohmann::json& rootJson, const nlohmann::json& new

auto hasBounds = isLayoutNode(rootJson);
Rect oldBounds, frame;
Matrix matrix;
if (!hasBounds)
{
return;
Expand Down Expand Up @@ -984,6 +989,7 @@ void ExpandSymbol::layoutSubtree(nlohmann::json& rootTreeJson,
JsonDocumentPtr{ new ReferenceJsonDocument{ m_outLayoutJson } },
false };
layout.resizeNodeThenLayout(subtreeNodeId, newBounds.size);
overrideLayoutRuleSize(subtreeNodeId, newBounds.size);
}

nlohmann::json* ExpandSymbol::findLayoutObject(nlohmann::json& instance,
Expand Down
1 change: 0 additions & 1 deletion src/Domain/Layout/Layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ void Layout::Layout::resizeNodeThenLayout(const std::string& nodeId, Size size)
node->setFrame(VGG::Layout::Rect{ node->frame().origin, size }, true);
node->autoLayout()->setNeedsLayout();

DEBUG("Layout::resizeNodeThenLayout: layout subtree, %s", nodeId.c_str());
m_layoutTree->layoutIfNeeded();
}
}
58 changes: 49 additions & 9 deletions test/domain/layout/expand_symbol_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Domain/JsonSchemaValidator.hpp"
#include "Domain/Layout/Helper.hpp"
#include "Domain/Layout/Rule.hpp"
#include "Domain/Model/JsonKeys.hpp"
#include "Utility/VggFloat.hpp"

Expand Down Expand Up @@ -30,29 +31,34 @@ class VggExpandSymbolTestSuite : public ::testing::Test
Helper::write_json(json, out_file_path);
}

bool hasLayoutRule(const nlohmann::json& layoutJson, const std::string& id)
const nlohmann::json* layoutRule(const nlohmann::json& layoutJson, const std::string& id)
{
if (!layoutJson.is_object())
{
return false;
return nullptr;
}

auto& obj = layoutJson[K_OBJ];
if (!obj.is_array())
{
return false;
return nullptr;
}

for (auto& item : obj)
{
auto& jsonId = item[K_ID];
if (jsonId == id)
{
return true;
return &item;
}
}

return false;
return nullptr;
}

bool hasLayoutRule(const nlohmann::json& layoutJson, const std::string& id)
{
return layoutRule(layoutJson, id) != nullptr;
}
};

Expand Down Expand Up @@ -630,12 +636,46 @@ TEST_F(VggExpandSymbolTestSuite, layout_container_when_child_bounds_are_overridd

// Then
auto expandedDesignJson = std::get<0>(result);
auto expandedLayoutJson = std::get<1>(result);

// layout
{
nlohmann::json::json_pointer path{ "/frames/0/childObjects/0/childObjects/1/matrix" };
auto childMatrix = expandedDesignJson[path].get<Matrix>();
EXPECT_DOUBLE_EQ(childMatrix.tx, 73.0);
EXPECT_DOUBLE_EQ(childMatrix.ty, -7.0);
nlohmann::json::json_pointer nodePath{ "/frames/0/childObjects/0/childObjects/0" };
{ // bounds
auto path = nodePath / "bounds";
auto bounds = expandedDesignJson[path].get<Rect>();
EXPECT_DOUBLE_EQ(bounds.width(), 61.0);
EXPECT_DOUBLE_EQ(bounds.height(), 20.0);
}
{ // matrix
auto path = nodePath / "matrix";
auto childMatrix = expandedDesignJson[path].get<Matrix>();
EXPECT_DOUBLE_EQ(childMatrix.tx, 8.0);
EXPECT_DOUBLE_EQ(childMatrix.ty, -2.0);
}
}
{
nlohmann::json::json_pointer nodePath{
"/frames/0/childObjects/0/childObjects/1/childObjects/0"
};
{ // bounds
auto path = nodePath / "bounds";
auto bounds = expandedDesignJson[path].get<Rect>();
EXPECT_DOUBLE_EQ(bounds.height(), 7.276787757873535);
EXPECT_DOUBLE_EQ(bounds.width(), 7.067143440246582);
}
{ // matrix
auto path = nodePath / "matrix";
auto childMatrix = expandedDesignJson[path].get<Matrix>();
EXPECT_DOUBLE_EQ(childMatrix.tx, 1.4617968797683716);
EXPECT_DOUBLE_EQ(childMatrix.ty, -1.3610986471176147);
}
}
{ // layout
auto json = layoutRule(expandedLayoutJson, "1:38__1:25");
EXPECT_NE(json, nullptr);
Layout::Internal::Rule::Rule rule = *json;
EXPECT_EQ(rule.width.value.types, Internal::Rule::Length::ETypes::PX);
EXPECT_DOUBLE_EQ(rule.width.value.value, 61.0);
}
}
Loading